# Volatility updating rule using r

I'm trying to program a volatility updating rule using iteration. I start with the well know Heston-Nandi model where the returns dynamics are : with is iid standard normal randome variable, where is time-varying squared volatility, , and .

I want to do is to write the code associate to the volatility updating rule, explain in this algorithm :

1. Define equals the given unconditional variance which is constant,
2. Iteration for : to obtain the returns based proxy for spot variances . Which yields an updating function that exclusively involves observation : My program (r-code) is the following:

library(fGarch)

T=3000
# For the example I simulate a GARCH
#process parameters
eta = 0.2 #eta = 0 is equivalent to Geometric Brownian Motion
mu = 100 #the mean of the process

#GARCH volatility model
specs = garchSpec(model = list(omega = 0.000001, alpha = 0.5, beta = 0.4))
sigma = garchSim(spec = specs, n = T)

P_0 = mu #starting price, known
P = rep(P_0,T)

for(i in 2:T){
P[i] = P[i-1] + eta * (mu - P[i-1]) + sigma[i] * P[i-1]
}

# Set the parameters :
para<-c(0.1,0.2,0.3,0.4,0.5,0.7) # (beta_0,beta_1, beta_2, beta_3, r, gamma)
# Iteration to obtain the volatility associate to the model :

vol = c()
vol=sd(P)
for (i in 2:length(P)){
para_vol <- para[1:6]
vol[i]=para_vol+ (para_vol*vol[i-1])+ (para_vol/vol[i-1])*(P[i-1]-para_vol-(para_vol+para_vol)*vol[i-1])
}
vol


This is an example where I simulate a GARCH (as data set), the I am trying to extract the volatility associate to the Heston-Nandi model.

I known, I´m using a lot of bad things for r, but I could not figure out a better solution. So my question is it correct?

Any correction and suggestion to improve this process! please feel free to share your extant code in R.

Huge thanks!

• As this seems to be a mostly conceptual question, my advice is that you'll get more traction for it on stats.stackexchange.com. – Robert Dodier Jan 16 '15 at 1:09

model = list(omega = 0.000001, alpha = 0.5, beta = 0.4)
HNGOption(TypeFlag, model, S, X, Time.inDays, r.daily)