Financial optimization of heston
4 views (last 30 days)
Show older comments
Simon Christensen
on 3 Dec 2023
Commented: Dyuman Joshi
on 26 Dec 2023
Hi Matlab,
At the moment I'm pricing options, and I have written the code below to calibrate a pricing-model (the model is shown below here)
function [Call_SV] = Price_SV(Sigma, Kappa, Theta, eta, VIX, vT, vt, K, r, y)
Alpha= (1-exp(-Kappa.*((30./365))))./(Kappa.*(30./365));
Beta = (Theta).*(1-Alpha);
%c_2 = (2.*Kappa)./(eta.^2.*(1-exp(-Kappa.*(vT-vt))));
%w = c_2.*(V.*exp(-Kappa.*(vT-vt)));
%q = ((2.*Kappa.*Theta)./(eta.^2))-1;
%I_q = besseli(q,2.*sqrt(w.*c_2.*y));
%gV = c_2.*exp(-w-c_2.*y).*((c_2./y)./w).^(q/2).*I_q
c_2 = (2.*Kappa)./((eta.^2).*(1-exp(-Kappa.*(vT-vt))));
w = c_2.*(((((VIX.^2)-Beta)./Alpha)).*exp(-Kappa.*(vT-vt)));
q = ((2.*Kappa.*Theta)./(eta.^2))-1;
X = 2.*sqrt(w.*c_2.*((y.^2 -Beta)./Alpha));
I_q = besseli(q, X);
gV_inv = ((2.*y)./Alpha).*(c_2.*exp(-w-c_2.*((y.^2 -Beta)./Alpha)).*((c_2./((y.^2 -Beta)./Alpha))./w).^(q/2).*I_q);
INT = integral(@(y) max(y-K,0).*gV_inv, 0, inf, 'RelTol',0,'AbsTol',1e-8);
Call_SV = exp(-r.*(vT-vt)).*INT;
%Feller 2*Kappa*Theta > eta
%con1 = 2.*Kappa.*Theta > eta;
%other condition y > sqrt(Beta) (otherwise zero)
%con2 = y > sqrt(Beta);
end
%Test the model: Price_SV(0.61, 3.21, 0.19, 0.7, 1, 0.8, 0.7, 2, 0.1, 5)
Now my question is, how do I write code to calibrate my model?
I have to minimize sum of squarred residuals (using lqsnonlin), but how do I write the code?
Attempt:
%Price_SV(Sigma, Kappa, Theta, eta, VIX, vT, vt, K, r, y)
% Estimate model parameters
options = optimoptions('lsqnonlin','Display', 'iter-detailed', 'PlotFcn', 'optimplotresnorm', 'MaxIterations', 10000, 'TolFun', 10^-12 );
lsqnonlin(@Error, [0.5 0.5 0.5 0.7 0 0], [0 0 0 0 0], [10 10 10 10 10], options)
where Error is sum(data-Price_SV).^2
Any help appreciatet, really struling with this one, thanks alot!
Best regards Karnow
17 Comments
Accepted Answer
Torsten
on 3 Dec 2023
Moved: Torsten
on 3 Dec 2023
Assuming that Price_SV returns a vector of the same size as P_data, your call would look somehow like
fun =@(p)Price_SV(p(1), p(2), p(3), p(4), p(5), vT, vt, K, r, yconst) - P_data;
p0 = [0.61, 3.21, 0.19, 0.7, 1];
p = lsqnonlin(fun,p0)
or maybe
fun = @(p)arrayfun(@(K,P_data)Price_SV(p(1), p(2), p(3), p(4), p(5), vT, vt, K, r, yconst) - P_data,K,P_data)
if each element of K(i) gives the value of Price_SV(i) that is to be compared with P_data(i).
10 Comments
Torsten
on 3 Dec 2023
%Price_SV(Sigma, Kappa, Theta, eta, VIX, vT, vt, K, r)
%https://se.mathworks.com/help/fininst/calibrate-option-pricing-model-using-heston-model.html
rho_J =0
Mu_V =0
Mu_S =0
Lambda =0
S = [Spot(2), Spot(3) Spot(4), Spot(5), Spot(6)]
%concatenate prices, real and theo:
Prices_true= [m2(:,2,1); m3(:,2,1); m4(:,2,1); m5(:,2,1); m6(:,2,1)]
K_true= [m2(:,3,1); m3(:,3,1); m4(:,3,1); m5(:,3,1); m6(:,3,1)]
S_array = [S(1)*ones(size(m2(:,2,1)));...
S(2)*ones(size(m3(:,2,1)));...
S(3)*ones(size(m4(:,2,1)));...
S(4)*ones(size(m5(:,2,1)));...
S(5)*ones(size(m6(:,2,1)))];
r_array = [r(2)*ones(size(m2(:,2,1)));...
r(3)*ones(size(m3(:,2,1)));...
r(4)*ones(size(m4(:,2,1)));...
r(5)*ones(size(m5(:,2,1)));...
r(6)*ones(size(m6(:,2,1)))];
vT_array = [vT(2)*ones(size(m2(:,2,1)));...
vT(3)*ones(size(m3(:,2,1)));...
vT(4)*ones(size(m4(:,2,1)));...
vT(5)*ones(size(m5(:,2,1)));...
vT(6)*ones(size(m6(:,2,1)))];
vt_array = [vt(2)*ones(size(m2(:,2,1)));...
vt(3)*ones(size(m3(:,2,1)));...
vt(4)*ones(size(m4(:,2,1)));...
vt(5)*ones(size(m5(:,2,1)));...
vt(6)*ones(size(m6(:,2,1)))];
fun = @(Param)arrayfun(@(K_true,Prices_true,S_array,r_array,vT_array,vt_array)Prices_true-SV_Heston(Param(1), Param(2), Param(3), Param(4), Param(5), rho_J, Mu_V, Mu_S, Lambda, S_array, K_true, r_array, vT_array, vt_array, 0.25),K_true,Prices_true,S_array,r_array,vT_array,vt_array);
p0 = [3 0.25 0.25 0.25 0.095];
lb = [0 0 0 0 0]
sol = lsqnonlin(fun, p0, lb)
More Answers (0)
See Also
Categories
Find more on Surrogate Optimization in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!