File tree Expand file tree Collapse file tree 4 files changed +13
-0
lines changed
Filter options
Expand file tree Collapse file tree 4 files changed +13
-0
lines changed
Original file line number Diff line number Diff line change @@ -68,6 +68,8 @@ CAGR [%] 16.80
68
68
Sharpe Ratio 0.66
69
69
Sortino Ratio 1.30
70
70
Calmar Ratio 0.77
71
+ Alpha [%] 450.62
72
+ Beta 0.02
71
73
Max. Drawdown [%] -33.08
72
74
Avg. Drawdown [%] -5.58
73
75
Max. Drawdown Duration 688 days 00:00:00
Original file line number Diff line number Diff line change @@ -152,6 +152,13 @@ def _round_timedelta(value, _period=_data_period(index)):
152
152
s .loc ['Sortino Ratio' ] = (annualized_return - risk_free_rate ) / (np .sqrt (np .mean (day_returns .clip (- np .inf , 0 )** 2 )) * np .sqrt (annual_trading_days )) # noqa: E501
153
153
max_dd = - np .nan_to_num (dd .max ())
154
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 ]
159
+ # Jensen CAPM Alpha: can be strongly positive when beta is negative and B&H Return is large
160
+ s .loc ['Alpha [%]' ] = s .loc ['Return [%]' ] - risk_free_rate * 100 - beta * (s .loc ['Buy & Hold Return [%]' ] - risk_free_rate * 100 ) # noqa: E501
161
+ s .loc ['Beta' ] = beta
155
162
s .loc ['Max. Drawdown [%]' ] = max_dd * 100
156
163
s .loc ['Avg. Drawdown [%]' ] = - dd_peaks .mean () * 100
157
164
s .loc ['Max. Drawdown Duration' ] = _round_timedelta (dd_dur .max ())
Original file line number Diff line number Diff line change @@ -1262,6 +1262,8 @@ def run(self, **kwargs) -> pd.Series:
1262
1262
Sharpe Ratio 0.58038
1263
1263
Sortino Ratio 1.08479
1264
1264
Calmar Ratio 0.44144
1265
+ Alpha [%] 394.37391
1266
+ Beta 0.03803
1265
1267
Max. Drawdown [%] -47.98013
1266
1268
Avg. Drawdown [%] -5.92585
1267
1269
Max. Drawdown Duration 584 days 00:00:00
Original file line number Diff line number Diff line change @@ -317,6 +317,8 @@ def test_compute_stats(self):
317
317
'Start' : pd .Timestamp ('2004-08-19 00:00:00' ),
318
318
'Win Rate [%]' : 46.96969696969697 ,
319
319
'Worst Trade [%]' : - 18.39887353835481 ,
320
+ 'Alpha [%]' : 394.37391142027462 ,
321
+ 'Beta' : 0.03803390709192 ,
320
322
})
321
323
322
324
def almost_equal (a , b ):
You can’t perform that action at this time.
0 commit comments