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.

103

with parameter estimates for the α i , which we can then use to form confidence intervals.

For completeness we recreate the x series:

> set.seed(1)

> x <- w <- rnorm(100)

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

Now we use the ar command to fit an autoregressive model to our simulated AR(1) process,

using maximum likelihood estimation (MLE) as the fitting procedure.

We will firstly extract the best obtained order:

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

> x.ar$order

[1] 1

The ar command has successfully determined that our underlying time series model is an

AR(1) process.

We can then obtain the α i parameter(s) estimates:

> x.ar$ar

[1] 0.5231187

The MLE procedure has produced an estimate, ˆα 1 = 0.523, which is slightly lower than the

true value of α 1 = 0.6.

Finally, we can use the standard error, with the asymptotic variance, to construct 95%

confidence intervals around the underlying parameter. To achieve this we simply create a vector

c(-1.96, 1.96) and then multiply it by the standard error:

x.ar$ar + c(-1.96, 1.96)*sqrt(x.ar$asy.var)

[1] 0.3556050 0.6906324

The true parameter does fall within the 95% confidence interval. This is to be expected since

the realisation has been generated from the model specifically.

How about if we change the α 1 = −0.6? The plot is given in Figure 10.2.

> set.seed(1)

> x <- w <- rnorm(100)

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

> layout(1:2)

> plot(x, type="l")

> acf(x)

As before we can fit an AR(p) model using ar:

> set.seed(1)

> x <- w <- rnorm(100)

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

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

> x.ar$order

[1] 1

> x.ar$ar

[1] -0.5973473

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

Saved successfully!

Ooh no, something went wrong!