[R-SIG-Finance] quantmod EMA and SMA
Hi all, I compare the serie from the function EMA() and the one from addEMA() getSymbols(^FCHI) M7=EMA(Cl(FCHI),7) candleChart(FCHI,theme=white,subset=2015,TA=NULL) addEMA(7) addTA(M7,on=-1) I don't understant why I don't obtain the same serie with the two functions... Reagrds, Olivier. ___ R-SIG-Finance@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.
[R-SIG-Finance] help with quantstrat
Hi all, I try to program a simple strategy to learn with the package quantstrat. Hereafter is the program, and the message I obtained when I applyed the strategy Error in eval(expr, envir, enclos) : objet 'rsif' introuvable Erreur dans `colnames-`(`*tmp*`, value = seq(ncol(tmp_val))) : attempt to set 'colnames' on an object with less than two dimensions Could you explain me what is wrong ? Regards, Olivier. #- currency(EUR) Sys.setenv(TZ=UTC) getSymbols('ACA.PA') stock(ACA.PA,currency=EUR) # system settings initDate - '2007-01-01' endDate - '2014-12-30' initEq - 1 #strategy mystrat - gg rm.strat(mystrat) # remove strategy initPortf(mystrat,'ACA.PA', initDate=initDate) initAcct(mystrat,portfolios=mystrat, initDate=initDate, initEq=initEq) # initialize orders container initOrders(portfolio=mystrat,initDate=initDate) # instantiate a new strategy object strategy(mystrat,store=TRUE) myRSI=function(x,nrsi=8,m=20){ r=SMA(RSI(x,n=nrsi),n=m) return(r) } myCCI=function(x,ncci=8,m=20){ r=SMA(CCI(x,n=ncci),n=m) return(r) } #indicatros mystrat=add.indicator(strategy =mystrat, name = myRSI,arguments = list(x =quote(Cl(mktdata)),nrsi=8 ,m=20), label=rsif) mystrat=add.indicator(strategy =mystrat, name = myRSI,arguments = list(x =quote(Cl(mktdata)),nrsi=14,m=20), label=rsis) mystrat=add.indicator(strategy =mystrat, name = myCCI,arguments = list(x =quote(Cl(mktdata)),ncci=8 ,m=20), label=ccif) mystrat=add.indicator(strategy =mystrat, name = myCCI,arguments = list(x =quote(Cl(mktdata)),ncci=14,m=20), label=ccis) #signals mystrat=add.signal(mystrat,name=sigFormula,arguments = list(columns=c(rsif,rsis,ccif,ccis),formula=rsifrsis ccifccis,cross=TRUE), label=up) mystrat=add.signal(mystrat,name=sigFormula,arguments = list(columns=c(rsif,rsis,ccif,ccis),formula=rsifrsis ccifccis,cross=TRUE), label=dn) mystrat=add.signal(mystrat,name=sigFormula,arguments = list(columns=c(rsif,rsis,ccif,ccis),formula=!(rsifrsis ccifccis ) | !(rsifrsis ccifccis),cross=TRUE), label=ex) # position rules mystrat=add.rule(mystrat, name=ruleSignal,arguments = list(sigcol=up, sigval=TRUE, orderqty=1,ordertype='market', orderside='long'), type='enter') mystrat=add.rule(mystrat, name=ruleSignal,arguments = list(sigcol=ex, sigval=TRUE, orderqty='all',ordertype='market', orderside='long'), type='exit') mystrat=add.rule(mystrat, name=ruleSignal,arguments = list(sigcol=dn, sigval=TRUE, orderqty=1,ordertype='market', orderside='short'), type='enter') mystrat=add.rule(mystrat, name=ruleSignal,arguments = list(sigcol=ex, sigval=TRUE, orderqty='all',ordertype='market', orderside='short'), type='exit') ## apply strategy applyStrategy(strategy=mystrat , portfolios=mystrat) This is the message I obtain : Error in eval(expr, envir, enclos) : objet 'rsif' introuvable Erreur dans `colnames-`(`*tmp*`, value = seq(ncol(tmp_val))) : attempt to set 'colnames' on an object with less than two dimensions ___ R-SIG-Finance@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.
[R-SIG-Finance] Help with quantstrat
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 (i3i4)(i5i6) I enter for a short position if (i3i4)(i5i6) 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=(i3i4)(i5i6) dn=(i3i4)(i5i6) 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@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.
[R-SIG-Finance] Help with quantstrat
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 (i3i4)(i5i6) I enter for a short position if (i3i4)(i5i6) 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=(i3i4)(i5i6) dn=(i3i4)(i5i6) 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@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.
Re: [R-SIG-Finance] Help with quantstrat.. correction
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 (i3i4)(i5i6) I enter for a short position if (i3i4)(i5i6) 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=(i3i4)(i5i6) dn=(i3i4)(i5i6) 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@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 ___ R-SIG-Finance@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.
[R-SIG-Finance] problem with quantstrat
Hi all, This my problem with the package quantstrat. When I execute demo(maCross) or demo(macd) I obtain the following message for the step applyStrategy(): out-applyStrategy(strat.st , portfolios=portfolio.st,parameters=list(nFast=fastMA, nSlow=slowMA, nSig=signalMA,maType=maType),verbose=TRUE) Erreur dans NextMethod(.Generic) : dims [produit 1] ne correspond pas à la longueur de l'objet [9] De plus : Message d'avis : In which((if (!is.null(status)) ordersubset[, Order.Status] == : Méthodes incompatibles (Ops.POSIXt, Ops.Date) pour Sorry my version is in french: this is an (approximate) translation: Error in NextMethod(.Generic) : dims [product 1] do not correspond to the size of object [9] Moreover: warning message : In which((if (!is.null(status)) ordersubset[, Order.Status] == : incompatible methods (Ops.POSIXt, Ops.Date) pour I tried the package with the R version R-2.15.3 and the version R-3.0.1 on Ubuntu system. I think that therie is no pb on windows system. Thanks for your help, O. ___ R-SIG-Finance@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.
[R-SIG-Finance] quantmod bug ?
Hi all, I recently posted a problem concerning shaded regions with quantmod package. More precisely, I used the function addTA with a boolean vector: for example addTA(vecB,col=green,border=NA,on=-1) where vecB is the boolean vector. In some cases, the shading result was not conform with the boolean vector. I checked the R source program, and more precisely the function chartTA() in TA.R file. So in the function chartTA, it seems that there is a mistake with the vector x.pos. the vector is given by x.pos - 1 + spacing * (1:length(x.range)) and it seems that this vector should be x.pos - 1:(spacing*x.range[2]) So I hope this indication would be relevant for people who work on the improvements of this package. Best regards. O. ___ R-SIG-Finance@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.
[R-SIG-Finance] about quantmod and shaded region
Hi all, I am a new user of quantmod package (version 0.3-8) and I have some problems. I would like to add shaded regions to a chart. 1. I tried the following commands (from slide presentation of Jeff Ryan) getSymbols('^FCHI',source=yahoo) CAC=FCHI candleChart(CAC,theme=white,subset='2012-05::2012-08',TA=NULL) addTA(RSI(Cl(CAC))50,col=green,border=NA,on=-1) addTA(RSI(Cl(CAC))40 RSI(Cl(CAC))50 ,col=red,border=NA,on=-1) addTA(RSI(Cl(CAC)) ,on=NA) So the first region RSI(Cl(CAC))50 is correctly shaded, but the second region RSI(Cl(CAC))40 RSI(Cl(CAC))50 isn't. So I supposed a bug with bollean vectors with addTA() ? 2. On the web, I found a mail from Jeff Ryan and he proposed to use the function xts() times - timeBasedSeq(20071001/2007) # create a Date sequence from 2007-10-01 to 2007-12-31 addTA(xts(rep(TRUE,length(times)), times), on=-1, col=#33, border=NA) Nevertheless, this command gives me an error concerning the function rect(). 3. I also tried to use the function newAT() without success.. :-( Best Regards, O. ___ R-SIG-Finance@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.