使用f中的fGarch包进行风险评估的价值

时间:2017-04-19 13:52:14

标签: r simulation estimation

我正在尝试对McNeil& amp;弗雷在他们的论文“估计异方差金融时间序列的尾部相关风险度量:极端值方法”但我在实施模型时遇到了问题。

该方法是拟合AR(1)-GARCH(1,1)模型,以便使用1000个观测值的窗口估计VaR的提前一天预测。

我已经模拟了我的模型应该可以正常工作的数据,并且我认为如果我这样做是正确的,那么观察到的覆盖率应该接近理论值。然而,它总是低于理论覆盖率,我不知道为什么。

我相信这就是计算估计VaR的方式

VaR_hat = mu_hat + sigma_hat * qnorm(alpha)

,但我可能错了。我曾尝试在堆栈中找到相关问题,但我没有找到任何问题。

我如何处理这个问题可归纳为三个步骤。

  1. 模拟2000 AR(1)-GARCH(1,1)观测并拟合相应的模型,并使用1000个观测值的窗口提取条件均值和标准差的一天预测。(从而进行1000次预测)

  2. 使用预测值和正态分位数来计算所需置信水平的VaR。

  3. 检查覆盖率是否接近理论值。

  4. 如果有人可以帮助我,我会非常感激,如果我不清楚我的形式,请告诉我,我会尝试对问题提出更好的解释。

    我正在使用的代码附在下面。 提前谢谢

    library(fGarch)
    
    nObs <- 2000                  # Number of observations.
    quantileLevel <- 0.95         # Since we expect 5% exceedances.  
    from <- seq(1,1000)           # Lower index vector for observations in model.
    to <- seq(1001,2000)          # Upper index vector for observations in model.
    VaR_vec <- rep(0,(nObs-1000)) # Empty vector for storage of 1000 VaR estimates.
    
    # Specs for simulated data (including AR(1) component and all components for GARC(1,1)).
    spec = garchSpec(model = list(omega = 1e-6, alpha = 0.08, beta = 0.91, ar = 0.10),
                 cond.dist = 'norm')
    # Simulate 1000 data points.
    data_sim <- c(garchSim(spec, n = nObs, n.start = 1000))
    
    for (i in 1:1000){
      # The rolling window of 1000 observations.
      data_insert <- data_sim[from[i]:to[i]]
      # Fitting an AR(1)-GARCH(1,1) model with normal cond.dist.
      fitted_model <- garchFit(~ arma(1,0) + garch(1,1), data_insert,
                           trace = FALSE,
                           cond.dist = "norm")
      # One day ahead forecast of conditional mean and standard deviation.
      predict(fitted_model, n.ahead = 1)
      prediction_model <- predict(fitted_model, n.ahead = 1)
      mu_pred <- prediction_model$meanForecast
      sigma_pred <- prediction_model$standardDeviation
      # Calculate VaR forecast
      VaR_vec[i] <- mu_pred + sigma_pred*qnorm(quantileLevel)
    
      if (length(to)-i != 0){
        print(c('Countdown, just',(length(to) - i),'iterations left'))
      } else {
        print(c('Done!'))
      }
    }
    
    # Exctract only the estiamtes ralated to the forecasts.
    compare_data_sim <- data_sim[1001:length(data_sim)]
    hit <- rep(0,length(VaR_vec))
    # Count the amount of exceedances. 
    for (i in 1:length(VaR_vec)){
      hit[i] <- sum(VaR_vec[i] <= compare_data_sim[i])
    }
    
    
    plot(data_sim[1001:2000], type = 'l', 
     ylab = 'Simulated data', main = 'Illustration of one day ahead prediction of 95%-VaR')
    lines(VaR_vec, col = 'red')
    
    cover_prop <- sum(hit)/length(hit)
    print(sprintf("Diff theoretical level and VaR coverage = %f", (1-quantileLevel) - cover_prop))
    

0 个答案:

没有答案