[R-SIG-Finance] issue with xts affectin Return.calculate in PerformanceAnalytics
susan22 at mail.com
susan22 at mail.com
Tue Jun 19 20:43:30 CEST 2012
I came across the issue below trying to calculate simple returns of an xts object using Return.calculate() in PerformanceAnalytics. This returns a series of all zeros. The root of the problem, however, seems to be with xts for which division seems to be a challenge. What am I missing? Coercion to numeric is not really a reasonable solution.
> p <- to.monthly(as.xts(s.ts), OHLC = FALSE)
> head(aap)
s1 s2
Dec 1999 1000.00 1000.00
Jan 2000 1021.27 959.85
Feb 2000 1017.30 962.06
Mar 2000 1022.99 1008.44
Apr 2000 1015.95 980.95
May 2000 1044.30 963.79
> r <- Return.calculate(aap, method = "simple")
> head(r)
s1 s2
Dec 1999 0 0
Jan 2000 0 0
Feb 2000 0 0
Mar 2000 0 0
Apr 2000 0 0
May 2000 0 0
> lr <- Return.calculate(aap, method = "compound")
> head(lr)
s1 s2
Dec 1999 NA NA
Jan 2000 0.02104695084364 -0.04097825672856
Feb 2000 -0.00389489202608 0.00229979652957
Mar 2000 0.00557765293308 0.04708304254280
Apr 2000 -0.00690557640376 -0.02763837145911
May 2000 0.02752266915648 -0.01764806131103
> p[2]/p[1]-1
Data:
numeric(0)
Index:
NULL
> as.numeric(p[2])/as.numeric(p[1])-1
[1] 0.02127 -0.04015
More information about the R-SIG-Finance
mailing list