Mr.Ishikawa(my old friend) and I developed "PairTrading" package, and uploaded it on CRAN.This article shows you how you can use it.
The pair trading is a market neutral trading strategy and gives traders a chance to profit regardless of market conditions. The idea of this strategy is quite simple.
1 : Select two stocks(or any assets) moving similarly
2 : Short out-performing stock, buy under-performing one
3 : If "spread"(price difference between two stocks) converge, close your position.
So, Let's start to explain how to use this package.
(This example is in PDF manual of this package)
0: Install & load package
You can install and load "PairTrading" package via CRAN in the same way as other packages.
1: Load sample data
We prepared sample stock price data in our package. You can load it by using "data" command.
2: Estimate parameters
Next, We extract two stock prices(from 31 Mar, 2008) and estimate parameters.
At the moment, we have only normal linear regression method to estimate parameters, but we will develop more sophisticated method in the future.The estimation result contains the following contents.
And, you can check the stationarity of that by using "IsStationary" function.
This function return the result of two types unit root test.
3: Estimate parameters for back-test
To run back-test, you have to estimate parameters historically by using "EstimateParametersHistorically"function. This function do something like "rolling regression" to estimate parameters. This point is different from "EstimateParameter" function.
4: Create trading signal
Next, you create trading singal using estimated spread. "Simple" function give a very simple trading strategy(If The spread is more(less) than specified value, you will buy(sell))
In this case, The trading signal is drawn as below.
Last, you can check the performance of pair trading by using "Return" function.
In this case, our strategy seems to work correctly :-)
6: Conclusion and remarks
Pair trading is well-known trading strategy, and I introduced "PairTrading" package in this article.
We would like to modify this package to be more useful and fit in real-market.
If you have any suggestion, please let me know.
And we created a presentation slide to explain the basic concept of pair trading.It may be useful for you to understand the basic concept of pair trading if you are interested in it.