A simple backtester to test trading algorithms and portfolio optimization strategies.
Docker
docker build . && docker run
Take note:
- First time this is run, it takes awhile to set up docker environment
plt.show()
wont work. Save it in a file instead (TODO)
Local
python -m pip install -r requirements.txt && python -m pip install -e .
python loop.py -c credentials.json
python loop.py -c credentials.json
- runs the backtester.
This repo is meant to be as low-level as possible to get greater control of the backtesting environment. Edit the various scripts explained below and import them to loop.py
to test your strategies.
This event-driven backtester consists of the following:
- DataHandler (Defines trading universe, reads in necessary data)
- broker Enironment (Details about the exchange that might affect backtesting strategies)
- Portfolio (Executes
OrderEvent
based onSignalEvent
, updates portfolio as necessary) - Strategy (Looks for
SignalEvent
to be routed to portfolio)
HistoricCSVDataHandler
Arguments:
event_queue
- An event queue, created asqueue.LifoQueue()
csv_dir
- directory where csv files are keptsymbol_list
- List of symbols as stock universe. Ensure that symbols have the same name as the CSV files incsv_dir
start_date
- YYYY-MM-DD. Has to be a trading day elseKeyError
will be returned.end_date
(OPTIONAL) - YYYY-MM-DD. Has to be a trading day elseKeyError
will be returned.
NOTE: Add the above to a github wiki page when more information is available