We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running the following:
from backtesting import Backtest, Strategy from backtesting.lib import crossover from backtesting.test import SMA import priceHistory class SmaCross(Strategy): def init(self): price = self.data.Close self.ma1 = self.I(SMA, price, 10) self.ma2 = self.I(SMA, price, 20) def next(self): if crossover(self.ma1, self.ma2): self.buy() elif crossover(self.ma2, self.ma1): self.sell() symbol = 'BA' ohlc = priceHistory.get_data(symbol, '2020-01-01', '2020-12-31') print(ohlc) bt = Backtest(ohlc, SmaCross, exclusive_orders=True) stats = bt.run() print(stats)
Produced the the following results:
Open High Low Close Volume datetime 2020-01-01 23:00:00-07:00 328.55 333.35 327.70 333.32 4548221 2020-01-02 23:00:00-07:00 330.63 334.89 330.30 332.76 3878374 2020-01-05 23:00:00-07:00 329.30 334.86 327.88 333.74 5357973 2020-01-06 23:00:00-07:00 334.26 344.19 330.71 337.28 9942277 2020-01-07 23:00:00-07:00 332.40 334.03 329.60 331.37 8246250 ... ... ... ... ... ... 2020-09-02 23:00:00-06:00 175.00 180.85 168.12 168.77 27799393 2020-09-03 23:00:00-06:00 171.31 172.83 164.00 171.05 18867266 2020-09-07 23:00:00-06:00 165.80 166.90 160.50 161.08 22622677 2020-09-08 23:00:00-06:00 161.61 163.06 157.00 160.78 21951401 2020-09-09 23:00:00-06:00 160.96 163.78 157.57 157.69 14532586 [175 rows x 5 columns]
Start 2020-01-01 23:00... End 2020-09-09 23:00... Duration 251 days 23:00:00 Exposure Time [%] 80.5714 Equity Final [$] 11014.4 Equity Peak [$] 13177.7 Return [%] 10.1445 **_Buy & Hold Return [%] 52.6911_** Max. Drawdown [%] -38.0218 Avg. Drawdown [%] -21.4588 Max. Drawdown Duration 174 days 00:00:00 Avg. Drawdown Duration 70 days 00:00:00 Trades 7 Win Rate [%] 42.8571 Best Trade [%] 41.7413 Worst Trade [%] -20.0121 Avg. Trade [%] 0.099488 Max. Trade Duration 49 days 00:00:00 Avg. Trade Duration 29 days 00:00:00 Profit Factor 1.27312 Expectancy [%] 15.1045 SQN 0.00995988 Sharpe Ratio 0.00470498 Sortino Ratio 0.0133826 Calmar Ratio 0.0026166 _strategy SmaCross _equity_curve ... _trades Size EntryBa... dtype: object
As you can see from the DataFrame of OHLC data for this year, BA is actually down on the year, not up 52.69%. How is Buy and Hold calculated?
The text was updated successfully, but these errors were encountered:
It's Buy & Hold or Sell & Hold, whichever is greater:
backtesting.py/backtesting/backtesting.py
Line 1378 in aa6830b
Duplicate of #36.
Sorry, something went wrong.
Ah... sorry I missed #36... thanks for the response...
This was changed as of 3045b64.
No branches or pull requests
Running the following:
Produced the the following results:
As you can see from the DataFrame of OHLC data for this year, BA is actually down on the year, not up 52.69%. How is Buy and Hold calculated?
The text was updated successfully, but these errors were encountered: