Time for action – trading correlated pairs
For this tutorial, we will use two sample data sets, containing the bare minimum of end-of-day price data. The first company is BHP Billiton (BHP), which is active in the mining of petroleum, metals, and diamonds. The second is Vale (VALE), which is also a metals and mining company. So there is some overlap, albeit not one hundred percent. For trading correlated pairs, follow these steps:
First, load the data, specifically the close price of the two securities, from the CSV files in the example code directory of this chapter and calculate the returns. If you don't remember how to do it, there are plenty of examples in the previous chapter.
Covariance tells us how two variables vary together; it is nothing more than unnormalized correlation. Compute the covariance matrix from the returns with the
cov
function (it's not strictly necessary to do this, but it will allow us to demonstrate a few matrix operations):covariance = np.cov(bhp_returns, vale_returns...