Skip to content

Backtest Not run with SMA #32

New issue

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

Open
kernelhacks opened this issue Apr 20, 2022 · 7 comments
Open

Backtest Not run with SMA #32

kernelhacks opened this issue Apr 20, 2022 · 7 comments

Comments

@kernelhacks
Copy link

kernelhacks commented Apr 20, 2022

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
Copy link
Author

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

@trentstauff
Copy link
Owner

Perfect!

@kernelhacks kernelhacks reopened this Apr 20, 2022
@kernelhacks
Copy link
Author

kernelhacks commented Apr 20, 2022

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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

@trentstauff
Copy link
Owner

Interesting. Ill take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants