Skip to content
Prev 13469 / 15274 Next

calculating beta-based variable dollar amounts to each leg of a spread backtest

On Wed, 2015-08-26 at 13:12 +0000, Tucker Sferro wrote:
The pairs trading demo was originally written by Garrett See, for the
record.

As is stated very clearly in the comments on the demo script, you would
never trade equity pairs this way.  

You should use a spreader.  Period.  

If you don't have a spreader, you shouldn't be trying to trade intra-day
stat arb pair trades.  

If you're trading long-cycle portfolio baskets, you likely don't need
quantstrat, and would be better off using Return.portfolio and a
timeseries of weights as a first approximation.
Construct multiple spreads. Trade these as instruments in your backtest.

for symbols

ABC
DEF
GHI

e.g.

stock('ABC')
stock('DEF')
stock('GHI')

you can construct spreads

ABC.DEF
DEF.GHI
ABC.GHI

e.g.

spread('ABC.DEF',members=c('ABC','DEF'),memberratio=c(ABC=1,DEF=-1))
spread('DEF.GHI',members=c('DEF','GHI'),memberratio=c(DEF=1,GHI=-2))
spread('ABC.GHI',members=c('ABC','GHI'),memberratio=c(ABC=1,GHI=-10))

(note different ratios for each pair)

presumably your ratios came from some beta calculation you've performed.

and you can now construct the spread time series using buildSpread or
your own function.  Your strategy works on the spreads.

If you want the ratio to change over time, that's actually a different
spread.

At one firm I was at, we would put the spread ratio into the primary_id
of the spread, e.g. ZF3.ZN2 ZF5.ZN3 though there are other approaches
that would be equally valid.

Regards,

Brian