I'm trying to transform a (well, many) column of return data to a column of closing prices. In Clojure, I'd use reductions
, which is like reduce
, but returns a sequence of all the intermediate values.
e.g.
$ c
0.12
-.13
0.23
0.17
0.29
-0.11
# something like this
$ c.reductions(init=1, lambda accumulator, ret: accumulator * (1 + ret))
1.12
0.97
1.20
1.40
1.81
1.61
NB: The actual closing price doesn't matter, hence using 1 as the initial value. I just need a "mock" closing price.
My data's actual structure is a DataFrame of named columns of TimeSeries. I guess I'm looking for a function similar applymap
, but I'd rather not do something hacky with that function and reference the DF from within it (which I suppose is one solution to this problem?)
Additionally, what would I do if I wanted to keep the returns
data, but have the closing "price" with it? Should I return a tuple instead, and have the TimeSeries be of the type (returns, closing_price)
?