[R-SIG-Finance] Applying transformations to timeSeries objects

nacho ignacio.rodrigo at gmx.com
Fri Jun 20 14:14:56 CEST 2014


Hi guys,

First of all, apologies for the simplicity of the question, I am a complete
R and Rmetrics newbie so I am just trying to learn. I have searched forums
and the internet in general for the answer but I have found none that I
could understand or matched my query.

So, using the Rmetrics package, I created a timeSeries object with a set of
closing prices, e.g.

> data

GMT
                Close
1974-12-31  191
1975-01-02  184
1975-01-03  173
1975-01-06  172
1975-01-07  171
1975-01-08  176
1975-01-09  179
1975-01-10  177
1975-01-13  181
1975-01-14  177

My first question is how to apply a transformation of one row relative to
the previous row to the 'data' timeSeries object and store it in a new
timeSeries object. I am aware that you can simply run:

> returns(data)

...and it will generate a returns timeSeries object. However, what if I want
to create a new timeSeries object from 'data' that applies a more custom
transformation that references other rows? e.g. one that subtracts the
previous observation from the current one

GMT
                Close
1975-01-02  -7
1975-01-03  -11
1975-01-06  -1
1975-01-07  -1
1975-01-08  5
1975-01-09  3
1975-01-10  -2
1975-01-13  4
1975-01-14  -4

I have tried doing it writing a for-loop but something tells me that it is
possible to do it in a much simpler way through timeSeries' fapply() or
applySeries() functions. Would anyone know how to do it?

Thanks a lot for taking the time to read this and for your help in advance,
much appreciated!



--
View this message in context: http://r.789695.n4.nabble.com/Applying-transformations-to-timeSeries-objects-tp4692438.html
Sent from the Rmetrics mailing list archive at Nabble.com.



More information about the R-SIG-Finance mailing list