Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Help with cumulative returns

Would someone help me with a rolling calculation for cumulative returns? In Excel this is simple but I'm having trouble figuring out how to do it with pandas. Hopefully the attached notebook will make it clear what I'm attempting to do.

TIA.

2 responses

There's probably a slicker way to do this but here's what worked for me:

for index in range(len(portfolio_index)-1):
portfolio_index[index+1] = portfolio_index[index] + (portfolio_index[index] * portfolio_daily_pct_change[index+1])

I don't know if this works for an entire portfolio, but if you want to calculate cumulative returns for a single security/index, this is a "slicker" way to do it:

from quantopian.research import symbols, returns

daily_returns = returns(  
    assets=symbols('YourSymbol'),  
    start='YourStartDate',  
    end='YourStartDate',  
)

cumulative_returns = (1 + daily_returns).cumprod()