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
Best Answer