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

조회 수: 1 (최근 30일)
Brian O'Connell
Brian O'Connell 2021년 12월 3일
댓글: Matt J 2021년 12월 3일
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에서 Nonlinear Optimization에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by