Serving the Quantitative Finance Community

 
User avatar
vipulas
Topic Author
Posts: 0
Joined: March 20th, 2007, 6:54 am

Option Pricing with FFT using Matlab

September 27th, 2007, 2:38 pm

Hi all,I'm newbie and trying to price an option using FFT as described in Carr Madan paper (1999) (Option Pricing with FFT , The Carr Madan paper ) I was following few sample codes and they have different implementations. I'm using the Variance Gamma Model. The sample 1 (Link to Source) (Characteristic function) According to the paper we need to get the characteristic function phi(v) and then have to generate the psi as in equation (6) in the paper. Then I have to plug that psi to the equation (24) to use the FFT on it to get the summation. But in the above matlab implementation they have directly used phi instead of psi. I tried modifying the code accordingly to implement the psi but it gives me a wired out put. (Please find the code below) Have I miss understood anything or have I made an error in my code. I really appreciate if someone could give me a hint on this. Cheers,Vijayfunction y = MyFFT%Option pricing using the FFT Carr Madan Method%Define the Parametersnu = .16;So = .98; % Stock Pricels = log(So); % Log Stock PriceX = 1; K = X/So% Strike Pricelk = log(K); % Log Strike Pricer = 0.059; % Risk free interest rateT = 1; % Maturity yearsigma = 0.12; % Volatilitytheta = -0.33; % theta of VG Model's characteristic function equation (26)% FFT will return N values of ln(K) values hence need to employ a regular% spacing %Define Parameteres for the GRID% All the Parameters are defined as sugested by Carr Madan% parametersa = 600; % endpoint of char fun grid (0,+a) we can either choose eta or a as in equation (18)N = 4096; % Required summations to approxymate the inegral. as in equation (24) % Normally deploy a power of 2. then Matlab uses % radix-2 algorithm wich is very fast.eta = a/N; % where a = N* eta is the effective upper limit for the integration as in equation (18)b = pi/eta % the bounds of the retuned log strike level. equation (19) lambda = (2*b)/N; % lambda = (2*b)/N lambda is the regular spacing set for the lk = log(K)%a= (2*pi)/lambda; % alpha = 1.5; % lambda has to be used to make integral of the call price square integrable %equation (3) the value of alpha is decided considering the condition in equation (7)u = (0:N-1) * eta ; % Vj as in Vj = (j -1 ) *etaku = -b + lambda * (0:N-1); % equation (19) empoying regular spacing for retunrd ku% derive the characteristic functionphi = u - (( alpha + 1) * i); % will be used when computing zhi(v) using the characteristic % function phi as in Equation (6)% Use the characteristic fucntion of VG cf = vgcf_vip(phi,theta,nu,sigma,T,r,So);v=nu;f1 = exp(-r*T) .*cf;f2 = (alpha^2 + alpha - u.^2 + i*(2*alpha + 1));zzhi = f1 ./ f2;% Create Simpson's weightsN = size(u,2);q1 = (-1).^(1:N);q2 = eye(1,N); % implements the direct deltaS = ( 3 + q1 - q2 )/3;zhi = zzhi .* S;%cft = zhi(nu,u);ft = fft( exp(i * b * u) .* zhi * eta );%cft=zhi(nu,u);Return_ku = real(ft .* exp(-alpha * ku ) /pi);%plot(exp(ku),Return_ku) plot (exp(ku),Return_ku)axis([.0 1.3 -1 1.5])grid ontitle 'Call Price VS K'xlabel 'Strike'ylabel 'Call Price'%plot (exp(ku))
 
User avatar
vipulas
Topic Author
Posts: 0
Joined: March 20th, 2007, 6:54 am

Option Pricing with FFT using Matlab

September 27th, 2007, 6:41 pm

Hi ,I was wondering whether I posted my question on the wrong place. Do aplogise if I have and for wasting ur time.Thank you.-Vijay
Last edited by vipulas on September 27th, 2007, 10:00 pm, edited 1 time in total.
 
User avatar
LordR
Posts: 1
Joined: July 14th, 2002, 3:00 am

Option Pricing with FFT using Matlab

September 28th, 2007, 5:43 pm

I'm not going to debug your code but you might check some easy things:* First moment equals forward of stock from your characteristic function* Do you price back the forward via Carr-Madan (if you let the strike tend to 0 ... etc.)* Why don't you just use the integration functions of Matlab directly? (you can pass it a function and it will do it for you - less error prone)Regs,Roger.
 
User avatar
vipulas
Topic Author
Posts: 0
Joined: March 20th, 2007, 6:54 am

Option Pricing with FFT using Matlab

October 2nd, 2007, 7:28 am

Hi LordR,Thanks for the advice. Actually I spot the error. -Vijay
 
User avatar
gerardpique
Posts: 0
Joined: October 22nd, 2012, 1:09 pm

Option Pricing with FFT using Matlab

October 22nd, 2012, 4:00 pm

Hello Vijay,I also have to price an option with fft (with underlying following VG process). My code looks like yours (see below), the prices I get seem reasonable but they don't match the B&S prices when theta=nu=0.Do you have an idea or can you send pls me your code so that I can compare?Many thanksfunction CallValue = VGCallFft(theta,nu,V0,r ,S0,strike,T)strike=strike/S0;x0 = log(S0);alpha = 1.5;N= 4096;c =4096/4;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;ku = -b + lambda * (0:N-1); charFunc=VG_char_function(theta, nu, V0, 1,r,T, v);ModifiedCharFunc = charFunc*exp(-r*T)./(alpha^2 + alpha - u.^2 + i*(2*alpha +1)*u);%formulaSimpsonW = 1/3*(3 + (-1).^[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 = S0*CallValueM(round(position));
 
User avatar
Lapsilago
Posts: 5
Joined: October 15th, 2004, 7:36 am
Location: Germany

Option Pricing with FFT using Matlab

October 24th, 2012, 5:24 am

Hi,all you need you can find here:http://www.mathworks.de/matlabcentral/f ... :246981The theory and details on the implementation are revealed in the corresponding book. "Financial Modelling, Theory, Implementation and Practice (with Matlab source)".Best, Lapsi
 
User avatar
gerardpique
Posts: 0
Joined: October 22nd, 2012, 1:09 pm

Option Pricing with FFT using Matlab

November 7th, 2012, 10:20 am

Hello Lapsi,Thank you very much for your answer. Sorry for the late reply I thought I would receive a notification on my e-mail adress if someone responded to one of my questions. Thank you!