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.

151

> ft <- as.numeric(ftrt)

> ft <- ft[!is.na(ft)]

The next task is to fit a suitable ARIMA(p,d,q) model. We saw how to do that in the previous

chapter so the procedure will not be repeated here. Instead the code will simply be provided:

> ftfinal.aic <- Inf

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

> for (p in 1:4) for (d in 0:1) for (q in 1:4) {

> ftcurrent.aic <- AIC(arima(ft, order=c(p, d, q)))

> if (ftcurrent.aic < ftfinal.aic) {

> ftfinal.aic <- ftcurrent.aic

> ftfinal.order <- c(p, d, q)

> ftfinal.arima <- arima(ft, order=ftfinal.order)

> }

> }

Since we have already differenced the FTSE returns once we should expect our integrated

component d to equal zero, which it does:

> ftfinal.order

[1] 4 0 4

Thus we receive an ARIMA(4,0,4) model. This contains four autoregressive parameters and

four moving average parameters.

We are now in a position to decide whether the residuals of this model fit possess evidence

of conditional heteroskedastic behaviour. To test this we need to plot the correlogram of the

residuals, as given in Figure 11.10.

> acf(resid(ftfinal.arima))

This looks like a realisation of a discrete white noise process indicating that we have achieved

a good fit with the ARIMA(4,0,4) model.

To test for conditional heteroskedastic behaviour we need to square the residuals and plot

the corresponding correlogram, as given in Figure 11.11.

> acf(resid(ftfinal.arima)^2)

We can see clear evidence of serial correlation in the squared residuals, leading us to the

conclusion that conditional heteroskedastic behaviour is present in the diff log return series of

the FTSE100.

We are now in a position to fit a GARCH model using the tseries library.

The first command actually fits an appropriate GARCH model, with the trace=F parameter

telling R to suppress excessive output.

The second command removes the first element of the residuals, since it is NA:

> ft.garch <- garch(ft, trace=F)

> ft.res <- ft.garch$res[-1]

To test for a good fit we can plot the correlogram of the GARCH residuals and the square

GARCH residuals as given in Figure 11.12.

> acf(ft.res)

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

Saved successfully!

Ooh no, something went wrong!