Serving the Quantitative Finance Community

 
User avatar
jellysky
Topic Author
Posts: 0
Joined: April 19th, 2005, 1:32 am

Problem using FFT to get prob dist in Matlab

May 2nd, 2009, 1:25 am

I am trying to use the Fast Fourier Transform to derive the probability distribution for an affine jump diffusion model. For some reason, I am having an enormously difficult time doing this in Matlab. I have posted my code below for trying to derive the Gaussian distribution from the Gaussian characteristic function (sort of like the Moment Generating Function). However I need to divide the resultant pdf by the interval size and still I get too much probability in the extremes (I keep getting probability's of 0.025 out for x's > 5 and x's < -5). Can someone please help me figure out what I am doing wrong.....Thanks.l = -10;u = 10;T = 512;dx = (u-l)/T;n = [0:T-1];x = (l)+n*dx; %my pdf x'st = [0:1:T-1];s_t = 2*pi*t/(T*dx); %my s's for the Gaussian characteristic functionmu = 0;sigma = 1;lambda = 2;norm = exp(s_t.*i.*mu - 0.5.*(sigma.*s_t).^2 - i.*s_t.*l); %Gaussian characteristic function (MGF except with 'it' substituted for 't'pdfnorm = real(fft(norm))./(u-l);plot(x,pdfnorm); %the whole distribution is wrong....it has too much probability at the extremes...and it does this even when I increase T or increase l and u...HELP!!!This is what the pdf and psi function should look like xlr=10; np=512; dx=2*xlr/np; x=dx*[0:np-1]-xlr; % OR, equivalently x=linspace(-xlr,xlr-dx,np); normp1 = pdf('norm',x,0,1); fnormp1 = fft(normp1); normp1after = ifft(fnormp1); plot (x,normp1)
Last edited by jellysky on May 1st, 2009, 10:00 pm, edited 1 time in total.
 
User avatar
dobranszky
Posts: 0
Joined: January 8th, 2006, 11:53 am

Problem using FFT to get prob dist in Matlab

May 6th, 2009, 10:58 pm

You miss two things: the weightening by cutting the tails and a multiplication by two at the end. Please, see below.Best regards, Peterl = -10;u = 10;T = 512;dx = (u-l)/T;n = [0:T-1];x = (l)+n*dx; %my pdf x'st = [0:1:T-1];s_t = 2*pi*t/(T*dx); %my s's for the Gaussian characteristic functionmu = 0;sigma = 1;lambda = 2;w = 1/3 * (3 + (-1).^[1:T] - [1, zeros(1,T-1)]); % Simpson rule%w = [0.5 ones(1,N-2) 0.5]; % Trapezoid rulenorm = exp(s_t.*i.*mu - 0.5.*(sigma*s_t).^2 - i.*s_t.*l) .* w;pdfnorm = real(fft(norm))./u;plot(x,pdfnorm);
 
User avatar
hamster
Posts: 1
Joined: October 12th, 2008, 3:51 pm

Problem using FFT to get prob dist in Matlab

May 14th, 2009, 11:52 am

other entry at wilmott some matlab codeit's about this bias correction. it can drive you crazy...