3D plot for pricing options over increasing time and asset price

조회 수: 2 (최근 30일)
Katie Brewer
Katie Brewer 2019년 2월 12일
댓글: Rena Berman 2019년 4월 2일
I have a function that works out the black scholes formula over changing time and price of the underlying.
I need C to store and save the answer for each iteration, in vector form, in order to plot a 3D to show the price of the call option changing over time and increasing underlying price.
S0=100;
X=120;
r=0.1;
sigma=0.2;
N=50;
x1=linspace(0,0.5,N); %time in years
x2=[0:1:N]'; %price of the underlying
C=zeros(1,N);
for x2=0:N
for x1=0:N
d1=(log(x2/X)+(r+0.5*sigma.^2)*x1)/(sigma*sqrt(x1));
d2=d1-sigma.*sqrt(x1);
C=S0*normcdf(d1)-X*exp(-r*x1)*normcdf(d2)
end
end
  댓글 수: 2
Jan
Jan 2019년 3월 21일
편집: Jan 2019년 3월 21일
Katie Brewer has removed the contents of all of her questions. It seems, like she is not interested in a cooperative usage of the forum. What a pity.
Rena Berman
Rena Berman 2019년 4월 2일
(Answers Dev) Restored edit

댓글을 달려면 로그인하십시오.

답변 (1개)

Patel Mounika
Patel Mounika 2019년 2월 19일
You can use array indexing to store the values of C in each iteration.
i=1;
for x2=0:N
for x1=0:N
d1=(log(x2/X)+(r+0.5*sigma.^2)*x1)/(sigma*sqrt(x1));
d2=d1-sigma.*sqrt(x1);
C(i)=S0*normcdf(d1)-X*exp(-r*x1)*normcdf(d2)
i=i+1;
end
end
This might help you.
  댓글 수: 2
Katie Brewer
Katie Brewer 2019년 2월 19일
Thanks,
This works!
Sorry, I'm new to matlab, I want to plot this in a 3D plot with x2 on the X axis, x1 on the Y axis and the option prices on the Z axis, do you know how I would do that?
Thanks
Patel Mounika
Patel Mounika 2019년 2월 19일
You can use 3D plots available in MATLAB like mesh,surface plots etc.,Please refer to
the below link.,

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Price and Analyze Financial Instruments에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by