Reputation: 1065
I have a series of stock log returns, say, 100 values. I want to use GARCH to predict the volatility at time 101. If I use the garch function from tseries package, I would call it like this:
garch(myData, order=c(1, 1))
So considering p = q = 1. This function returns an object which contain 100 fitted values (the first being NA), coefficients (a0, a1 and a2) and 100 residuals (again the first being NA). How do I use this information to predict volatility at time 101?
My first guess was calculating:
Vol_101 = a0 + a1 * fitted.values[100] + a2 * residuals[100]
But judging by the results I get this is definitely not right. How could I use GARCH information to predict volatility from a time period that was not part of the original data?
Many thanks,
Chicoscience
Upvotes: 1
Views: 6889
Reputation: 709
In package fGarch
,there is a function predict
which can help you get volatility out of sample.
example as fellows:
library(fGarch)
da=read.table("m-intcsp7309.txt",header=T)
intc=log(da$intc+1)
length(intc)
#numbers of sample is 444
m4=garchFit(~1+garch(1,1),data=intc,trace=F)
condPre <- predict(m4, n.ahead = 5)
condPre$standardDeviation
standardDeviation
has stored volatility out of sample(from 445 to 449)
standardDeviation
is just conditional standard deviation!
Upvotes: 0
Reputation: 942
perhaps you can use the fGarch
package:
library(fGarch)
y1 <- myData # store your series of returns in y
# parameter estimates
g = garchFit(~garch(1,1), y1, cond.dist= "norm", include.mean=FALSE, trace=FALSE)
omega = g@fit$matcoef[1,1]
alpha = g@fit$matcoef[2,1]
beta = g@fit$matcoef[3,1]
sigma2 = omega + alpha * y1[100]^2 + beta*[email protected][100] # compute sigma2 for t+1
print(sigma2)
Upvotes: 1