Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VaR and ES calculation #63

Closed
Nofearwithbeer opened this issue May 11, 2020 · 1 comment
Closed

VaR and ES calculation #63

Nofearwithbeer opened this issue May 11, 2020 · 1 comment

Comments

@Nofearwithbeer
Copy link

Error: Error in out$VaR[n, i] <- x[which.min(abs(cumul[, n] - alpha[i]))] :
replacement has length zero

Code:
nots<- 1196 #length of outsample evaluation
nits<- 3000 #length of insample data (fit sample size)
alpha<- c(0.01 , 0.05) #Risk level
update<- 7 #Estimation Frequency

GBPits<- GBPr[i:(nits+i-1)]
GBPots<- matrix(NA, nrow = nots, ncol = 1)
#BEST EURO
BestGBPES_0.01<-matrix(NA, nrow = nots, ncol = 1)
BestGBPES_0.025<-matrix(NA, nrow = nots, ncol = 1)

for (i in 1:nots)
{
GBPits<- GBPr[i:(nits+i-1)] # rolling estimation window of last 365 obs (updates the in-sample observations)

cat("VaR forecasts vs. out-of-sample: ", i, "\n")

if (i %% update == 1) # if modulus is 1 (rest after division, 8/7=1 ; 15/7=1 etc) -> every 7 days update
{
BestGBPfit <- FitML(spec = EGARCH2.EGARCH3 ,data = GBPits) # reestimate model with updated in-sample observations

cat("Best model is reestimated \n")

}

GBPots[i] <- GBPr[nits+i] # pick corresponding to VaR forecast out-of-sample observation for the later backtesting

BestGBPES_0.01[i] <- Risk(object = BestGBPfit$spec, # fill entry by ES, using specification of model
par = BestGBPfit$par, # using parameters
data = GBPits, # use updated 365 in-sample obs as rolling window to give VaR forecast
alpha = 0.01, # quantile
nahead = 1, # horizon
do.es = TRUE)$ES # ES

BestGBPES_0.025[i] <- Risk(object = BestGBPfit$spec,
par = BestGBPfit$par,
data = GBPits,
alpha = 0.025,
nahead = 1,
do.es = TRUE)$ES
}

I am facing this issue with two exchange rate data sets.
can you help ?

@keblu
Copy link
Owner

keblu commented May 11, 2020

It seems like an estimation issue perhaps at some point in the loop, we often get it with EGARCH and probably should look more once time is not an issue. Hard to check now without the time series. You could try using the past parameter estimates as the starting value for the subsequent one. This can be set up by setting: ctr = list(par0 = SomeOldEstPar) in FitML()

@keblu keblu closed this as completed Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants