fix: avoid decimal overflow in portfolio statistics alpha - #9861
Merged
Martin-Molinero merged 1 commit intoOct 2, 2026
Merged
Martin-Molinero merged 1 commit into
Martin-Molinero merged 1 commit into
Conversation
- compute alpha in double and cast it back with SafeDecimalCast, like the information and treynor ratios - add test with a capped annual performance and a negative benchmark term
Martin-Molinero
approved these changes
Oct 2, 2026
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.
Description
PortfolioStatisticscomputed alpha in decimal. When the annual performance is capped atdecimal.MaxValueand the benchmark term is negative, the subtraction overflows:Alpha is now computed in double and cast back with
SafeDecimalCast, the same way the information and Treynor ratios already are.Related PR(s)
#8256 fixed the same overflow for the information and Treynor ratios.
Related Issue
N/A
Motivation and Context
Seen in a live deployment. A cash deposit more than doubled the account value, so one daily return was about +156% and the annual performance hit the decimal cap. From the next day on, every statistics update failed with the error above, 45 times in 2.5 days, until the algorithm stopped.
Requires Documentation Change
No
How Has This Been Tested?
PortfolioStatisticsTests.PortfolioStatisticsDoesNotFailWhenAlphaExceedsDecimalRange: fails on master with the stack above, passes with the fix.QuantConnect.Tests.Common.Statistics: 379 of 379 passed.BasicTemplate*regression algorithms: 40 of 40 passed, so their expected alpha did not change.Types of changes
Checklist:
bug-<issue#>-<description>orfeature-<issue#>-<description>