@@ -154,7 +154,7 @@ def backtest(
154
154
costs = cmn_costs + borrow_costs + spread_costs
155
155
156
156
# Calc the number of valid trading periods for each asset
157
- # to calculate correct number of trades
157
+ # to get correct number of trades
158
158
strat_valid_periods = weights .apply (
159
159
lambda col : col .loc [col .first_valid_index () :].count ()
160
160
)
@@ -166,7 +166,6 @@ def backtest(
166
166
strat_rets = weights * (prices .pct_change () - costs ).shift (- shift_periods )
167
167
strat_rets = strat_rets .iloc [:- shift_periods ] if shift_periods > 0 else strat_rets
168
168
strat_cum = (1 + strat_rets ).cumprod () - 1
169
- strat_profit_cost_ratio = strat_cum .iloc [- 1 ] / costs .sum ()
170
169
strat_perf = pd .concat (
171
170
[
172
171
strat_rets .apply (
@@ -176,15 +175,13 @@ def backtest(
176
175
strat_rets .apply (_cagr , periods = freq_year ),
177
176
strat_rets .apply (_max_drawdown ),
178
177
_trade_count (weights ) / strat_total_days ,
179
- strat_profit_cost_ratio ,
180
178
],
181
179
keys = [
182
180
"annual_sharpe" ,
183
181
"annual_volatility" ,
184
182
"cagr" ,
185
183
"max_drawdown," ,
186
184
"trades_per_day" ,
187
- "profit_cost_ratio" ,
188
185
],
189
186
axis = 1 ,
190
187
)
@@ -193,7 +190,6 @@ def backtest(
193
190
port_rets = strat_rets .sum (axis = 1 )
194
191
port_cum = strat_cum .sum (axis = 1 )
195
192
port_costs = costs .sum ().sum ()
196
- port_profit_cost_ratio = port_cum .iloc [- 1 ] / port_costs if port_costs > 0 else None
197
193
port_perf = pd .DataFrame (
198
194
{
199
195
"annual_sharpe" : _ann_sharpe (
@@ -202,7 +198,6 @@ def backtest(
202
198
"annual_volatility" : _ann_vol (port_rets , periods = freq_year ),
203
199
"cagr" : _cagr (port_rets , periods = freq_year ),
204
200
"max_drawdown" : _max_drawdown (port_rets ),
205
- "profit_cost_ratio" : port_profit_cost_ratio ,
206
201
},
207
202
index = ["portfolio" ],
208
203
)
0 commit comments