Skip to content
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

AutoData docs #69

Open
rseverinop opened this issue Dec 1, 2022 · 2 comments
Open

AutoData docs #69

rseverinop opened this issue Dec 1, 2022 · 2 comments

Comments

@rseverinop
Copy link

**Is your feature request related to a problem? Imagine user wants to use data from other sources for AutoData() for example a data frame from MetaTrader5, how that user could integrate their strategies with auto trader?

@kieran-mackle
Copy link
Owner

Hi @rseverinop,

There are two ways you could go about this. The first (and the simplest) way would be to use the add_data method to read from local data files. An example run script is provided below, where a file name "EUdata.csv" contains data for the "EUR_USD" instrument in the strategy config file. Of course, you would need to figure out a way to write data from MetaTrader5 to a CSV file.

from autotrader import AutoTrader

# Create AutoTrader instance, configure it, and run backtest
at = AutoTrader()
at.configure(verbosity=1, show_plot=False, mode="periodic")
at.add_strategy('macd')
at.backtest(start='1/1/2021', end='1/5/2021')
at.virtual_account_config(initial_balance=1000, leverage = 30)
at.add_data(data_dict={"EUR_USD": "EUdata.csv"})
at.run()

Note that AutoTrader expects the data to be kept in a price_data/ directory, as per the recommended directory structure, but you can specify a different directory using the data_directory path.


The second option is to use a custom data pipeline. Unfortunately, I haven't had the chance to document any examples of this approach, but you can use the source code for guidance. As a short summary to get you started:

  • Each trading bot instantiates its own DataStream object, responsible for providing processed data to the bot.
  • You can create your own custom DataStream class by inheriting it first and adding your own logic, then provide it to AutoTrader using the add_data method, via the stream_object argument.
  • The first method of DataStream to overwrite is the refresh method, called by the trading bots. This is where you place any logic to load the data. Here, you could connect to MetaTrader to retrieve the data, before formatting it into a DataFrame.
  • The second method which you may need to overwrite is get_trading_bars. If your data is in the standard Pandas DataFrame format, you may skip this step.

If this option is something you are interested in, let me know and I will try to find a minimum working example.

Please let me know if you have any questions about the options above.

@x-EricH-x
Copy link

x-EricH-x commented Nov 18, 2023

Hi, thank you so much for sharing this great framework and keeping it well maintained.

I am actually facing a similar issue.
I have the OHLC data saved as a local database file. During analysis, I usually use make a SQL query and put them in a DataFrame. Just wonder how to make it work without re-exporting to CSVs. Is there some more info on using custom data source?

I looked a bit into the DataStream class,
Am I correct that in addition to OHLC price data, quote_data must also be provided?
And what AutoData class/instance should I use in such case? (e.g. do I need to subclass it or config it in some ways?)

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

3 participants