Can't get this to plot (Asian Option)

3 次查看(过去 30 天)
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 个评论
Joe Bannen
Joe Bannen 2014-4-28
Sorry! Forgot to include the error. I am trying to plot AsianCallH(NRep1) against a range of NRep1's. I am trying this:
>> NRep1=1:1000:100000;
>> Plot(NRep1,AsianCallH(NRep1))
Error using qrandstream/qrand (line 211)
Number of points must be a positive scalar integer.
Error in Halton (line 11)
RandMat=qrand(q,NRep1);
Error in AsianCallH (line 22)
Increments=drift+vari*Halton(NSteps,NRep1);
Image Analyst
Image Analyst 2014-4-28
编辑:Image Analyst 2014-4-28
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.

请先登录,再进行评论。

采纳的回答

dpb
dpb 2014-4-28
Yeah, it's exactly what it says it is--you've defined
NRep1=1:1000:100000;
as a vector and passed it to
AsianCallH(NRep1))
which calls qrandstream/qrand with that vector when the input N must be a positive scalar integer. The output is then an NxD array.
You'll have to call in a loop over your number of points or use arrayfun perhaps since qrand isn't vectorized internally.

更多回答(0 个)

类别

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