[R-SIG-Finance] Adding Stop Loss to pair_trade example

Derek Wong treydog999 at gmail.com
Mon Sep 8 21:26:13 CEST 2014


I am very new to quantstrat and R. I have been playing with the pair_trade
example and have been wondering how to implement stop losses that are non
indicator based. I would like to implement a stop loss based on the
movement of the spread. I have looked at the macd example for risk stop
losses however when i apply that same syntax to the pair_trade it does not
affect the system at all. Can anyone help?

The Changes i made to the orignal example code are, labeling the entries as
Long or Short. Then adding 2 additional rules as chain and having them use
a threshold multiplier or +/- .05

*My code for the Rules Section of the example*

pairStrat <- add.rule(strategy=pairStrat, name='ruleSignal',
                      arguments=list(sigcol="cross.dn", sigval=TRUE,
                                     orderqty=1e6, ordertype='market',
                                     orderside=NULL,
osFUN='osSpreadMaxPos'),
                      type='enter',
                      label = 'Long')
pairStrat <- add.rule(strategy=pairStrat, name='ruleSignal',
                      arguments=list(sigcol="cross.up", sigval=TRUE,
                                     orderqty=-1e6, ordertype='market',
                                     orderside=NULL,
osFUN='osSpreadMaxPos'),
                      type='enter',
                      label = 'Short')
pairStrat <- add.rule(strategy=pairStrat, name='ruleSignal',
                      arguments=list(sigcol="cross.mid.fb", sigval=TRUE,
                                     orderqty='all', ordertype='market',
                                     orderside=NULL),
                      type='exit')
pairStrat <- add.rule(strategy=pairStrat, name='ruleSignal',
                      arguments=list(sigcol="cross.mid.fa", sigval=TRUE,
                                     orderqty='all', ordertype='market',
                                     orderside=NULL),
                      type='exit')

pairStrat <- add.rule(strategy=pairStrat, name'ruleSignal',
                      arguments=list(sigcol="cross.dn", sigval=TRUE,
                                     orderqty='all', ordertype='stoplimit',
                                     orderside=NULL,
                                     threshold = -.05, tmult=TRUE,
                                     orderset='exit2'),
                      type = 'chain',
                      parent = 'Long',
                      label = 'LongStop')

pairStrat <- add.rule(strategy=pairStrat, name'ruleSignal',
                      arguments=list(sigcol="cross.dn", sigval=TRUE,
                                     orderqty='all', ordertype='stoplimit',
                                     orderside=NULL,
                                     threshold = .05, tmult=TRUE,
                                     orderset='exit2'),
                      type = 'chain',
                      parent = 'Short',
                      label = 'ShortStop')



Thanks

Derek

	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list