Comments (5)
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.
from autotrader.
@GL-Software This is patched now with v0.7.1
, so you can either update by pulling the latest from the repo or by running:
pip install autotrader --upgrade
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 (config/keys.yaml
):
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
from autotrader.
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.
from autotrader.
Glad to hear.
Absolutely, you can access all of this info via at.trade_results
- this is an instance of the TradeAnalysis
class.
To look at the trades (ie. fills), you can inspect at.trade_results.trade_history
, giving you a DataFrame like this:
In [5]: at.trade_results.trade_history
Out[5]:
order_time order_price order_type fill_time fill_price direction size fee instrument id order_id broker
2022-01-19 11:00:00+00:00 2022-01-19 10:00:00+00:00 1.061250 market 2022-01-19 11:00:00+00:00 1.06120 1 3663.00 0.0 AUD_NZD 1 1 broker
2022-01-20 00:00:00+00:00 2022-01-20 00:00:00+00:00 1.065345 market 2022-01-20 00:00:00+00:00 1.06535 -1 3663.00 0.0 AUD_NZD 2 1 broker
Since you are using Oanda, you might be more interested in at.trade_results.isolated_position_history
. This will closer reflect how Oanda manages 'trades', which is a bit more like treating them as positions (hence the name 'isolated position'). This DataFrame looks as so:
In [8]: at.trade_results.isolated_position_history
Out[8]:
instrument status ID order_price order_time ... exit_time exit_price trade_duration fees broker
2022-01-19 11:00:00+00:00 AUD_NZD closed 1 1.06125 2022-01-19 10:00:00+00:00 ... 2022-01-20 00:00:00+00:00 1.06535 46800.0 None broker
2022-01-24 21:00:00+00:00 AUD_NZD closed 2 1.06631 2022-01-24 20:00:00+00:00 ... 2022-01-25 08:00:00+00:00 1.07047 39600.0 None broker
There is a whole lot more info to be found in the TradeAnalysis
class stored in at.trade_results
- try inspecting at.trade_results.__dict__.keys()
to start. Note that if you are running a strategy with multiple trading bots, you can access their specific trade analysis object in the same manner, perhaps first by using the get_bots_deployed
method to get the bot. Some pseudo code:
EURUSD_bot = at.get_bots_deployed('EUR_USD')
EURUSD_bot.trade_results
Hope this helps!
from autotrader.
Thx so much Kieran, I'll take a look
from autotrader.
Related Issues (20)
- AutoData docs HOT 2
- Can we please get an exact Step-by-Step tutorial of how to set it up with Crypto Exchange? HOT 1
- Crash raise ValueError("No objects to concatenate") HOT 2
- Crash: IndexError: only integers, slices (`:`), ellipsis (`...`),
- Taking profits and leaving runners concept
- Range exception index -1 in indicator method unroll_signal_list
- Plot Error when running backtest on multiple pairs HOT 1
- Not clear how to login, needing simple example template HOT 2
- multi-time frame data not working
- \
- help with issue HOT 1
- 'Index' object has no attribute 'tzinfo', and so on ~ HOT 1
- Running paper trade mode in Oanda
- Display statistics in backtesting mode
- Peer closed connection. clientId 3 already in use?
- Integrate existing indicator library HOT 2
- Custom xml plot path
- Help beginners run the project locally HOT 5
- Divergencies not plot again HOT 1
- Can't use crypto exchange as feed?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autotrader.