Created
December 28, 2015 19:36
-
-
Save ksindi/84d5e2c36e8ad9fde72c to your computer and use it in GitHub Desktop.
Show cumulative return and rank
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
df = pd.DataFrame([['2012', 'A', 1], ['2012', 'B', 4], ['2011', 'A', 5], ['2011', 'B', 4]], | |
columns=['year', 'manager', 'return_pct']) | |
df['total_return'] = (df | |
.groupby('manager')['return_pct'] | |
.transform(lambda group: (1 + group / 100.).cumprod().iat[-1])) - 1 | |
df['ranking'] = df.total_return.rank(ascending=False, method='dense') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment