Category Archives: Matlab

Exploring pair trading opportunities with yahoo, python and LibreOffice

I have been reading two books about quantitative and algorithmic trading by Ernie Chan:

  • Quantitative Trading: How to Build Your Own…
  • Algorithmic Trading: Winning Strategies and…

See the books page for my reading recommendations.

One of the main take aways of this reading is the insight that it is possible to create stationary pairs by shorting and longing two, or more equities that usually move in tandem. The idea is to arbitrage the oscillating differences in moves between the equities in the pairs. Mr Chan explains all the mathematics behind mean reversion and provides Matlab code do the necessary calculus.
My approach to exploring this idea and the possibilities is far simpler and less elegant. Still, I think some might find it useful to see my take on it. I wrote a python script that pulls daily data from Yahoo and then calculates the ratios between two equities. With the resulting ratios data I continued my investigations in LibreOffice Calc. I like to use Calc to model my ideas and as they become more complicated or as I want to test more data sets I move the model over to code using Python and the pandas library.

Continue reading