-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Allow for different periodicity (annualization factors) in the annual_*() methods #164
Conversation
…al_volatility calcs
Thanks @cgdeboer! I'll try to take a look soon. |
ann_factor = ANNUALIZATION_FACTORS[period] | ||
except KeyError: | ||
raise ValueError( | ||
"periodicty must cannot be: '{}'." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
@cgdeboer Thanks for this PR! It looks really nice -- very clean implementation, and very readable code. I have one concern in that when migrating from one periodicity (e.g. Daily) to supporting various ones with various annualization factors, etc., I feel like its possible that things can break pretty easily downstream (edge cases, etc). I'd feel more comfortable merging this PR after some unit tests. We already have a bunch for our existing metrics, perhaps you can add a couple of test conditions to the existing unit tests? Thanks again! |
@twiecki and @justinlent , thanks for the feedback. I added a couple tests (just for the two primary annualization methods) and also ensured that other functions that were calling the annual_return and annual_volatility methods are have an optional kwarg for period. A couple notes. I toyed with the idea of using Let me know if I need to add anything else to the code or tests. |
Looks like one of the tests is failing now....I will investigate later this weekend. Hang tight. |
Hi guys, not sure why the build is failing at this point; I'm unable to replicate this far on running tests locally in a new virtualenv. Can you point me in the right direction on this? The error traces back to a numpy import which seems irrelevant to what I was working on. |
That error is very odd, hard to believe it has anything to do with what you did. I restarted the build just in case. |
Merged with ee928a3. Many thanks! |
Summary
I have a use case for passing in a Series of monthly returns to a variety of the methods available in timeseries.py. A lot of the methods will work and calculate properly regardless of the periodicity of the data. Things like cum_returns, normalize, max_drawdown all are frequency agnostic. I've added a 'period' kwarg to the annual_return and annual_volatility function to allow for the specification of other frequencies (the default remains daily).
Changes
annual_return
andannual_volatility
now raises a ValueError if you pass in a 'period' that is not accepted (followed the precedent set in theaggregate_returns()
method.Notes
There is certainly more one could do to support frequencies app-wide, as some raw return data is not available at the daily periodicity level, however, I didn't want to short-circuit or prematurely jumpstart any plans you all had to begin that effort.