[R-SIG-Finance] How to test pairs trading strategy

veepsirtt veepsirtt at gmail.com
Wed Jun 8 11:19:37 CEST 2011


Dear Daniel Cegiełka,

  I iinstalled and run the  demo.

https://r-forge.r-project.org/scm/viewvc.php/pkg/quantstrat/demo/pair_trade.R?view=markup&revision=605&root=blotter

Now I want to change the pair trading strategy as follows.

## given 2 stocks, calculate the ratio of their notional values.  If the
ratio falls below it's
# 2 stdev band, then when it crosses back above it, buy stock 1 and sell
stock 2.
 
# If the ratio rises above it's 1 stdev band, then  flatten any open
positions.

For this condition how to modify the following lines,

# Create signals -*** BBands for 2 Stdev

pairStrat <- add.signal(strategy = pairStrat, name = "sigCrossover",
arguments= list(columns=c("Ratio","up"), relationship="lt"),
label="cross.up")
pairStrat <- add.signal(strategy = pairStrat, name = "sigCrossover",
arguments= list(columns=c("Ratio","dn"), relationship="gt"),
label="cross.dn")

# Create entry and exit rules for longs  and for shorts..****here BBands for
1 stdev

pairStrat <- add.rule(strategy = pairStrat, name='ruleSignal', arguments =
list(sigcol="cross.up", sigval=TRUE, orderqty=-1e6, ordertype='market',
orderside=NULL, osFUN='osSpreadMaxPos'), type='enter')

 How to exit ?

Thanking you
veepsirtt



--
View this message in context: http://r.789695.n4.nabble.com/How-to-test-pairs-trading-strategy-tp3558776p3582036.html
Sent from the Rmetrics mailing list archive at Nabble.com.



More information about the R-SIG-Finance mailing list