GARCH to predict VaR using rolling window

14 visualizzazioni (ultimi 30 giorni)
Chad
Chad il 19 Feb 2024
Risposto: Manikanta Aditya il 26 Feb 2024
I have been trying to measure VaR using rolling window and estimate VaR using GARCH.
To do so I have implemented below loop. However, I am uncertain below method is correctly impplemented. Due to my lack of knoweldge in Matlab.
Would someone please guide me through this?
for t = startIdx:numReturns
% Get the window of returns
windowReturns = returns((t - rollingWindowSize):(t - 1));
% Calculate the parametric VaR using the normal distribution
windowMean = mean(windowReturns);
windowStd = std(windowReturns);
parametricVaR(t) = windowMean - zScore * windowStd;
% Calculate the parametric VaR using the t-distribution
pd = fitdist(windowReturns, 'tLocationScale');
tQuantile = tinv(confidenceLevel, pd.nu);
parametricTVaR(t) = windowMean - tQuantile * windowStd; % Negative sign for loss
% Fit the GARCH(1,1) model and forecast the next period's variance
garchModel = garch('GARCHLags',1,'ARCHLags',1);
[estGarchModel,~,~,~] = estimate(garchModel, windowReturns, 'Display', 'off', 'Options', options);
[condVar, ~] = infer(estGarchModel, windowReturns);
garchVaR(t) = windowMean - zScore * sqrt(condVar(end));
% Fit the GARCH(1,1) with tdistribution model and forecast the next period's variance
garchModelt = garch('GARCHLags',1,'ARCHLags',1,'Distribution','t');
[estGarchModelt,~,~,~] = estimate(garchModelt, windowReturns, 'Display', 'off', 'Options', options);
[condVargarcht, ~] = infer(estGarchModelt, windowReturns);
dofgarcht = estGarchModelt.Distribution.DoF;
tQuantilegarch = tinv(confidenceLevel, dofgarcht);
garchTVaR(t) = windowMean - tQuantilegarch * sqrt(condVargarcht(end));
% Fit the EGARCH(1,1) model and forecast the next period's variance
egarchModel = egarch('GARCHLags',1,'ARCHLags',1,'Distribution','t');
[estEgarchModel,~,~,~] = estimate(egarchModel, windowReturns, 'Display', 'off', 'Options', options);
[condVarEgarch, ~] = infer(estEgarchModel, windowReturns);
dofEgarch = estEgarchModel.Distribution.DoF;
tQuantileEgarch = tinv(confidenceLevel, dofEgarch);
egarchTVaR(t) = windowMean - tQuantileEgarch * sqrt(condVarEgarch(end));
end

Risposte (1)

Manikanta Aditya
Manikanta Aditya il 26 Feb 2024
Hi Chad,
I feel your implementation looks correct and relevant.
Here is what I understood from the loop implementation you shared:
  • For each time point in your data, you’re creating a rolling window of returns.
  • You’re then calculating the mean and standard deviation of the returns within this window.
  • Using these statistics, you’re calculating the parametric Value at Risk (VaR) under the assumption of normality. This is done by subtracting the product of the z-score and the standard deviation from the mean.
  • You’re also fitting a t-distribution to the window of returns and calculating the parametric VaR under this distribution.
  • You’re fitting a GARCH (1,1) model to the window of returns and forecasting the next period’s variance. You’re then using this forecast to calculate the VaR under the GARCH model.
  • You’re doing the same as step 5, but assuming a t-distribution for the innovations in the GARCH model.
  • Finally, you’re fitting an EGARCH (1,1) model to the window of returns and calculating the VaR under this model.
Here are few suggestions from my end to make your implementation more effective:
  • Make sure that ‘startIdx’ is greater than ‘rollingWindowSize’ to avoid negative indexing.
  • Ensure that ‘zScore’ and ‘confidenceLevel’ are defined before the loop.The 'zScore' is the number of standard deviations away from the mean, and it’s related to the 'confidenceLevel'. For example, for a 95% confidence level, the 'zScore' would be approximately 1.96
  • The options variable used in the estimate function should be defined before the loop.
  • The ‘infer’ function gives you the conditional variances of the entire series, not just the next period. You might want to use the 'forecast' function instead if you’re interested in the next period’s variance.
Check the following reference to know more about ‘forecast’ function:
Hope this helps!

Prodotti


Release

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by