[R-SIG-Finance] (no subject)

Joshua Ulrich josh.m.ulrich at gmail.com
Wed Nov 2 22:10:10 CET 2011


I didn't dig too much, but it looks like some of the
PerformanceAnalytics functions may not play well with the yearmon
index class.  Keeping the index as a Date works for me.  You can do
that by setting the indexAt argument of to.monthly:

EEM.m=to.monthly(Ad(EEM),indexAt="lastof")
BA.m=to.monthly(BAMLEMCBPITRIV,indexAt="lastof")

HTH,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



On Wed, Nov 2, 2011 at 3:30 PM, Martin Bauer <Bauermartin at gmx.at> wrote:
> Hi,
>
> I was trying to code this
>
> http://econompicdata.blogspot.com/2011/10/emerging-market-rotation-strategy.html
>
> in R
>
> # EM Rotation model
> library(quantmod)
> library(PerformanceAnalytics)
> indexes<-c("SPY","EEM","VWO")
> sym=getSymbols(indexes,from="2000-09-15",to=Sys.Date())
> sym1=getSymbols("BAMLEMCBPITRIV",from="2000-09-15",to=Sys.Date(),src="FRED")
> EEM.m=to.monthly(Ad(EEM))
> EEM.m=EEM.m[,4]
> BA.m=to.monthly(BAMLEMCBPITRIV)
> BA.m=(BA.m[,4])
> b=na.omit(merge(EEM.m,BA.m))
> EEM.m=b[,1]
> BA.m=b[,2]
> seem=SMA(EEM.m,10)
> long=ifelse(EEM.m>seem,1,0)
> short=ifelse(EEM.m<seem,1,0)
> colnames(long)=c("LONG EEM")
> colnames(short)=c("LONG Bonds")
> retup=lag(long,k=1)*ROC(EEM.m,type="discrete",n=1)
> retdown=lag(short,k=1)*ROC(BA.m,type="discrete",n=1)
> ret=retup+retdown
> ret=ret[1:NROW(ret)-1,]
> re=merge(ret,ROC(EEM.m,type="discrete",n=1))
> colnames(re)=c("TAA","EEM")
> charts.PerformanceSummary(re,ylog=TRUE,main="TAA")
> Return.annualized(ret)
> SharpeRatio.annualized(ret)
> tail(ret)
> table.Drawdowns(ret, top=10)
> table.DownsideRisk(ret)
>
> but at this point >
> Return.annualized(ret)
> I get the following error
>
> Error in FUN(newX[, i], ...) :
>  'R' needs to be timeBased or xtsible, or scale must be specified.
>
> I have no clue why .....
>
> What is missing ?
>
> Thanks in advance
>
> Martin
> --
>
> _______________________________________________
> 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.
>



More information about the R-SIG-Finance mailing list