[R-SIG-Finance] Pairs trade?
Brian G. Peterson
brian at braverock.com
Tue Mar 6 14:51:02 CET 2007
On Tuesday 06 March 2007 07:20, John McHenry wrote:
> I'm looking for examples of how to code pairs trades in R. I'm self
> taught, so no example is too simple!
>
> Does any financial package cover pairs trading?
I'm not aware of any statistical software package that covers pairs
trading per se. Often, you would use statistical software to analyze
historical correlations on related sector instruments to identify target
pairs, and then use an execution environment to generate the signals when
highly correlated instruments diverge.
There are execution environments like TradeStation or Interactive Brokers
for retail trading (IB also has a professional product), which both have
simple programming environments and some mean reversion methods built in.
To take advantage of pairs trades in actual practice, you also need a data
management mechanism, price data, etc. So, you may wish to start with
one of the retail environments I've mentioned above, to avoid the extra
overhead.
If you still want to code it in R, you'll need to start thinking about
these questions:
- Where will I get market data?
- How will I calculate correlations?
- How will I generate my target list of highly paired instruments?
- What will be my signal for divergence?
- How wide a spread before I put the trade on?
- When do I take the trade off?
- Will I ever move or take off only one side of the spread?
- What execution environment am I going to use?
R is capable of doing all these things. Packages and functions exist for
some individual techniques or portions of functionality to implement the
software needed for my list of questions above. Others you would have to
write yourself or pay someone to write for you.
This list will be most useful to you if you attempt to implement something
specific, and then ask the list when you have a question which might be
phrased something like:
"I've attempted to generate a timeseries of signals describing when two
highly correlated instruments diverge by more than one standard
deviation. My code mostly works, but I can't formulate the long and
short signals into a timeseries that I can use in my backtesting
environment. Could someone help me fix function pair_signals()?"
I hope this helps.
Regards,
- Brian
--
773-459-4973 mobile
http://braverock.com/brian/resume-quant.pdf
More information about the R-SIG-Finance
mailing list