Skip to content

Conversation

@jensnesten
Copy link
Contributor

@jensnesten jensnesten commented Mar 23, 2025

Fixes #1251

The code was generating runtime warnings when calculating covariance with insufficient data points:

RuntimeWarning: Degrees of freedom <= 0 for slice
cov_matrix = np.cov(equity_log_returns, market_log_returns)

Added length checks before covariance calculation to handle cases where:

  • There are no trades executed
  • The data series is too short
  • There are NaN values in the data

The fix returns np.nan for both Alpha and Beta metrics when there isn't enough data for a valid covariance calculation.

@kernc
Copy link
Owner

kernc commented Mar 26, 2025

Applied with slight modification. Thanks for figuring it out!

@kernc kernc merged commit 84e685a into kernc:master Mar 26, 2025
7 checks passed
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.

RuntimeWarning: Degrees of freedom <= 0 for slice

2 participants