Carpemer
Carpemer

Reputation: 287

How to calculate compound interest by day in pandas

If I have a DataFrame like:

date       value
2015-01-01 1.1
2015-01-01 1.2
2015-01-01 1.1
2015-01-01 1.1

I want to get:

date       value compound value
2015-01-01  1.1  1.1
2015-01-01  1.2  1.1*1.2
2015-01-01  1.1  1.1*1.2*1.1
2015-01-01  1.1  1.1*1.2*1.1*1.1

Is there any simple solution for this in pandas?

Upvotes: 2

Views: 4202

Answers (1)

EdChum
EdChum

Reputation: 394101

You want cumprod:

In [7]:
df['compound'] = df['value'].cumprod()
df

Out[7]:
         date  value  compound
0  2015-01-01    1.1    1.1000
1  2015-01-01    1.2    1.3200
2  2015-01-01    1.1    1.4520
3  2015-01-01    1.1    1.5972

Upvotes: 4

Related Questions