-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
RuntimeWarning: Degrees of freedom <= 0 for slice #1251
Comments
backtesting 0.6.3 |
Seems to warn on line: backtesting.py/backtesting/_stats.py Line 157 in b1a869c
@jensnesten Since git blames you for that line, would you happen to know what the issue is and how to mitigate? 😅 |
This happens because there are cases where we dont have enough data points to calculate covariance. We can fix the warning by setting proper checks before calculating: if len(equity_log_returns) > 1 and len(market_log_returns) > 1:
cov_matrix = np.cov(equity_log_returns, market_log_returns)
beta = cov_matrix[0, 1] / cov_matrix[1, 1]
s.loc['Alpha [%]'] = s.loc['Return [%]'] - risk_free_rate * 100 - beta * (s.loc['Buy & Hold Return [%]'] - risk_free_rate * 100) # noqa: E501
s.loc['Beta'] = beta
else:
s.loc['Alpha [%]'] = np.nan
s.loc['Beta'] = np.nan |
Fixes #1251: covariance calculation for insufficient data points
Expected behavior
Error happens at _stats.py:161:
Errors info
Code sample
Actual behavior
eroor
Additional info, steps to reproduce, full crash traceback, screenshots
No response
Software versions
bokeh.__version__
:The text was updated successfully, but these errors were encountered: