[R-SIG-Finance] Help with quantstrat

Olivier MARTIN Olivier.Martin at avignon.inra.fr
Wed Jan 21 11:21:22 CET 2015


Hi all,

I am beginner with quantstrat. I would like to try a simple strategy but 
I have some
difficulties to program it. The strategy is based on two signals : the 
CCI and the RSI.
First, I compute RSI and CCI for period n=21. Let's denote them rsi21 
and cci21.
Secondly, I compute two moving average for rsi21 and cci21 with two
periodes : 8 and 14. I obtain four signals. Let's denote i3 and i4 for
rsi21, and i5 and i6 for cci21.
Finally, I  enter for a long position if (i3>i4)&(i5>i6)
I enter for a short position if (i3<i4)&(i5<i6)
I exit for a long or a short position when it is flat.

###
rsi21=RSI(Cl(mktdata),n=21)
cci21=RSI(Cl(mktdata),n=21)
i3 is equal to  SMA(rsi21,8)
i4 is equal to  SMA(rsi21,14)
i5 is equal to  SMA(cci21,8)
i6 is equal to  SMA(cci21,14)

up=(i3>i4)&(i5>i6)
dn=(i3<i4)&(i5<i6)
flat=!up & !dn
###


So I try to program these strategy but I don't know how to take
into account the different boolean conditions with the add.rule() function

#indicators
add.indicator(strategy =mystrategy, name = "SMA",arguments = list(x = 
quote(RSI(Cl(mktdata),n=8)), n=20), label="i3")
add.indicator(strategy =mystrategy, name = "SMA",arguments = list(x = 
quote(RSI(Cl(mktdata),n=14)), n=20), label="i4")
add.indicator(strategy =mystrategy, name = "SMA",arguments = list(x = 
quote(CCI(Cl(mktdata),n=8)), n=20), label="i5")
add.indicator(strategy =mystrategy, name = "SMA",arguments = list(x = 
quote(CCI(Cl(mktdata),n=14)), n=20), label="i6")

#signals
add.signal(mystrategy,name="sigCrossover",arguments = 
list(columns=c("i3","i4"),relationship="gt"),  label="i3.gt.i4")
add.signal(mystrategy,name="sigCrossover",  arguments = 
list(columns=c("i5","i6"),relationship="gt"),  label="i5.gt.i6")
add.signal(mystrategy,name="sigCrossover",  arguments = 
list(columns=c("i3","i4"),relationship="lt"),  label="i3.lt.i4")
add.signal(mystrategy,name="sigCrossover",  arguments = 
list(columns=c("i5","i6"),relationship="lt"),  label="i5.lt.i6")

#rules
  ???????




Could someone help me ?
Best regards,
Olivier.



More information about the R-SIG-Finance mailing list