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

1 visualización (últimos 30 días)
Brian O'Connell
Brian O'Connell el 3 de Dic. de 2021
Comentada: Matt J el 3 de Dic. de 2021
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

Respuestas (1)

Walter Roberson
Walter Roberson el 3 de Dic. de 2021
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 comentario
Matt J
Matt J el 3 de Dic. de 2021
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

Iniciar sesión para comentar.

Categorías

Más información sobre Optimization en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by