trentstauff / FXBot

A fully automated Forex trading bot utilizing the OANDA API.
194 stars 67 forks source link

Backtest Not run with SMA #32

Open kernelhacks opened 2 years ago

kernelhacks commented 2 years ago

Traceback (most recent call last): File "main.py", line 214, in trader = SMABacktest(instrument, start, end, smas, smal, granularity, trading_cost) File "/root/FXBot/backtesting/SMABacktest.py", line 25, in init super().init( File "/root/FXBot/backtesting/Backtester.py", line 27, in init self._data = self.acquire_data() File "/root/FXBot/backtesting/Backtester.py", line 41, in acquire_data df = oanda.get_history( File "/root/FXBot/env/lib/python3.8/site-packages/tpqoa-0.0.55-py3.8.egg/tpqoa/tpqoa.py", line 241, in get_history AttributeError: 'Index' object has no attribute 'tz_localize'

kernelhacks commented 2 years ago

This command fixe the issues inside the main FXbot directory pip install --upgrade git+https://github.com/yhilpisch/tpqoa.git

trentstauff commented 2 years ago

Perfect!

kernelhacks commented 2 years ago

Sorry to reopen this issue but the command do not work, I don't know way after I run that command was working but when I stop the bot and run again I get the same error again. AttributeError: 'Index' object has no attribute 'tz_localize'

EUR_USD Live Trading (1) or Backtesting (2)? 2 Please choose the strategy you would like to backtest:

sma, bollinger_bands, contrarian, momentum, ml_classification, ml_regression, sma Enter the start date for the backtest (string, in form of "YYYY-MM-DD"):

2022-04-19 Enter the end date for the backtest (string, in form of "YYYY-MM-DD"):

2022-04-19 Enter the trading cost to consider: (float, IE 0.0, 0.00007):

1.0811 Please enter the granularity for your session (See list in README, IE "S30", "M1", "H1"):

M1 Enter SMAS value (integer, IE 9):

7 Enter SMAL value (integer, IE 20):

14 Downloading historical data... Traceback (most recent call last): File "main.py", line 214, in trader = SMABacktest(instrument, start, end, smas, smal, granularity, trading_cost) File "/home/darwin/FXBot/backtesting/SMABacktest.py", line 25, in init super().init( File "/home/darwin/FXBot/backtesting/Backtester.py", line 27, in init self._data = self.acquire_data() File "/home/darwin/FXBot/backtesting/Backtester.py", line 41, in acquire_data df = oanda.get_history( File "/home/darwin/FXBot/env/lib/python3.8/site-packages/tpqoa/tpqoa.py", line 241, in get_history data.index = data.index.tz_localize(None) AttributeError: 'Index' object has no attribute 'tz_localize'

kernelhacks commented 2 years ago

Ok, it looks that the issue only appears when the start and the end date are the same. but when I was playing with the SMAS and the SMAL and the granularity, some combinations produce errors.

kernelhacks commented 2 years ago

this backtest setup work EUR_USD Live Trading (1) or Backtesting (2)? 2 Please choose the strategy you would like to backtest:

sma, bollinger_bands, contrarian, momentum, ml_classification, ml_regression, sma Enter the start date for the backtest (string, in form of "YYYY-MM-DD"):

2022-04-19 Enter the end date for the backtest (string, in form of "YYYY-MM-DD"):

2022-04-20 Enter the trading cost to consider: (float, IE 0.0, 0.00007):

1.0811 Please enter the granularity for your session (See list in README, IE "S30", "M1", "H1"):

M1 Enter SMAS value (integer, IE 9):

7 Enter SMAL value (integer, IE 20):

18 Downloading historical data... Download complete. Testing strategy with smas = 7, smal = 18 ... Return: -100.0%, Out Performance: -100.11% Optimizing strategy... 25%... 50%... 75%... Strategy optimized on interval 2022-04-19 - 2022-04-20 Max Return: -100.0%, Best SMAS: 34 (M1), Best SMAL: 247 (M1) Plotting Results.

kernelhacks commented 2 years ago

I think I found the issue only works with granularity M1 or S30

trentstauff commented 2 years ago

Interesting. Ill take a look