-
Notifications
You must be signed in to change notification settings - Fork 199
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
Backtest strategy using Oanda historical data ? #45
Comments
This looks like a bug I've introduced in v0.7.0. I'll work on a fix for it now. In the meantime, a workaround would be to download the data first, then run the backtest by providing the local data filepath. To download the data: from autotrader import AutoData
data_config = {
'data_source': 'oanda',
'API': 'api-fxpractice.oanda.com',
'ACCESS_TOKEN': 'xxx-yyy',
'PORT': 443,
'ACCOUNT_ID': 'xxx-xxx-xxxxxxxx-xxx'
}
ad = AutoData(data_config)
data = ad.fetch(instrument='EUR_USD', granularity='1h', count=100) To run a backtest with local data, refer to the docs for add_data. I'll aim to have a fix out in the next few hours. |
@GL-Software This is patched now with
Note that the configuration keys required for Oanda have changed slightly to clarify what they are to be used for. You can refer to the account configuration docs for the new keys, but feel free to ask here if it is not clear. For complete reference, this is the runfile I have used to verify the fix: from autotrader import AutoTrader
at = AutoTrader()
at.configure(verbosity=1, show_plot=True, feed='oanda', mode='periodic')
at.add_strategy('macd')
at.backtest(start = '1/1/2022', end = '1/5/2022')
at.virtual_account_config(initial_balance=1000, leverage = 30)
at.run() And this is my account config for Oanda ( OANDA:
LIVE_API: "api-fxtrade.oanda.com"
LIVE_ACCESS_TOKEN: "xxx-yyy"
PRACTICE_API: "api-fxpractice.oanda.com"
PRACTICE_ACCESS_TOKEN: "xxx-yyy"
DEFAULT_ACCOUNT_ID: "xxx-xxx-xxxxxxxx-xxx"
PORT: 443 |
Thx Kieran now it works fine! Is it possible to see all orders opened/close in backtest as a report ? Actually I can see only summary statistical info and backtest graph, there's no way to check if strategy works as expected by inspecting a report trade by trade. |
Glad to hear. Absolutely, you can access all of this info via To look at the trades (ie. fills), you can inspect
Since you are using Oanda, you might be more interested in
There is a whole lot more info to be found in the EURUSD_bot = at.get_bots_deployed('EUR_USD')
EURUSD_bot.trade_results Hope this helps! |
Thx so much Kieran, I'll take a look |
Hi,
I'm trying to backtest your macd demo strategy using Oanda as broker but I'm not able to do so.
Here's steps I've done :
Create a demo account in Oanda , so to receive api v20 access token and account id
Generate keys.yaml in /config folder where I've put previous data (ACCESS_TOKEN, DEFAULT_ACCOUNT_ID)
Modified runfile.py to use oanda as broker at line: at.configure(verbosity=1, show_plot=True, feed='oanda', mode='periodic')
Changed macd.yaml like to match EURUSD Oanda symbol at line : WATCHLIST: ['EUR_USD']
Execute python runfile.py and received this error :
(base) C:\Users\Giacomo\Downloads_AutoTrader\AT_DEMO>python runfile.py
Traceback (most recent call last):
File "C:\Users\Giacomo\Downloads_AutoTrader\AT_DEMO\runfile.py", line 9, in
at.run()
File "C:\Users\Giacomo\anaconda3\lib\site-packages\autotrader\autotrader.py", line 1049, in run
self._main()
File "C:\Users\Giacomo\anaconda3\lib\site-packages\autotrader\autotrader.py", line 1428, in _main
self._assign_broker(broker_config)
File "C:\Users\Giacomo\anaconda3\lib\site-packages\autotrader\autotrader.py", line 1635, in _assign_broker
broker.configure(**account_config, autodata_config=autodata_config)
File "C:\Users\Giacomo\anaconda3\lib\site-packages\autotrader\brokers\virtual\broker.py", line 256, in configure
self._autodata = AutoData(data_config, **autodata_config)
File "C:\Users\Giacomo\anaconda3\lib\site-packages\autotrader\autodata.py", line 82, in init
self.ACCOUNT_ID = data_config["ACCOUNT_ID"]
KeyError: 'ACCOUNT_ID'
Is there something else that I have to set in order to be able to backtest whatever strategy using oanda historical prices ?
Thanks,
Regards
Giacomo
The text was updated successfully, but these errors were encountered: