[R-SIG-Finance] Help with quantstrat.. correction

Olivier MARTIN Olivier.Martin at avignon.inra.fr
Sat Jan 10 19:48:09 CET 2015


Sorry, I made a mistake in my preious mail...

flat=!up & !dn


Le 10/01/2015 19:24, Olivier MARTIN a écrit :
> 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.
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R 
> questions should go.


-- 
-------------------------------------------------------------
MARTIN Olivier
INRA-Centre de recherche PACA
228 route de l Aerodrome
Unité Biostatistique & Processus Spatiaux
CS 40509
Domaine St Paul, Site Agroparc
84914 Avignon Cedex 9, France
Tel : 04 32 72 21 57



More information about the R-SIG-Finance mailing list