Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: fix annualization of alpha #60

Merged
merged 9 commits into from
Aug 25, 2019
Merged

BUG: fix annualization of alpha #60

merged 9 commits into from
Aug 25, 2019

Conversation

vikram-narayan
Copy link
Contributor

For #59, annualize alpha correctly

@twiecki
Copy link
Contributor

twiecki commented Oct 16, 2017

This looks right. But would hope that some tests catch this we need to change.

@vikram-narayan
Copy link
Contributor Author

@twiecki just updated test_stats.py to fix the failures - mind taking a quick look at those as well? Mostly just updating numbers

@@ -1111,7 +1114,7 @@ def test_roll_up_capture(self, returns, factor_returns, window, expected):
(empty_returns, simple_benchmark, (np.nan, np.nan)),
(one_return, one_return, (np.nan, np.nan)),
(mixed_returns[1:], negative_returns[1:],
(-8.306666666666668, -0.71296296296296313)),
(-0.9997853834885004, -0.71296296296296313)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This already shows why the previous result was wrong.

@twiecki
Copy link
Contributor

twiecki commented Oct 17, 2017

LGTM. We should probably alert others to this bugfix.

@@ -818,7 +818,7 @@ def alpha_aligned(returns, factor_returns, risk_free=0.0, period=DAILY,
adj_factor_returns = _adjust_returns(factor_returns, risk_free)
alpha_series = adj_returns - (_beta * adj_factor_returns)

return nanmean(alpha_series) * ann_factor
return (nanmean(alpha_series) + 1) ** ann_factor - 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you think about breaking this formula out into a helper function? Feels like that would make it clearer what's happening here, and less error prone.

(At the least a comment to the effect of #59 would be good)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added an annualize helper in utils, and used that here

@@ -443,3 +443,10 @@ def default_returns_func(symbol, start=None, end=None):
rets = get_symbol_returns_from_yahoo(symbol, start=start, end=end)

return rets[symbol]


def annualize(stat, ann_factor=252):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be called something like annualize_compounding? From what I understand the compounding is why this formula applies?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, I agree

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 renamed to annualize_compounding

Copy link

@yankees714 yankees714 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but just want to make sure, have we verified the changes to these test values?

@chrismyles4
Copy link

chrismyles4 commented Oct 26, 2017

We are good to release

@yankees714
Copy link

LGTM

@twiecki
Copy link
Contributor

twiecki commented Nov 16, 2017

Can we merge this?

@vikram-narayan
Copy link
Contributor Author

We chose to wait for when we have the bandwidth to write a blog post announcing the change. Will follow up on that today

empyrical/stats.py Outdated Show resolved Hide resolved
@twiecki
Copy link
Contributor

twiecki commented Aug 23, 2019

I think there is still a bug here, as the failing tests show. Seems like it always returns 0 or nan?

@twiecki twiecki merged commit 4cb0508 into master Aug 25, 2019
@twiecki twiecki deleted the fix_alpha_aligned branch August 25, 2019 11:57
@twiecki
Copy link
Contributor

twiecki commented Aug 25, 2019

Thanks @gmanoim-quantopian !

gusgordon added a commit to quantopian/zipline that referenced this pull request Aug 28, 2019
Fixes incorrect alpha calculation: quantopian/empyrical#60
richafrank pushed a commit to quantopian/zipline that referenced this pull request Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants