Saturday, February 13, 2010

Classical Pairs Trading

Classical Pairs Trading Scripts Running in FreeMAT


The pairs trade or pair trading, also known as market neutral, was developed in the late 1980s by quantitative analysts and pioneered by Gerald Bamberger while at Morgan Stanley. With the help of others at Morgan Stanley at the time, including Nunzio Tartaglia, Bamberger found that certain securities, often competitors in the same sector, were correlated in their day-to-day price movements. When the correlation broke down, i.e. one stock traded up while the other traded down, they would sell the outperforming stock and buy the underperforming one, betting that the "spread" between the two would eventually converge.” –from wikipedia

Marcelo Perlin shared his MATLAB scripts for Classical Pairs Trading Using MatLab in the MathWorks website. I downloaded his scripts, and tried to run at FreeMAT. It basically worked without any change. (Two minor errors due to the difference between MATLAB and FreeMAT, but you can run scripts to end to get the final results and a plot.)

Unzip the files you downloaded into a directory. Open the FreeMAT, then change directory to the directory where the file “Example_Script_Pairs_Trading.m” is. Then the FreeMAT command line, type

à Example_Script_Pairs_Trading

Just like that, after a few minutes, you will get plot like this:

This is resulted from his sample stock data. He seems also used S&P data to get the results like this:

Since his scripts used his sample data, I will have to modify/add some scripts to make it robust to be used for a set of stocks I choose to test out the pair trading strategy.
I will keep you posted.

No comments:

Post a Comment