Hi
I am trying to input a mesh into a slight variant of the standard Black-Scholes function. I wish to vary the 'S' and the 't'. I am using the linspace for this so that I generate 100 equally spaced points in equally spaced intervals.
function C=bsf3(S,t)% Here our function is C=bsf3(S,t,--all the rest given ---K,r,sigma,T)
% We will construct the Black-Scholes formula for
% a European call option
% We set up our variables:
T=1; % Time to Expiry
K=1; % Strike Price
r=0.05; % Riskless Interest Rate
sigma=0.25; % Market Volatility
tau=T-t;if tau>0 d1=(log(S/K)+(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-K*exp(-r*tau)*N2;else C=max(S-K,0);end
I try to call bsf3 using the following:
>> [S,t]=meshgrid(linspace(0,2),linspace(0,1));>> C=bsf3(S,t);>> mesh(S,t,C)
C seems to be a 100 x 100 matrix with repeated rows, which is not what I am looking for as each row should be different. In particular the mesh has no 'skew' or tilt.
How do I generate C by varying the input along S and along t so that I have 100×100 different entries?
Should I be using different inputs?
Thanks
Joe
Best Answer