For loop in GARCH Monte Carlo Simulation
조회 수: 1 (최근 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!