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.

95

Once quantmod is installed we can use it to obtain the historical price of MSFT stock:

> require(’quantmod’)

> getSymbols(’MSFT’, src=’yahoo’)

> MSFT

..

..

2015-07-15 45.68 45.89 45.43 45.76 26482000 45.76000

2015-07-16 46.01 46.69 45.97 46.66 25894400 46.66000

2015-07-17 46.55 46.78 46.26 46.62 29262900 46.62000

This will create an object called MSFT (case sensitive) into the R namespace, which contains

the pricing and volume history of MSFT. We are interested in the corporate-action adjusted

closing price. We can use the following commands to (respectively) obtain the Open, High,

Low, Close, Volume and Adjusted Close prices for the Microsoft stock: Op(MSFT), Hi(MSFT),

Lo(MSFT), Cl(MSFT), Vo(MSFT), Ad(MSFT).

Our process will be to take the difference of the Adjusted Close values, omit any missing

values, and then run them through the autocorrelation function. When we plot the correlogram

we are looking for evidence of discrete white noise, that is, a residuals series that is serially

uncorrelated. To carry this out in R, we run the following command:

> acf(diff(Ad(MSFT)), na.action = na.omit)

The latter part (na.action = na.omit) tells the acf function to ignore missing values by

omitting them. The output of the acf function is given in Figure 9.5.

Figure 9.5: Correlogram of the Difference Series from MSFT Adjusted Close.

We notice that the majority of the lag peaks do not differ from zero at the 5% level. However

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

Saved successfully!

Ooh no, something went wrong!