Closed samueltg92 closed 1 year ago
When I run the backtester I expect to have all the metrics calculated, included the Sharpe R, Sortino R and Calmar R, instead, it is not calculating anyone of those metrics. Is it probably a bug?
1. 2. 3.
class MyStrat(Strategy): riskpct = 0.01 rsi_window = 2 os = 5 ob = 95 sl_buy = 0.985 tp_buy = 1.03 sl_sell = 1.015 tp_sell = 0.97 def init(self): super().init() self.vwap = self.I(lambda: ta.vwap(self.data.High.s, self.data.Low.s, self.data.Close.s, self.data.Volume.s, anchor='W')) self.rsi = self.I(lambda: ta.rsi(self.data.Close.s, length=self.rsi_window)) self._trade_max_cash = self.equity * self.riskpct def next(self): super().next() price = self.data.Close[-1] # if self.position: # self.position.close() if self.rsi <= self.os and price > self.vwap: self.position.close() self.buy(sl = self.sl_buy*price, tp = self.tp_buy*price, size = int(self._trade_max_cash//price)) elif self.rsi >= self.ob and price < self.vwap: self.position.close() self.sell(sl = self.sl_sell*price, tp = self.tp_sell*price, size = int(self._trade_max_cash//price)) bt = Backtest(df1, MyStrat, cash=1000000, margin=1/1, commission = 0.0006, trade_on_close=True, hedging=True, exclusive_orders=True) stat = bt.run() print(stat)
Duplicate of https://github.com/kernc/backtesting.py/issues/715.
Expected Behavior
When I run the backtester I expect to have all the metrics calculated, included the Sharpe R, Sortino R and Calmar R, instead, it is not calculating anyone of those metrics. Is it probably a bug?
Actual Behavior
Steps to Reproduce
1. 2. 3.
Additional info