Serving the Quantitative Finance Community

 
User avatar
marcockc
Topic Author
Posts: 1
Joined: February 14th, 2007, 10:17 am

Moodley's SV (Heston) FFT matlab code

August 30th, 2007, 7:10 pm

Hello everyone~ I found some people also use "Moodley's" code to obtain European call price under SV. Although the calculated option price from the code is quite close to other option calcultor, the characteristic function (CF) used in the code/paper is quite weird. It is very different from the CF in Heston's paper. Surprisedly, when I try to replace with the CF from Heston's paper, the code gives me very strange result, which is very far away from the original one. Does this mean the code have some problem ?? (though the fft part looks fine for me.) Or when using FFT, the CF need to be modifed instead of using the original CF in Heston's paper ??If any of you has some similiar experience could you please tell me about it. (I attached the raplaced CF code. )many thanks,Marco
 
User avatar
Y0da
Posts: 0
Joined: August 7th, 2007, 4:48 pm

Moodley's SV (Heston) FFT matlab code

August 30th, 2007, 7:45 pm

Why has everyone suddenly become so hooked on Moodley?Seems like some kind of a trend these days.Don't get me wrong. Moodley's paper is a great intro to theHeston model. But it sure has some issues. At least it didthe last time I looked at it.However, I recall writing down some of Moodley's Matlabcode and getting good results with it. I also got rather close(but not exact, of course) results with FFT.
 
User avatar
tontonkum
Posts: 0
Joined: July 26th, 2007, 12:08 pm

Moodley's SV (Heston) FFT matlab code

August 31st, 2007, 8:35 am

It's maybe a problem of calculating complex logarithms (or power of complex numbers).If u do not take care of the branch switching to keep your log continuous, you could get some very wrong prices.The fact is : this issue can be handled by a refactorization of the original Heston's formula, which makes the the argument complex number inside the logarithm impossible to get over Pi in absolute value.This must probably be the case of the Moodley's formula, some other authors have used that trick too. When you replace th Moddley's formula with the original one, you then get a unhandled issue.That might be an explanation, however it might be something else.
 
User avatar
marcockc
Topic Author
Posts: 1
Joined: February 14th, 2007, 10:17 am

Moodley's SV (Heston) FFT matlab code

August 31st, 2007, 6:47 pm

Hi Y0da:I do agree taht Moodly's paper is quite a nice intro and feel his code is quite correct/useful. Especially he made this niece work during undergraduate, which is very amazing. I like his work very much indeed. But just feel starnge when replacing the CF. Because I am working on Multi-variable SV model whose CF can just adapts Heston's paper, I feel safer to use Heston's instead of Hong's.
 
User avatar
marcockc
Topic Author
Posts: 1
Joined: February 14th, 2007, 10:17 am

Moodley's SV (Heston) FFT matlab code

August 31st, 2007, 7:10 pm

Hi tontonkum:Thanks very much for the explanation. I guess that complex logarithm could be the issue. Initially, I thought the complex number issue has been tackled by Carr& Madan's modified CF, but now i realized there is still some thing need to be handled in the CF itself.Most papers didn't clearly mention they refractorized Heston's formula actually. Guess they regard this as basic knowledge, but this really makes my lousy complex number knowledge even poorer. Fortunately, there is this forum and you guys. Much appreciated~ (I attached the replaced CF of Moodley's code if anyone is intersted the CF problem.)
Attachments
HestonCallFft_withHestonCF.zip
(1.22 KiB) Downloaded 77 times
 
User avatar
pleoni
Posts: 0
Joined: July 13th, 2006, 1:05 pm

Moodley's SV (Heston) FFT matlab code

September 8th, 2007, 7:59 am

Also check out Schoutens and Tistaert paper (see www.schoutens.be) on the heston trap where they discuss the problem with the characteristic function of heston
 
User avatar
aankz
Posts: 3
Joined: December 29th, 2007, 1:10 pm

Moodley's SV (Heston) FFT matlab code

August 12th, 2009, 5:13 am

