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
945 stars 217 forks source link

Backtests for Intraday Strategies which involve exiting trade at particular time before auto square off #15

Closed rahulmr closed 2 years ago

rahulmr commented 2 years ago

Is your feature request related to a problem? Please describe. Not sure whether it is request but would like to know how we can perform backtests for intraday strategies. Time frame 5 min something like that. Yfinance gives data for intraday only for 2 months (1 min or 5 min data).

Describe the solution you'd like Facility to run intraday backtests using say 5 min timeframe data. Solution is to have local csv files and call them in pandas and use for analysis.

Describe alternatives you've considered Download csv data and run backtest using that data

Additional context Brokers provide 5 min data for 60 days only if we want more data we need to run in loop for every 2 months. And only 5 years data is available for zerodha like Indian broker

kieran-mackle commented 2 years ago

This can be achieved using the data_file attribute of an AutoTrader instance. See the Getting Price Data docs for an example. As a quick summary, you can provide the file name of your data as follows:

from autotrader.autotrader import AutoTrader

at = AutoTrader()
at.data_file = 'price_data.csv'

Just make sure that your file, eg. price_data.csv, is in a price_data sub-directory of your project, as this is where AutoTrader will search for it.

kieran-mackle commented 2 years ago

@rahulmr I have just added a new method, add_data to AutoTrader (v0.5.21), which adds a bit more capability to providing local data files. See the documentation for this method here.