For loop in GARCH Monte Carlo Simulation

1 view (last 30 days)
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

Accepted Answer

Asvin Kumar
Asvin Kumar on 8 Feb 2021
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
GARCH models are not my area of expertise. This example on simulating GARCH models might help.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!