We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b1a869c commit 84e685aCopy full SHA for 84e685a
backtesting/_stats.py
@@ -154,8 +154,11 @@ def _round_timedelta(value, _period=_data_period(index)):
154
s.loc['Calmar Ratio'] = annualized_return / (-max_dd or np.nan)
155
equity_log_returns = np.log(equity[1:] / equity[:-1])
156
market_log_returns = np.log(c[1:] / c[:-1])
157
- cov_matrix = np.cov(equity_log_returns, market_log_returns)
158
- beta = cov_matrix[0, 1] / cov_matrix[1, 1]
+ beta = np.nan
+ if len(equity_log_returns) > 1 and len(market_log_returns) > 1:
159
+ # len == 0 on dummy call `stats_keys = compute_stats(...)` pre optimization
160
+ cov_matrix = np.cov(equity_log_returns, market_log_returns)
161
+ beta = cov_matrix[0, 1] / cov_matrix[1, 1]
162
# Jensen CAPM Alpha: can be strongly positive when beta is negative and B&H Return is large
163
s.loc['Alpha [%]'] = s.loc['Return [%]'] - risk_free_rate * 100 - beta * (s.loc['Buy & Hold Return [%]'] - risk_free_rate * 100) # noqa: E501
164
s.loc['Beta'] = beta
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments