I read Chen et al. "Forecasting volatility with support vector machine-based GARCH model" (2010) where they implented a recurrent SVM procedure to estimate volatility by a GARCH based model. The model is of the form

$y_t = f(y_{t-1}) + u_t \qquad \qquad \ \ \ (1)$

$u^2_t = g(u^2_{t-1}, w_{t-1}) + w_t \qquad (2)$

At first they got estimates for $u_t$ by estimating $(1)$ by a SVM. Then, the following recurrent SVM algorithm was proposed to estimate $(2)$.

Recurrent SVM Algorithm:

Step 1: Set $i = 1$ and start with all residuals at zero: $w_t^{(1)} = 0 $.

Step 2: Run an SVM procedure to get the decision function $f^{(i)}$ to the points $\{x_t, y_t\} = \{u_{t - 1}^2, u_t^2 \}$ with all inputs $x_t = \{u_{t - 1}^2, w_{t-1} \}$

Step 3: Compute the new residuals $w_t^{i+1} = u_t^2 - f^{(i)}$.

Step 4: Terminate the computaion process if the stopping criterion is satisfied; otherwise, set $i = i + 1$ and go back to Step 2.

The proposed stopping critrerion is based a Ljung-Box-Test for the residuals $w_t$. Only if the $p$-values of the test in five consecutive periods are higher than 0.1 the process is stopped.

As real world example the log-returns of the New York Stock Exchange (NYSE) composite stock index for the period from January 8, 2004 to December 31, 2007 was used. The last 60 observations where used as test sample. Hence, the estimation was done with the first 940 observations. In their study, the process converged after 121 interations. (Question:) However, my implementation in R does not converge. I think I have a misunderstanding of the concept. Because I think I implemented it exactly as stated. My R code is the following

rm(list = ls())


#Get NYSE data and convert to log returns
id     <- "^NYA"
data   <- getSymbols(id, source = "yahoo", auto.assign = FALSE, 
                     from = "2004-01-08", to = "2007-12-31")
series <- data[,6]  #Get adjusted closing prices
series <- na.omit(diff(log(series)))*100  #Compute log returns

#Lagged data for analysis
x      <- na.omit(cbind(series, lag(series)))

#Set parameters as in paper
svm_eps   <- 0.05
svm_cost  <- 0.005
sigma     <- 0.02
svm_gamma <- 1/(2*sigma^2)

#SVM to get u_t
svm     <- svm(x = x[,-1], y = x[,1], scale = FALSE,
               type = "eps-regression", kernel = "radial",
               gamma = svm_gamma, cost = svm_cost, epsilon = svm_eps)

u    <- svm$residuals  #Extract u_t
n    <- 60  #Size of test set
u_tr <- u[1:(nrow(u) - n)]  #Subset to training set
u_tr <- na.omit(cbind(u_tr, lag(u_tr)))^2  #Final training set

#Recurrent SVM for vola estimation
i       <- 1
p_count <- 0

while(p_count < 5){

  print(i)  #Print number of loops

  #Estimate SVM for u^2
  svmr     <- svm(x = u_tr[,-1], y = u_tr[,1], scale = FALSE,
                  type = "eps-regression", kernel = "radial",
                  gamma = svm_gamma, cost = svm_cost, epsilon = svm_eps)

  #Test autocorrelation of residuals to lag 1
  test    <- Box.test(svmr$residuals, lag = 1, type = "Ljung-Box")
  p_val   <- test$p.value
  p_count <- ifelse(p_val > 0.1, p_count + 1, 0)

  #Extract residuals for next estimation step
  w        <- svmr$residuals
  w        <- c(0, w[-length(w)])  #lag 1

  u_tr <- cbind(u_tr[,1:2], w)

  i <- i + 1
  • $\begingroup$ I tried to highlight your question as it was a bit lost in the long text. So essentially, would you like us to go through the code and look for a mistake? Or how could we help you? $\endgroup$ – Richard Hardy May 18 '16 at 18:22
  • $\begingroup$ I want to reproduce the results in the paper. So, going through the code and checking for mistakes would be helpful. Moreover, maybe I didn't understand the idea of recurrent SVM at all. Hence, I am not sure whether my implementation makes any sense in the context of recurrent SVM. I am unsure about my understanding because I read it several times but I don't see where I am wrong with my implementation. $\endgroup$ – random_guy May 18 '16 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.