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.

118

> require(quantmod)

> getSymbols("AMZN")

> amznrt = diff(log(Cl(AMZN)))

Now that we have the log returns stream we can use the arima command to fit MA(1), MA(2)

and MA(3) models and then estimate the parameters of each. For MA(1) we have:

> amznrt.ma <- arima(amznrt, order=c(0, 0, 1))

> amznrt.ma

Call:

arima(x = amznrt, order = c(0, 0, 1))

Coefficients:

ma1 intercept

-0.030 0.0012

s.e. 0.023 0.0006

sigma^2 estimated as 0.0007044: log likelihood = 4796.01, aic = -9586.02

We can plot the residuals of the daily log returns and the fitted model given in Figure 10.13.

> acf(amznrt.ma$res[-1])

Figure 10.13: Residuals of MA(1) Model Fitted to AMZN Daily Log Prices

Notice that we have a few significant peaks at lags k = 2, k = 11, k = 16 and k = 18,

indicating that the MA(1) model is unlikely to be a good fit for the behaviour of the AMZN log

returns, since this does not look like a realisation of white noise.

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

Saved successfully!

Ooh no, something went wrong!