ranaroussi / quantstats

Portfolio analytics for quants, written in Python
Apache License 2.0
4.76k stars 835 forks source link

Fix EOY compound return bug #200

Closed TradingDominion closed 2 years ago

TradingDominion commented 2 years ago

The end of year (EOY) compounded returns calculated by stats.monthly_returns() were not being properly calculated.

You can confirm the bug with the following code on the existing repo:

import quantstats as qs
qs.extend_pandas()
stock = qs.utils.download_returns('META')
rets = stock.monthly_returns().iloc[1][0:12]
eoy = stock.monthly_returns().iloc[1][12]
print(rets)
print(f'Original compound end of year return = {eoy}')  # shows 0.82
compret = rets.add(1).prod() - 1
print(f'Correct compound return should be = {compret}')  # shows 1.05

This PR fixes the bug.