Efficient Monte Carlo code
- To: mathgroup at smc.vnet.net
- Subject: [mg44997] Efficient Monte Carlo code
- From: DBiyana at btech.tktech.ac.za
- Date: Fri, 12 Dec 2003 04:41:55 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Dear MathGropup,
I'm trying to set up a Mathematica Code, that implements a Monte Carlo call
options price, that Alan Lewis in his book:"Option Valuation under
Stochastic Volatility : with Mathematica Code", refers to as Mixing
theorem. The stock price S follows the usual Geometric Brownian motion:
dS/S = rdt + Sqrt(V)(dW+(1-rho^2)^(1/2)dZ and the volatility evolves under the
square-root process: dV = (w - theta V )dt+ ksi Sqrt(V)dW. dZ and dW have
zero correlation. The call option is given by < B(Seff,K,T,r,d,(Veff)^(1/2)) >
where < > denotes expectation under risk adjusted volatility process. For
Monte Carlo implementation < > means averaging. Seff = Sexp(Y(T)), Y(t+dt)
= Y(t)-sum(rho^2 V(t)dt,{t,0,T-dt,dt}) + rho*sqrt(V(t) dt)Z(t), Veff = (1-
rho^2)sum(V(t)dt,{t,0,T-dt,dt}). The code that I managed to write
is:\!\(MCmixingCall[S_, K_, r_, \[Delta]_,
V0_, \[Tau]_, \[Omega]_, \[Theta]_, \[Xi]_, \[Rho]_, m_, n_] :=
Module[{normals, v, y, Seff, Veff, bsvec},
normals = Table[Table[norm[0, 1], {i, m}], {j, n}];
v = Table[
FoldList[\((#1 + \((\[Omega] - \[Theta]\ #1)\) \[Tau]/
m + \[Xi]\ Sqrt[#1\ \[Tau]/m] #2)\) &, V0,
normals[\([i]\)]], {i, n}];
y = Table[
FoldList[\((#1 - \(\[Rho]^2 #2 \((\[Tau]/m)\)\)\/2)\) &, 0,
Drop[v[\([i]\)], \(-1\)]] +
FoldList[\((#1 + \[Rho] #2)\) &, 0,
Sqrt[Drop[v[\([i]\)], \(-1\)]] \((\[Tau]/
m)\)\ normals[\([i]\)]], {i, n}];
Seff = S\ Exp[Last[Transpose[y]]];
Veff = Table[
Fold[Plus, 0, \((1 - \[Rho]^2)\) Drop[v[\([i]\)], \(-1\)]]/
Length[Drop[v[\([i]\)], \(-1\)]], {i, n}];
bsvec = Map[
BScall[#[\([1]\)], K, \[Tau], r, \[Delta], Sqrt[#[\([2]\)]]] &,
Transpose[{Seff, Veff}]]; {Mean[bsvec],
StandardErrorOfSampleMean[bsvec]}]\)
This is a very inefficient code it takes about 30 seconds a pentium 4, pc. I
need to modify this and make it more efficient. Can someone help.
Regards
DM Biyana
Eastern Cape Technikon
South Africa