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.

105

Figure 10.3: Realisation of AR(2) Model, with α 1 = 0.666, α 2 = −0.333 and Associated Correlogram.

> x <- w <- rnorm(100)

> for (t in 3:100) x[t] <- 0.666*x[t-1] - 0.333*x[t-2] + w[t]

> x.ar <- ar(x, method = "mle")

Warning message:

In arima0(x, order = c(i, 0L, 0L), include.mean = demean) :

possible convergence problem: optim gave code = 1

> x.ar$order

[1] 2

> x.ar$ar

[1] 0.6961005 -0.3946280

The correct order has been recovered and the parameter estimates ˆα 1 = 0.696 and ˆα 2 =

−0.395 are not too far off the true parameter values of α 1 = 0.666 and α 2 = −0.333.

Notice that we receive a convergence warning message. Notice also that R actually uses the

arima0 function to calculate the AR model. As we will learn in subsequent chapters, AR(p)

models are simply ARIMA(p, 0, 0) models, and thus an AR model is a special case of ARIMA

with no Moving Average (MA) or Integrated (I) component.

We will also be using the arima command to create confidence intervals around multiple

parameters, which is why we have neglected to do it here.

Now that we have created some simulated data it is time to apply the AR(p) models to

financial asset time series.

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

Saved successfully!

Ooh no, something went wrong!