Pure Recruitment

Forum Navigation:


FORUMS > Numerical Methods Forum < refresh >
Topic Title: Help with Heston Monte Carlo Spreadsheet
Created On Sun Dec 14, 03 08:49 PM
Topic View:

View thread in raw text format


dS
Member

Posts: 30
Joined: Jun 2003

Sun Dec 14, 03 08:49 PM
User is offline

I'm having problems with the Heston Model:
According to Heston's paper, the correlation, rho, should affect the skew of the PDF, and the vol of variance, sigma, should give fat tails.

I'm just not getting that effect with sigma. Sigma is affecting the skew, and does not seem to be giving me fat tails.

The attached spreadsheet implements this using Monte Carlo, as it is the most intuitive to understand. I know there are other implementations out there, but I'd like to understand why the mechanical monte carlo approach isn't working.

If anyone can help out and suggest what is happening, or if I've made a fundamental error in my coding then it would be very much appreciated.


thanks,
dS

HestonMonteCarlo.zip HestonMonteCarlo.zip  (64 KB)

 
Reply
   
Quote
   
Top
   
Bottom
     



AVt
Senior Member

Posts: 828
Joined: Dec 2001

Mon Dec 15, 03 08:57 PM
User is offline View users profile

Nice sheet, dS! But proper checks are beyond intuition :-) So only some thoughts: in
www.wilmott.com/messageview.cfm?catid=8&threadid=11125&FTVAR_MSGDBTABLE=
i posted you a formula to compute it, this would be one way (ok, it is ugly and some
what on the fly, but it should be possible with lots of paper & pencil + using Gauss
integration - and it would avoid simulation. Hmm, i hope it is correct ... please note
it is without discounting).

The next is http://www.math.nyu.edu/fellows_fin_math/gatheral/h2.c giving you a
code in C and i want to bet: it works & is ok. You may want to check you VBA code
against it.

And some vague by looking at your source: you use Rnd() which i never do feeling
unsave with it (ok, you use a modification due to Marsaglia ...). There was a posting
'normsinv not so random' with some reasonable and fast alternative. The point may
also be that you do not enough simulations (100 steps ?), but may be here i simply
did not see what you are doing in detail.

Hope that helps, even if it does not really solve it. But it is likely Heston is right :-)

And finally: if you want to fight those questions more often you may want to think
not to use only Excel for that, look for a computer algebra system (i used Maple
to get my above formula, but other CAS should work as well).
 
Reply
   
Quote
   
Top
   
Bottom
     



dS
Member

Posts: 30
Joined: Jun 2003

Mon Dec 15, 03 10:23 PM
User is offline

Thanks for the feedback AVt. You're always helpful on this stuff.
The spreadsheet is a conversion of some code I wrote in C++ ...I thought it would expecting a bit too much of people to trawl through my C++, and to then plot the results!
...So I don't *think* it is a problem with the random number generator, as I get the same results in C++.

The VBA Rnd() function cycles at around 16,000,000 - but my MC isn't reaching that limit. I don't think Rnd() is autocorrelated, but haven't done the testing - but as I say, I'm getting comparable results with my C++ implementation.

My original C++ code was heavily influenced by Gatheral - but I will test his code. For his default settings, he uses about the same number of paths as me (he has 30000 with antithetic variables, I have 50000), but 150 steps instead of my 100 steps. In my C++, I run a lot more paths, but generally keep the steps the same - I'll try increasing these.

I've got access to Mathematica, so will try to get things working there.

If I'm backed into a corner, then I'll go into the maths!

