Can't get this to plot (Asian Option)
Mostrar comentarios más antiguos
Hi
Needing help.
I am trying to plot this code (NRep 1 on the X axis, Y on the Y-axis) but am hitting too many input argument errors etc. I need to plot it for a range of the NRep1: say 0 to 100,000 in increments of 10000 (say), but for the life of me can't get it to work.
How do I input this range and then plot without hitting any errors?
Many, many thanks in advance
Joe
The code is as follows:
function Y=AsianCallH(NRep1)
% AsianCall calculates the approximate value of the Asian Call Option
% based on the motion of the underlying asset price with random sequences
% Format of Call: AsianCall(S0,K,r,T,sigma,NSteps,NRep1)
% S0: Current asset price
% K: Strike Price
% r: Riskfree rate
% Sigma: The standard deviation
% NSteps: The number of steps(dimensions) between t=0 and t=T
% NRep1: Number of simulations per time step
S0=75;
K=75;
r=0.015;
T=2;
sigma=0.30;
NSteps=24;
% NRep1=50000
dt=T/NSteps;
drift=(r-0.5*sigma^2)*dt;
vari=sigma*sqrt(dt);
Increments=drift+vari*Halton(NSteps,NRep1);
LogPaths=cumsum([log(S0)*ones(NRep1,1),Increments] ,2);
% Now the underlying asset path is generated
SPath=exp(LogPaths);
Payoff=zeros(NRep1,1);
Payoff=max(0,mean(SPath(:,2:(NSteps+1)),2)-K);
Y=mean(exp(-r*T)*Payoff);
end
For completion the Halton code is:
function HaltonMat = Halton(NSteps,NRep1)
% This function will use the grandstream Matlab function
% to simplify the Halton
q=qrandstream('halton',NSteps,'Skip',1e3,'Leap',1e2);
% Defines a function which generates the quasi points from the
% qrandstream function
RandMat=qrand(q,NRep1);
% HaltonMat will geneate the NRep1*NSteps matrix
HaltonMat=norminv(RandMat,0,1);
end
3 comentarios
dpb
el 28 de Abr. de 2014
Show the actual error in context w/ the code that generated it--don't make us guess...what does plotting have to do with anything--I see no plot() command anywhere.
Joe Bannen
el 28 de Abr. de 2014
Image Analyst
el 28 de Abr. de 2014
Editada: Image Analyst
el 28 de Abr. de 2014
Plot is different than plot you know, because MATLAB is case sensitive. Who knows what Plot it's actually calling? To find out, do this:
which -all Plot
That's Plot with a capital P , just like you copied and pasted from your command window.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Geographic Plots en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!