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.