13.08.2022 Views

advanced-algorithmic-trading

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

132

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

q = 2

The corelogram does indeed look like a realisation of DWN. Finally, we perform the Ljung-Box

test for 20 lags to confirm this:

> Box.test(resid(final.arma), lag=20, type="Ljung-Box")

Box-Ljung test

data: resid(final.arma)

X-squared = 13.1927, df = 20, p-value = 0.869

Notice that the p-value is greater than 0.05, which states that the residuals are independent

at the 95% level and thus an ARMA(3,2) model provides a good model fit.

Clearly this should be the case since we have simulated the data ourselves. However this is

precisely the procedure we will use when we come to fit ARMA(p,q) models to the S&P500 index

in the following section.

10.6.7 Financial Data

Now that we have outlined the procedure for choosing the optimal time series model for a

simulated series it is rather straightforward to apply it to financial data. For this example we

are going to once again choose the S&P500 US Equity Index.

Let us download the daily closing prices using quantmod and then create the log returns

stream:

> require(quantmod)

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

Saved successfully!

Ooh no, something went wrong!