kieran-mackle / AutoTrader

A Python-based development platform for automated trading systems - from backtesting to optimisation to livetrading.
https://kieran-mackle.github.io/AutoTrader/
GNU General Public License v3.0
937 stars 215 forks source link

AutoData docs #69

Open rseverinop opened 1 year ago

rseverinop commented 1 year ago

**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 commented 1 year ago

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:

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 commented 9 months ago

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?)