Error with Difference line

% PlotBLS with varying dS
S = 0:1:10;
S0 = 60;
K = 62;
r = 0.09
sigma = 0.5
for T=3:-0.5:0
C1 = blsprice(S0+S,K,r,T,sigma);
C0 = blsprice(S0,K,r,T,sigma);
delta = blsdelta(S0,K,r,T,sigma);
gamma = blsgamma(S0,K,r,T,sigma);
Difference = (C1[T]-(C0+(delta*S)+(0.5*gamma*(S^2))));
plot(S,Difference);
hold on;
end
axis ([0 10 -10 50]);
grid on

回答 (1 件)

Geoff Hayes
Geoff Hayes 2016 年 10 月 12 日

0 投票

Manish - is the error message Unbalanced or unexpected parenthesis or bracket.? If so, look closely at this line of code
Difference = (C1[T]-(C0+(delta*S)+(0.5*gamma*(S^2))));
Since C1 is an array, you need to use the round brackets to access elements within it. Just change the above line to
Difference = (C1(T)-(C0+(delta*S)+(0.5*gamma*(S^2))));
and try again.

4 件のコメント

Manish Abbi
Manish Abbi 2016 年 10 月 12 日
編集済み: Walter Roberson 2016 年 10 月 12 日
Geoff, the entire code is below. I want to graph more than 1 plot but only the first plot is generated. Now, I'm getting the error message
Error in api (line 42)
delta = blsdelta(S0,K,r,T,sigma);
%Calculating a call option and put option prices
S0 = 60;
K = 62;
r = 0.11;
T = 11/12;
sigma = 0.5;
q = 0;
[C, P] = blsprice (S0, K, r, T, sigma, q)
% PlotBLS
S0 = 20:1:80;
K = 62;
r = 0.09
sigma = 0.5
for T=3:-0.5:0
plot(S0,blsprice(S0,K,r,T,sigma));
hold on;
end
axis ([20 80 -10 50]);
grid on
%Illustrating approximation of call price
CO = blsprice(60, 60, 0.09, 11/12, 0.3)
dS = 2;
C1 = blsprice(60+dS, 60, 0.09, 11/12, 0.3)
delta = blsdelta(60, 60, 0.09, 11/12, 0.3)
gamma = blsgamma(60, 60, 0.09, 11/12, 0.3)
CO + delta*dS + 0.5*gamma*dS^2
% PlotBLS with varying dS
dS = 0:1:10;
S0 = 60;
K = 62;
r = 0.09
sigma = 0.5
C1 = blsprice(S0+dS,K,r,T,sigma);
C0 = blsprice(S0,K,r,T,sigma);
delta = blsdelta(S0,K,r,T,sigma);
for T=3:-0.5:0
gamma = blsgamma(S0,K,r,T,sigma);
Difference = (C1-(C0+(delta*dS)+(0.5*gamma*(dS.^2))));
plot(S,Difference);
hold on;
end
axis ([0 10 -10 50]);
grid on
Walter Roberson
Walter Roberson 2016 年 10 月 12 日
What error message are you seeing? Please post everything that shows up in red.
Manish Abbi
Manish Abbi 2016 年 10 月 12 日
Error in api (line 42)
delta = blsdelta(S0,K,r,T,sigma);
Walter Roberson
Walter Roberson 2016 年 10 月 12 日
Does it say something about an unknown function or variable "blsdelta"? Does it say something about it being the wrong phase of the moon? Does it say that the weasel made the rich programmer do it?

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

カテゴリ

ヘルプ センター および File ExchangeTime Series Events についてさらに検索

タグ

質問済み:

2016 年 10 月 12 日

コメント済み:

2016 年 10 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by