Warning: Matrix is singular to working precision.

1 Ansicht (letzte 30 Tage)
Steven Semeraro
Steven Semeraro am 30 Dez. 2020
Bearbeitet: madhan ravi am 30 Dez. 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 Kommentar
Mathieu NOE
Mathieu NOE am 30 Dez. 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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

madhan ravi
madhan ravi am 30 Dez. 2020
Bearbeitet: madhan ravi am 30 Dez. 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");

Kategorien

Mehr zu Financial Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by