first time matlab user, trying to use fmincon for a simple question

1 次查看(过去 30 天)
Hi, I am trying to use fmincon to get the best result for an input variable. I think I am close. Student here!
my input variables are
S0 = 1433.32; K = 1430; r = 0.0011; T = 30/365; sigma = .15;
y = ??
the y is my variable I need to change, so that the result of this function will be 24.5.
x0 = 24.9;
x = fmincon(blackScholesCallPrice,x0,[],[])
function [cprice] = blackScholesCallPrice( K, T, S0, r, y, sigma )
numerator = log(S0./K) + (r-y+0.5*sigma.^2).*T;
denominator = sigma.*sqrt(T);
d1 = numerator./denominator;
d2 = d1 - denominator;
cprice = S0 *exp(-y*T).* normcdf(d1) - exp(-r.*T).*K.*normcdf(d2);
end

回答(1 个)

Walter Roberson
Walter Roberson 2021-12-3
S0 = 1433.32; K = 1430; r = 0.0011; T = 30/365; sigma = .15;
x0 = 24.9;
x = fmincon(@(y)blackScholesCallPrice(K,T,S0,r,y,sigma), x0, [], [])
Initial point is a local minimum that satisfies the constraints. Optimization completed because at the initial point, the objective function is non-decreasing in feasible directions to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 24.9000
syms Y
X = blackScholesCallPrice( K, T, S0, r, Y, sigma )
X = 
dX = diff(X,Y)
dX = 
bestX = vpasolve(dX == 0)
bestX = Empty sym: 0-by-1
fplot(dX, [0 1])
limit(dX, Y, 0)
ans = 
vpa(ans)
ans = 
limit(dX, Y, inf)
ans = 
0
vpa(ans)
ans = 
0.0
function [cprice] = blackScholesCallPrice( K, T, S0, r, y, sigma )
numerator = log(S0./K) + (r-y+0.5*sigma.^2).*T;
denominator = sigma.*sqrt(T);
d1 = numerator./denominator;
d2 = d1 - denominator;
cprice = S0 *exp(-y*T).* normcdf(d1) - exp(-r.*T).*K.*normcdf(d2);
end
So the minimum of the function is at Y = infinity
  1 个评论
Matt J
Matt J 2021-12-3
Brian O'Connell's reply moved here:
HI, Thanks.
I am way out of my depth here. The lecturer said the cprice should be the midpoint of 24.1 - 24.9, which is why I put x0 = 24.5.
I think y is supped to equal 0.3. he just wants us to familiarise ourselves with using fmincon. Apparently its better than excel solver, which is where I got the result 0.3 for Y.
regards
brian

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Optimization 的更多信息

产品


版本

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by