For loop in GARCH Monte Carlo Simulation
2 次查看(过去 30 天)
显示 更早的评论
Dear all,
I am trying to run a monte carlo simulation on a GARCH based conditional variance model, but I fail to correctly implement a loop into the code. I would like to simulate 10000 paths each for 250 days and the resulting output variables SimInno and SimVar should not be overwritten with each step, but added one column each time the loop runs (so I would like to get two 250x10000 arrays from the original 1x10000 arrays).
Any help would be highly appreciated.
SimInno = VolGARCHsp(end).*normrnd(0,1,10000,1) %starting value VolGARCHsp stems from an estimated GARCH model
SimVar = ParGARCHsp(end,1) + ParGARCHsp(end,2).*SimInno.^2 + ParGARCHsp(end,3).*VolGARCHsp(end).^2 %parameters ParGARCHsp come from the same model
for i = 1:250
SimInno = SimVar(i).*normrnd(0,1,10000,1)
SimVar = ParGARCHsp(end,1) + ParGARCHsp(end,2).*SimInno(i+1) + ParGARCHsp(end,3).*SimVar(i+1)
end
Leo
0 个评论
采纳的回答
Asvin Kumar
2021-2-8
I'm unsure what the variables mean. If what you are trying to do is preserve the values at each step of your for loop, you can do that by pre-allocating an array and filling up each row of it. Here's a template you can adapt from:
varA = zeros(25+1,10); % preallocate as required
varB = zeros(25+1,10); % "
varA(1,1:10) = 2*ones([1,10]); % start values
for i=2:26
varA(i) = varA(i-1)+varB(i-1); % use your formula here
varB(i) = varA(i-1)-varB(i-1); % use your formula here
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Conditional Variance Models 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!