13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

133

> getSymbols("^GSPC")

> sp = diff(log(Cl(GSPC)))

Let us perform the same fitting procedure as for the simulated ARMA(3,2) series above on

the log returns series of the S&P500 using the AIC:

> spfinal.aic <- Inf

> spfinal.order <- c(0,0,0)

> for (i in 0:4) for (j in 0:4) {

> spcurrent.aic <- AIC(arima(sp, order=c(i, 0, j)))

> if (spcurrent.aic < spfinal.aic) {

> spfinal.aic <- spcurrent.aic

> spfinal.order <- c(i, 0, j)

> spfinal.arma <- arima(sp, order=spfinal.order)

> }

> }

The best fitting model has order ARMA(3,3):

> spfinal.order

[1] 3 0 3

Let us plot the residuals of the fitted model to the S&P500 log daily returns stream, as given

in Figure 10.24:

> acf(resid(spfinal.arma), na.action=na.omit)

Figure 10.24: Correlogram of the residuals of the best fitting ARMA(p,q) Model, p = 3 and

q = 3, to the S&P500 daily log returns stream

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!