[R-SIG-Finance] Calculating returns on negative time series
Johnson, Cedrick W.
cedrick at cedrickjohnson.com
Wed Oct 27 17:54:30 CEST 2010
Howdy-
I *know* I've seen it discussed before on the list, and I've tried to
search through all my emails and the archives for it so forgive me for
reposting (perhaps I'm using the improper search terms).
To calculate the simple returns for a time series above 0, no brainer:
I'm using the Return.calculate function to calculate these (method="simple")
Things get a little tricky when I throw in time series that are negative
(such as spreads):
x =
c(-117,-122,-129,-129,-134,-136,-136,-140,-143,-143,-143.2,-146.7,-145.8,-143,-141.2,-137.7,-135.5,-133.6)
NaN's are produced when trying to get a "return" time series. I seem to
recall doing this
xa = abs(x)
Return.calculate(xa)
2 0.041847110
3 0.055791360
4 0.000000000
5 0.038027396
6 0.014815086
7 0.000000000
8 0.028987537
9 0.021202208
10 0.000000000
11 0.001397624
12 0.024147431
13 -0.006153866
14 -0.019391189
15 -0.012667305
16 -0.025099919
17 -0.016105765
18 -0.014121379
I am thinking that I could take the abs value, once I get the return
series just invert it by multiplying by -1. I'm concerned that something
could be thrown off by a series that's changing from lets say 1,0,-1
(puking on the 0).
Can someone point me to anything that addresses this? Not sure the
"solution" i outlined above is the proper way to handle this.
-c
More information about the R-SIG-Finance
mailing list