pyfolio icon indicating copy to clipboard operation
pyfolio copied to clipboard

Question about 'Cumulative returns' calculation in tear sheets

Open JoeOD opened this issue 7 years ago • 2 comments

Problem Description

Please provide a minimal, self-contained, and reproducible example:

import empyrical as emp
import numpy as np

b = np.array([1,2,3])

print(emp.cum_returns_final(b))
print(np.nanprod(b+1, axis=0)-1)
print(np.prod(b+1)-1)

Please provide the full traceback:

no traceback

Please provide any additional information below:

I have a question about the “cumulative returns” stat this is reported in the tear sheets.

I noticed that the stat doesn’t appear to be the cumulative sum of the returns. Looking at the code, in the timeseries.py script, on line 653, I saw that the tear sheet calls the cum_returns_final function from the empyrical package when it calculates the cumulative returns. The empyrical documentation says it computes the “total returns from simple returns.”

That function seems to add 1 to each element in the array of returns, calculate the product of the returns, and then subtract 1 at the end. It does this, rather than just calculating the cumulative sum. I tested my hunch out a couple different ways, using the code above.

Am I correct about how the cumulative returns stat is calculated? If so, could you explain why this is done, instead of just calculating the cumulative sum? Or provide me with a term to google, so I can look it up? Is it something to do with compounding? Thanks, -Joe

Versions

  • Pyfolio version: 0.9.0
  • Python version: 3.7.1
  • Pandas version: 0.23.4
  • Matplotlib version: 3.0.2

JoeOD avatar Sep 18 '19 10:09 JoeOD

Pyfolio returns are daily simple returns, so combining periods is through prod()

If it were daily log returns, then combining would be through sum()

Here is the relevant line from the empyrical package: https://github.com/quantopian/empyrical/blob/b561c5fd2d299590a45c870868e84c6060a50c1d/empyrical/stats.py#L262

lionelyoung avatar Mar 09 '20 13:03 lionelyoung

https://www.kellogg.northwestern.edu/rc/workshops/cumulative_returns.htm

twiecki avatar Mar 09 '20 13:03 twiecki