%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% %%% Option pricer for European option under Black-Scholes-Merton model using %%% the Fourier Space Time-stepping method %%% %%% 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] = FST_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 = 8192; % Real space x_min = -7.5; x_max = 7.5; dx=(x_max-x_min)/(N-1); x=x_min:dx:x_max; s = 0.5*(S(1)+S(end))*exp(x); % Fourier space w_max=pi/dx; dw=2*w_max/N; w=[0:dw:w_max, -w_max+dw:dw:-dw]; % FST method char_exp_factor = exp((i*(r-0.5*sigma^2-q).*w-0.5*(sigma*w).^2-r)*T); fftw('planner', 'measure'); for iter_k = 1:length(K) %FST algorithm payoff = max(s-K(iter_k),0); values = real(ifft(fft(payoff).*char_exp_factor)); values_call(:,iter_k) = interp1(s,values,S,'cubic'); payoff = max(K(iter_k)-s,0); values = real(ifft(fft(payoff).*char_exp_factor)); values_put(:,iter_k) = interp1(s,values,S,'cubic'); end time = cputime - time;