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
0 个评论
回答(1 个)
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, [], [])
syms Y
X = blackScholesCallPrice( K, T, S0, r, Y, sigma )
dX = diff(X,Y)
bestX = vpasolve(dX == 0)
fplot(dX, [0 1])
limit(dX, Y, 0)
vpa(ans)
limit(dX, Y, inf)
vpa(ans)
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
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!