Skip to content

fix: resolve NaN value return in stats#525

Draft
Soojal1807 wants to merge 1 commit into
ranaroussi:mainfrom
Soojal1807:fix/nan-value-return
Draft

fix: resolve NaN value return in stats#525
Soojal1807 wants to merge 1 commit into
ranaroussi:mainfrom
Soojal1807:fix/nan-value-return

Conversation

@Soojal1807

Copy link
Copy Markdown

Fix: NaN handling in "autocorr_penalty" in stats.py
Added validation to prevent autocorr_penalty from returning NaN in edge cases.

Issues fixed:

1.Missing length check — Function didn't verify at least 2 data points existed. Short or identical-value series make the correlation calculation undefined hence returning NaN.

2.Unvalidated NaN propagation — A NaN coefficient would silently flow into downstream metrics like sharpe_ratio etc. No check existed to catch this before it spread.

Fix: Added early returns — if data points < 2, or coefficient is NaN, return neutral default 1.0 instead.

@Soojal1807
Soojal1807 marked this pull request as draft June 17, 2026 18:18
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.

1 participant