%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% %%% Option pricer for European option under Black-Scholes-Merton model using %%% the FFT method of Carr, Madan 1999 %%% %%% Copyright (C) 2008 Vladimir Surkov %%% %%% %%% This program is free software: you can redistribute it and/or modify %%% it under the terms of the GNU General Public License as published by %%% the Free Software Foundation, either version 3 of the License, or %%% (at your option) any later version. %%% %%% This program is distributed in the hope that it will be useful, %%% but WITHOUT ANY WARRANTY; without even the implied warranty of %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %%% GNU General Public License for more details. %%% %%% You should have received a copy of the GNU General Public License %%% along with this program. If not, see . %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [values_call, values_put, time] = CarrMadanFFT_European_BlackScholesMerton(S, K, T, sigma, r, q) values_call = zeros(length(S), length(K)); values_put = zeros(length(S), length(K)); time = cputime; N = 4096; nu = 0.25; alpha = 1.5; lambda = 2*pi/(nu*N); b = N*lambda/2; m =1:N; k = -b+lambda*(m-1); %Set constants const = @(m)(exp(-alpha*k(m))/pi); kron = @(n)(n==0); v = nu*(m-1); for iter_s = 1:length(S) %Set Fourier transform of pdf and payoff pdf_ft = @(u)(exp(i*u*log(S(iter_s))+ i*u*(r-q-sigma^2/2)*T-u.^2*sigma^2*T/2)); payoff_call_ft = @(u)(exp(-r*T).*pdf_ft(u-(alpha+1)*i)./(alpha^2+alpha-u.^2+i*(2*alpha+1)*u)); integrand_call = @(j)(exp(i*b*v(j)).*payoff_call_ft(v(j))*(nu/3).*(3+(-1).^(j)-kron(j-1))); %Matlab uses -i in fft, thus use forward transform, not backward values = real(const(m).*fft(integrand_call(1:N))); values_call(iter_s,:) = interp1(exp(k), values, K); values_put(iter_s,:) = values_call(iter_s,:) - S(iter_s)*exp(-q*T) + K*exp(-r*T); end time = cputime - time; time = time*2; % because we use put-call parity for put options