Warning: Matrix is singular to working precision.

1 回表示 (過去 30 日間)
Steven Semeraro
Steven Semeraro 2020 年 12 月 30 日
編集済み: madhan ravi 2020 年 12 月 30 日
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 件のコメント
Mathieu NOE
Mathieu NOE 2020 年 12 月 30 日
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

サインインしてコメントする。

回答 (1 件)

madhan ravi
madhan ravi 2020 年 12 月 30 日
編集済み: madhan ravi 2020 年 12 月 30 日
% 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");

カテゴリ

Help Center および File ExchangeFinancial Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by