Hello Everyone !I was trying to implement the Heston model using FFT and was following Moodleys paper for starters. I had a doubt in the code that he has given in the paper (for the FFT of the characteristic function) :x0 = log(s0);alpha = 1.25;N= 4096;c = 600;eta = c/N;b =pi/eta;u = [0:N-1]*eta;lambda = 2*b/N;position = (log(strike) + b)/lambda + 1; %position of call%value in FFT%matrixv = u - (alpha+1)*i;zeta = -.5*(v.^2 +i*v);gamma = kappa - rho*sigma*v*i;PHI = sqrt(gamma.^2 - 2*sigma^2*zeta);A = i*v*(x0 + r*T);B = v0*((2*zeta.*(1-exp(-PHI.*T)))./(2*PHI - (PHI-gamma).*(1-exp(-PHI*T))));C = -kappa*theta/sigma^2*(2*log((2*PHI - (PHI-gamma).*(1-exp(-PHI*T)))./ (2*PHI)) + (PHI-gamma)*T);charFunc = exp(A + B + C);ModifiedCharFunc = charFunc*exp(-r*T)./(alpha^2 + alpha - u.^2 + i*(2*alpha +1)*u);SimpsonW = 1/3*(3 + (-i).^[1:N] - [1, zeros(1,N-1)]); FftFunc = exp(i*b*u).*ModifiedCharFunc*eta.*SimpsonW;payoff = real(fft(FftFunc));CallValueM = exp(-log(strike)*alpha)*payoff/pi;format short;CallValue = CallValueM(round(position)); Don't you think the following line is wrongly coded : "SimpsonW = 1/3*(3 + ((-i)).^[1:N] - [1, zeros(1,N-1)]);" and should have been coded as "SimpsonW = 1/3*(3 + ((-1)).^[1:N] - [1, zeros(1,N-1)]);"Basically, there should be '-1' in the line instead of " -i "I would really appreciate if some one could confirm this. Thanks !!
Last edited by aankz on August 11th, 2009, 10:00 pm, edited 1 time in total.
 
User avatar
aankz
Posts: 3
Joined: December 29th, 2007, 1:10 pm

Moodley's SV (Heston) FFT matlab code

August 12th, 2009, 5:18 pm

I noticed that the highlighting was making it really difficult to read the code earlier .. I hope its clearer now ... and hopefully one of you can confirm my doubt and put me out of my misery ...
 
User avatar
DCH
Posts: 0
Joined: September 5th, 2005, 9:47 pm

Moodley's SV (Heston) FFT matlab code

January 6th, 2011, 12:43 pm

Hi Aankz,Sorry for the late reply - I wasn't following this thread earlier in my life :-)I agree with you that the "-i" is a mistake and should be "-1". It's not consistent with Moodley's formula in the same paper, nor with Carr and Madan's paper, nor with Simpson's Rule itself. Pleoni et al, in Schoutens article "The Little Heston Trap" I think I found an issue there. They base their proof of the choice of characteristic formula (Theorem 3) on Carr-Madan's formulation (which is specific to calls). With the put the sign of the damping term (alpha) must be negative since we must damp as k-> infinity not -infinity as with calls. Therefore, I think that their analysis is only valid for calls. Not entirely sure, as I haven't gone through their argument fully, but with alpha changing sign it looks like it breaks the argument. This was written in 1997 - I wonder if anyone has written papers on this subject recently...Regards,David.
 
User avatar
DCH
Posts: 0
Joined: September 5th, 2005, 9:47 pm

Moodley's SV (Heston) FFT matlab code

January 6th, 2011, 3:49 pm

QuoteOriginally posted by: DCHHi Aankz,This was written in 1997 - I wonder if anyone has written papers on this subject recently...Sorry, I meant 2007, and by "this" I mean Schoutens article, not Moodley's thesis.
 
User avatar
wdl
Posts: 2
Joined: October 11th, 2010, 2:59 pm

Moodley's SV (Heston) FFT matlab code

January 27th, 2011, 12:48 pm

QuoteOriginally posted by: aankzI noticed that the highlighting was making it really difficult to read the code earlier .. I hope its clearer now ... and hopefully one of you can confirm my doubt and put me out of my misery ...how do you determine the strike prices to be used for Moodley's SV (Heston) FFT matlab code? Thanks
Last edited by wdl on January 26th, 2011, 11:00 pm, edited 1 time in total.