Repository navigation
Conversation
pain_index() is the mean absolute drawdown over all observations (Becker / Zephyr; Bacon, Practical Portfolio Performance Measurement and Attribution). pain_ratio() divides the annualized return minus the annualized risk-free return by it, using the same risk-free convention as martin_ratio(). Both have rolling variants and 1d/2d/rolling numba kernels, following the ulcer index / Martin ratio layout.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the pain index and pain ratio to
ReturnsAccessor, next to the ulcer index and Martin ratio from #881:pain_index()/rolling_pain_index(): the mean absolute drawdown over all observations (Thomas Becker, Zephyr Associates; Bacon, Practical Portfolio Performance Measurement and Attribution). The ulcer index squares the drawdowns before averaging; the pain index averages them as they are, so every period under water counts linearly. Returned as a positive fraction.pain_ratio()/rolling_pain_ratio(): annualized return minus annualized risk-free return, divided by the pain index.Layout and conventions follow #881 one to one:
returns/nb.py, built ondrawdown_1d_nbandannualized_return_1d_nb.returns/dispatch.pythat rejectengine="rust"through_no_rust(...), since vectorbt-rust has no counterpart.risk_freeis a constant per-period rate compounded overann_factor, the same asmartin_ratio.minpcounts non-NaN returns; empty input gives NaN; a series with no drawdown gives a pain index of 0 and a pain ratio of NaN.Not added to
stats(), so existing stats output is unchanged. Happy to add them there if you want.Tests:
[0.10, -0.20, 0.25, -0.10, 0.0]give equity 1.10, 0.88, 1.10, 0.99, 0.99 and drawdowns 0, -20%, 0, -10%, -10%, so the pain index is 0.4 / 5 = 0.08. With 5 periods per year the annualized return is -1%, so the pain ratio is -0.125; with a 0.2% per-period risk-free rate it is(-0.01 - (1.002**5 - 1)) / 0.08.freq/year_freqpairs and three risk-free rates, interior NaN windows, numba vs auto engine equality, accessor defaults, and the explicit-rust rejection intests/test_engine.py.tests/test_returns.pyandtests/test_engine.pypass locally (99 passed, the rest are vectorbt-rust skips); black is clean on the changed files.If this is welcome, a follow-up would add Kappa-n on lower partial moments (Kaplan and Knowles 2004), which generalizes the Sortino ratio (n=2) and Omega (n=1, as Omega - 1).