我想在MATLAB中使用Garch 1,1模型来估计调整波动率加权的回报时间序列。然而,当我运行代码时,使用标准的MATLAB函数,我在生成正确的返回向量时遇到了困难,我正在寻找进一步构建它的方法。
有人有Garch 1,1模型可以在函数内运行并将调整后的波动率序列作为向量输出吗?
这是模型
function [vols] = modelGarchVol(omega, beta, alpha, returns)
variance_vec = zeros(length(returns), 1);
variance_vec(2) = returns(1)^2;
for i=3:length(variance_vec)
variance_vec(i) = omega + alpha*returns(i-1)*returns(i-1) + beta*variance_vec(i-1);
end
variance_vec;
mean(variance_vec);
vols = variance_vec(2:end).^(1/2);
和garch vol
function [params,fval] = garchVol(initial_params, returns)
A = [0 1 1];
b = [1];
[params, fval] = fmincon(@maxGarchParams, initial_params, A, b, [], [], [0 0 0]);
function [logLikelihood] = maxGarchParams(params_vec)
omega = params_vec(1);
beta = params_vec(2);
alpha = params_vec(3);
variance_vec = zeros(length(returns), 1);
variance_vec(2) = returns(1)^2;
logLikelihood = 0;
for i=3:length(variance_vec)
variance_vec(i) = omega + alpha*returns(i-1)*returns(i-1) + beta*variance_vec(i-1);
logLikelihood = logLikelihood + (-log(variance_vec(i)) - ((returns(i)*returns(i))/variance_vec(i)));
end
logLikelihood = logLikelihood*-1;
end
end