One of the things that MC has to deal with (which Gatheral's code has) is what to do if the variance goes negative. As the stochastic eqns for both dS and dv contain sqrt(v), a negative v is clearly a problem. Gatheral says either reflect (v = -v) or absorb (v=0) when v goes negative. Now, I wonder if this actually causes errors in Monte Carlo.
The closed form solution just doesn't have to do this. The fact that Monte Carlo has to deal with it suggests to me that it is more and more of an approximation when it has to start manipulating the results (?)
 
Reply
   
Quote
   
Top
   
Bottom
     



asd
Senior Member

Posts: 660
Joined: Aug 2002

Tue Dec 16, 03 06:13 AM
User is offline

dS,

Thanks for posting out your excellent code!
It does work as per theory, only thing is I tried with steps =1000 and reduced the paths by 1/10. Rho will change the skew, and sigma makes the curve fatter. I guess, this is what you want.
I think, this is because reducing the timestep will reduce the probability of getting negative volatilties for CIR dynamics.
Please correct me if I am wrong.
It is also a better idea to check the values with Avt's code out there in there in software forum.


Hope it helps,
asd


-------------------------
Life is a journey and not a destination
quant code directory

Edited: Tue Dec 16, 03 at 06:14 AM by asd
 
Reply
   
Quote
   
Top
   
Bottom
     



AVt
Senior Member

Posts: 828
Joined: Dec 2001

Tue Dec 16, 03 08:29 AM
User is offline View users profile

I see ... looking at your plots i am not sure whether you dont miss a factor,
the pdf of a lognormal is not pdfN(z): cdfN(ln(x))' = 1/x * pdfN(ln(x)) ...

May be asd has the easiest way: either increasing step numbers or use prices
and numerical differentiate twice to get the density (that should be fast).
 
Reply
   
Quote
   
Top
   
Bottom
     



hazerider
Member

Posts: 171
Joined: Jul 2003

Tue Dec 16, 03 04:03 PM
User is offline

Slightly off-topic: why do you call a straightforward Box-Muller transform the Marsaglia method?

Edited: Tue Dec 16, 03 at 04:04 PM by hazerider
 
Reply
   
Quote
   
Top
   
Bottom
     



dS
Member

Posts: 30
Joined: Jun 2003

Tue Dec 16, 03 10:14 PM
User is offline

Increasing the steps doesn't seem to make a difference - I'm still getting more skew as I decrease sigma, which I don't understand.


AVt, can you explain a bit more about the pdf - I don't entirely follow you. Surely for the pdf of the returns, all I need to do is:
1. Generate lots of expiry stock prices using Monte Carlo of Heston's model
2. Calculate the return by dividing by S(0)
3. Collect everything up into bins, and calculate the bin frequency (i.e. create a histogram)
4. Divide each bin frequency by the total number of results (i.e. the no. of paths in Monte Carlo) to re-scale
5. Plot bin frequency vs. bin value - this is my pdf



hazerider: For some info of Marsaglia's development of Box-Muller, I've found this:
http://ct.radiology.uiowa.edu/~jiangm/courses/dip/html/node41.html


 
Reply
   
Quote
   
Top
   
Bottom
     



asd
Senior Member

Posts: 660
Joined: Aug 2002

Wed Dec 17, 03 12:35 AM
User is offline

"Increasing the steps doesn't seem to make a difference - I'm still getting more skew as I decrease sigma, which I don't understand"
Sorry, I had tried it with large value of sigma around 0.9 and it seemed stable without skew.The skew is indeed still there for sigma around 0.1.
Actually, the problem might not be related to Heston's model because if the value of V(0) is set to theta and sigma=0, it is simply a case of lognormal distribution of returns. This itself seems to be skewed.

Hope it helps,
asd

-------------------------
Life is a journey and not a destination
quant code directory
 
Reply
   
Quote
   
Top
   
Bottom
     



dS
Member

Posts: 30
Joined: Jun 2003

Wed Dec 17, 03 07:38 AM
User is offline

Yes of course!
As you both point out - I've been plotting the distribution of S(T)/S(0) - which will be lognormal. I should be plotting ln[S(T)/S(0)]
I'm getting the right results now - Hooray!

...a basic error, which I might have picked up if I had started by plotting the standard Black-Scholes as well. I'll post a corrected spreadsheet over the next day or two.
 
Reply
   
Quote
   
Top
   
Bottom
     



robertral
Senior Member

Posts: 655
Joined: Mar 2003

Wed Dec 17, 03 09:20 AM
User is offline

dS...excellent sheet. I await the updated sheet

-------------------------
"WAAH EXACCLY I PACE!!!!!!!!!!!!!!!!!!!!!?"??..."WAAH EXACCLY I PACE!!!!!!!!!!!!!!!!!!!!!?"??
 
Reply
   
Quote
   
Top
   
Bottom
     



dS
Member

Posts: 30
Joined: Jun 2003

Wed Dec 17, 03 08:34 PM
User is offline

This is the corrected spreadsheet showing results in line with Heston. Thanks for all of your help.

BTW, if you want to understand more about the reflection/absorption issues with the Heston Monte Carlo, then Gatheral has some stuff about it, as does Uwe Wystup in his formula catalogue:

http://www.mathfinance.de/

HestonMonteCarlo2.zip HestonMonteCarlo2.zip  (76 KB)

 
Reply
   
Quote
   
Top
   
Bottom
     



AVt
Senior Member

Posts: 828
Joined: Dec 2001

Thu Dec 25, 03 03:59 PM
User is offline View users profile

If one can give prices (like for the Heston model) there is no need to do MC
to produce the pdf, since up to a discounting factor it is the 2nd derivative
w.r.t. strike. I did the differentiation numerical (Lagrange method, 5 points,
see Abramowitz & Stegun) to get the Heston pdf over logarithmic moneyness =
- log(forward/strike) (use chain rule). Who prefers it over the strikes just
do it there (but note that numerical diff one needs equal spacing, so start
over the strikes and things become even simplier).

It is compared to BS by using the implied vol of the Heston price at ATM
(to be understood as strike=forward) using the same method (as a test).

The advantage is speed and exactness, but one needs a dense grid of prices.

One can choose the grid. If the curves start to jitter integration has to
be improved (larger intervall, smaller subintervalls - in the last sheet
just check what's going on to help yourself ... ). With minor modifications
i used the solution i once uploaded to the software forum (and recognized
that i forgot to handle the case VolVol=0, so just use a small value like
0.001 instead of 0 if neccessary ... ahem).

The smile is plotted at the same time. If strikes are extreme than the simple
solution in Excel fails, so do not worry in that case.

Heston93_pdf.zip Heston93_pdf.zip  (95 KB)

 
Reply
   
Quote
   
Top
   
Bottom
     



Demian
Junior Member

Posts: 8
Joined: Aug 2004

Mon Sep 06, 04 11:45 AM
User is offline View users profile

Hello,

With regards to your attachment "HestonMonteCarlo2.zip"...may I ask why you multiply cdf of normal distribution by 2041?

I dont understand that part. I appreciate your repplies

demian
 
Reply
   
Quote
   
Top
   
Bottom
     



dS
Member

Posts: 30
Joined: Jun 2003

Mon Sep 06, 04 12:04 PM
User is offline

...that was a *long* time ago - from memory, it was probably so that the graphs matched up - i.e. created by trial and error in order to produce a reasonable looking report


 
Reply
   
Quote
   
Top
   
Bottom
     



Forde
Member

Posts: 123
Joined: Nov 2002

Mon Oct 11, 04 02:17 PM
User is offline

Hi Avt, can u remember where was the thread describing the methodology used to compute vanilla prices under Heston (think it was Gauss Laguerre quadrature)

thx

 
Reply
   
Quote
   
Top
   
Bottom
     



sammus
Senior Member

Posts: 317
Joined: Nov 2003

Mon Oct 11, 04 03:18 PM
User is offline View users profile

you mean this?

-------------------------
search and research

Edited: Mon Oct 11, 04 at 03:19 PM by sammus
 
Reply
   
Quote
   
Top
   
Bottom
     

View thread in raw text format
FORUMS > Numerical Methods Forum < refresh >

Forum Navigation:

© All material, including contents and design, copyright Wilmott Electronic Media Limited - FuseTalk 4.01 © 1999-2010 FuseTalk Inc.