0
$\begingroup$

I am trying to evalute two functions using iterative process as below

S[i+1] = S[i] (1+ r*dt +vol*w *sqrt(dt)) for i= 1 to nts and for j = 1 to path.
Optionprice [j] = Max (S[nts] - strike) for j = 1 to path

Output of 1st iterative process (S[nts]) is input of 2nd (to compute Parameter Optionprice) as in below code. Both iterative process involves usage of random no generated using parameter w. However Nest function is not generating new values of w (or new random no.). w is updated only for For loop. Can anybody help in modifying or simplifying the code so that I can generate random no for two Paths and use the output of 1st path (S) to compute parameter in 2nd path please. I am expecting a value close to $10$ when I run below function as

mcOptionPrice[10000,10,1,100,0.05,0.2,100]

I only get that for nts =1 when I increase it more than $1$ (say $10$) FVMC diverges away.

mcOptionPrice[paths_,nts_,T_,strike_, r_,vol_, S0_] := Module[{dt,stock,optionprice,df,w,S,FVMC},
dt = T/nts;
stock=optionprice = Table[1,{paths}];
df= Exp[-r*T];
For [ i=1, i <paths+1, i++, 
w=RandomReal[NormalDistribution[0,1]];
S=Nest[# *(1+r*dt+vol*w*sqrt(dt))&,S0,nts];
stock[[i]]=S;
optionprice[[i]]=Max[S- strike,0]];
FVMC = df*Mean[optionprice];
FVMC
]
$\endgroup$

1 Answer 1

0
$\begingroup$

Two small issues in your code.

  1. You have incorrect syntax in your Nest statement that assigns a value to S. sqrt is not defined. I think you want Sqrt and will have to change your brackets as well.
  2. Use SetDelayed (:=) for assignment of w to have it re-evaluated each time in the Nest statement.

Hope this helps.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.