Borrar filtros
Borrar filtros

Financial optimization of heston

4 visualizaciones (últimos 30 días)
Simon Christensen
Simon Christensen el 3 de Dic. de 2023
Comentada: Dyuman Joshi el 26 de Dic. de 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 comentarios
Rena Berman
Rena Berman el 26 de Dic. de 2023
(Answers Dev) @Dyuman Joshi, I restored the comments.
Dyuman Joshi
Dyuman Joshi el 26 de Dic. de 2023
Thank you, Rena!

Iniciar sesión para comentar.

Respuesta aceptada

Torsten
Torsten el 3 de Dic. de 2023
Movida: Torsten el 3 de Dic. de 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 comentarios
Simon Christensen
Simon Christensen el 3 de Dic. de 2023
Editada: Simon Christensen el 26 de Dic. de 2023
Hmmm, i tried this one
%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(:,3,1)]
K_true= [m2(:,3,1); m3(:,3,1); m4(:,3,1); m5(:,3,1); m6(:,3,1)]
M2 = @(Param) SV_Heston(Param(1), Param(2), Param(3), Param(4), Param(5), rho_J, Mu_V, Mu_S, Lambda, S(1), K_true(1), r(2), vT(2), vt(2), 0.25);
M3 = @(Param) SV_Heston(Param(1), Param(2), Param(3), Param(4), Param(5), rho_J, Mu_V, Mu_S, Lambda, S(2), K_true(3), r(3), vT(3), vt(3), 0.25);
M4 = @(Param) SV_Heston(Param(1), Param(2), Param(3), Param(4), Param(5), rho_J, Mu_V, Mu_S, Lambda, S(3), K_true(4), r(4), vT(4), vt(4), 0.25);
M5 = @(Param) SV_Heston(Param(1), Param(2), Param(3), Param(4), Param(5), rho_J, Mu_V, Mu_S, Lambda, S(4), K_true(5), r(5), vT(5), vt(5), 0.25);
M6 = @(Param) [SV_Heston(Param(1), Param(2), Param(3), Param(4), Param(5), rho_J, Mu_V, Mu_S, Lambda, S(5), K_true(6), r(6), vT(6), vt(6), 0.25);
M = {M2, M3, M4, M5, M6}
%Construct objective function
fun = @(Param) arrayfun(@(K_true,Prices_true) Prices_true - M K_true,Prices_true);
p0 = [3 0.25 0.25 0.25 0.095];
lb = [0 0 0 0 0]
sol = lsqnonlin(fun, p0, lb)
But unfortunately, once it is a function handle datatype, it is not possible to subtract. Do you know how I can proceed?
Torsten
Torsten el 3 de Dic. de 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)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by