My code is
load returns.TXT;
%%I n i t i a l gues s , parameter s and data ar e de f ined
% NOTE: mu = the ta ( 1 ) ; sigma = the ta ( 2 ) ; lambda = the ta ( 3 ) ; p =theta ( 4 ) ;
% etaPlus = theta ( 5 ) ; etaMinus = the ta ( 6 ) ;
disp ( 'The i n i t i a l gue s s f o r the parameter ve cor i s ( [mu sigmalambda p e taPlus etaMinus ] ) ' ) ;
theta0 = [0.25 0.2 50 0.5 0.05 0.05]; % initial guess for theta
K = 60 ; % +/? K i s the upper / lower i n t e g r a t i o n bound , as byCont & Tankov
gap_halfwidth = 0.02 ; % Hal fwidth o f gap around 0 in the integration interval
stock_prices= returns(:,2);
period_length = round ( length ( stock_prices ) /252) ;
time_resolution = period_length / length(stock_prices ) ;
logreturns = zeros ( length ( stock_prices )-1 ,1) ;
for i =1:( length ( stock_prices )-1)
logreturns ( i ) = log ( stock_prices ( i +1 ,1) / stock_prices( i , 1 ) );
end
sigma_star = std(logreturns ) ;
%%The distance integra1 is defined as a function of theta
integrand = @(u,theta) abs(characteristic_exponent(u,theta)...
-empirica1_characteristic_exponent(u,logreturns,time_resolution)).^2 ...
.*weight (u , sigma_star) ;
distance = @(theta) integral(@(u) integrand(u ,theta),-K, -gap_halfwidth )...
+ integral(@(u) integrand(u,theta), gap_halfwidth , K) ;
%%An opt imi z a t i on r out ine i s used to f i n d the minimizing theta
options = optimset ( 'MaxFunEvals ' , 100000 , 'MaxIter ' ,100000 , 'TolX ' , 1e-6);
lb=[-Inf 0 0 0 0 0 ] ;
ub=[ Inf Inf Inf 1 Inf 0.9999 ] ;
disp ( 'The CONSTRAINED c a l i b r a t i o n r e s u l t i s ( [mu sigma lambda p etaPlus etaMinus ] ) ' ) ;
theta_cal_const = fmincon(distance , theta0 , [] , [] , [] , [] , lb , ub ,[] , options );
disp ( 'The ca libration result is ( [mu sigma lambda p e taPlus etaMinus ] ) ' ) ;
theta_cal = fminsearch ( distance , theta0 ,options )