Warning: Matrix is singular to working precision.

2 visualizaciones (últimos 30 días)
Steven Semeraro
Steven Semeraro el 30 de Dic. de 2020
Editada: madhan ravi el 30 de Dic. de 2020
I am trying to create a 3D plot of option Vanna. However, I have this error "Warning: Matrix is singular to working precision." What am I doing wrong?
% Black Scholes Vanna
% Steven Semeraro
sigma = ones(100, 100) * 0.2;
stock = ones(100, 100) * 50;
x = 1:100;
y = 0.01:0.01:1;
[strike, time] = meshgrid(x, y);
% The Error is in these lines
d1 = log(stock / strike) + (sigma^2 / 2) * time;
d1 = d1 / sigma * sqrt(time);
d2 = log(stock / strike) + (sigma^2 / 2) * time;
d2 = d2 / sigma * sqrt(time);
vanna = -((exp(-(d1^2/2))) / (sqrt(2 * pi)) ) * d2 * sigma;
surf(strike, time, vanna);
title("S = 50, Vol = 0.2");
xlabel("Strike Price");
ylabel("Time To Expiration");
zlabel("Vanna");
  1 comentario
Mathieu NOE
Mathieu NOE el 30 de Dic. de 2020
hello
I cannot say if the code is correct , but you are doing multiple matrix divisions, like stock / strike
but you cannot make a reliable inversion of strike because all lines are identical
strike =
Columns 1 through 14
1 2 3 4 5 6 7 8 9 10 11 12 13 14
1 2 3 4 5 6 7 8 9 10 11 12 13 14
1 2 3 4 5 6 7 8 9 10 11 12 13 14
1 2 3 4 5 6 7 8 9 10 11 12 13 14
.....
same comment every time you do these matrix divisions

Iniciar sesión para comentar.

Respuestas (1)

madhan ravi
madhan ravi el 30 de Dic. de 2020
Editada: madhan ravi el 30 de Dic. de 2020
% Black Scholes Vanna
% Steven Semeraro
sigma = ones(100, 100) * 0.2;
stock = ones(100, 100) * 50;
x = 1:100;
y = 0.01:0.01:1;
[strike, time] = meshgrid(x, y);
d1 = log(stock ./ strike) + (sigma.^2 / 2) .* time;
d1 = (d1 ./ sigma) .* sqrt(time);
d2 = log(stock ./ strike) + (sigma.^2 / 2) .* time;
d2 = (d2 ./ sigma) .* sqrt(time);
vanna = -((exp(-(d1.^2/2))) / (sqrt(2 * pi)) ) .* d2 .* sigma;
surf(strike, time, vanna);
title("S = 50, Vol = 0.2");
xlabel("Strike Price");
ylabel("Time To Expiration");
zlabel("Vanna");

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by