Hi
I am trying to plot a Black-Scholes surface:
I have the following simple code --
function C=bsf(S,t,E,r,sigma,T)
% Here our function is C=bsf(S,t,E,r,sigma,T)
% We will construct the Black-Scholes formula for
% a European call option
tau=T-t;
if tau>0
d1=(log(S/E)+(r+0.5*sigma^2)*tau)/(sigma*sqrt(tau));
d2=d1-sigma*sqrt(tau);
% From standard Black-Scholes materials
N1=0.5*(1+erf(d1/sqrt(2)));
N2=0.5*(1+erf(d2/sqrt(2)));
C=S*N1-E*exp(-r*tau)*N2;
else
C=max(S-E,0);
end
I input fixed values of E,r,sigma and T. Hence I need to input a range of values for S and t. I have attempted to construct a mesh via meshgrid:
[S,t]=meshgrid(linspace(0,3),linspace(0,1));
I then try to call the bsf code:
mesh(S,t,bsf)
This results in an error in Line 6 of the code (the construction of tau).
How do I get this to work or any pointers on where I am going wrong!
Many thanks
Joe

댓글 수: 2

Star Strider
Star Strider 2015년 3월 22일
‘This results in an error in Line 6 of the code (the construction of tau).’
Would you be so kind as to tell us what the error is? (Copy and paste all the red output in the Command Window and paste it to a comment here.)
What are the sizes of ‘T’ and ‘t’?
Here is my attempt to get this to work:
>> T=1;E=1;r=0.05;sigma=0.05;
>> [S,t]=meshgrid(linspace(0,3),linspace(0,1));
>> mesh(S,t,bsf)
Error using bsf (line 6)
Not enough input arguments.
>>
Thanks
Joe

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

 채택된 답변

Star Strider
Star Strider 2015년 3월 22일

1 개 추천

You need to call your ‘bsf’ function as:
C=bsf(S,t,E,r,sigma,T);
then plot it as:
mesh(S,t,C)
Since ‘bsf’ is a function file, you have to pass to it all the arguments in its argument list. It will not pick up any variables from the workspace, as an anonymous function would.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Probability Distributions and Hypothesis Tests에 대해 자세히 알아보기

제품

태그

질문:

2015년 3월 22일

댓글:

2015년 3월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by