[R-SIG-Finance] historical simulation with EWMA fitting

J Konnonen jkonn2001 at yahoo.com
Mon Dec 1 09:07:07 CET 2008


Dear All,

I am trying to do a historical simulation with EWMA fitting for the variances, but I ran into some problems

The relevant part of my code is the following (using the EWMA function in fTrading package)

> for (k in 1:trading.days)
> {
> #losses vector is updated every day in the simulation
> lambdaval <- 0.94
> mod <- EWMA(losses^2, lambda=lambdaval) 
> nn <- length(losses)
> lastX <- losses[nn]
> lastSigma2 <- mod[nn]
> meanloss <- mean(losses)
> varloss <- (1-lambdaval)*lastX^2 + lambdaval*lastSigma2
> VaR <- meanloss + sqrt(varloss)*qnorm(0.95)
> } #for k

However, for some reason it doesn't produce the expected results.

I ran the same simulation on the same data with GARCH fitting for the standard deviations, and that works perfectly. 

My debugging showed that the obvious difference between my GARCH and EWMA fittings is, that while the values in the yearly timeseries of the standard deviations from the GARCH fitting move with minimal change from one day to another, the variances from the above EWMA fitting are jumping almost random from day to day in a fairly wide range, resulting the varloss and the VaR variables also do the same. 

I also tried to do the EWMA fitting using the ewmaSmooth function in the qcc package the following way

> x <- 1:1000
> modsmooth <- ewmaSmooth(x, losses1000^2, lambda=lambdaval)
> lastSigma2 <- modsmooth$y[nn,1]        

and it seemed to result the same behaviour is above. 

So I suppose I must do something wrongly in coding the EWMA fitting itself, but I was not able to figure it so far

Any suggestions are very much appreciated.

Best regards,
/Johan



More information about the R-SIG-Finance mailing list