File tree 1 file changed +5
-6
lines changed 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -154,15 +154,14 @@ def _round_timedelta(value, _period=_data_period(index)):
154
154
s .loc ['Calmar Ratio' ] = annualized_return / (- max_dd or np .nan )
155
155
equity_log_returns = np .log (equity [1 :] / equity [:- 1 ])
156
156
market_log_returns = np .log (c [1 :] / c [:- 1 ])
157
+ beta = np .nan
157
158
if len (equity_log_returns ) > 1 and len (market_log_returns ) > 1 :
159
+ # len == 0 on dummy call `stats_keys = compute_stats(...)` pre optimization
158
160
cov_matrix = np .cov (equity_log_returns , market_log_returns )
159
161
beta = cov_matrix [0 , 1 ] / cov_matrix [1 , 1 ]
160
- # Jensen CAPM Alpha: can be strongly positive when beta is negative and B&H Return is large
161
- s .loc ['Alpha [%]' ] = s .loc ['Return [%]' ] - risk_free_rate * 100 - beta * (s .loc ['Buy & Hold Return [%]' ] - risk_free_rate * 100 ) # noqa: E501
162
- s .loc ['Beta' ] = beta
163
- else :
164
- s .loc ['Alpha [%]' ] = np .nan
165
- s .loc ['Beta' ] = np .nan
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
166
165
s .loc ['Max. Drawdown [%]' ] = max_dd * 100
167
166
s .loc ['Avg. Drawdown [%]' ] = - dd_peaks .mean () * 100
168
167
s .loc ['Max. Drawdown Duration' ] = _round_timedelta (dd_dur .max ())
You can’t perform that action at this time.
0 commit comments