Home

This is a highly modular program that allows for users to easily switch the data and execution APIs, as well as strategies.

Code is available at execPlatform. Note the repository is private and source code for the entire project is only available to contributors.

Layout

execPlatorm/
    .venv/
    .git/
    ...
    Backtesting/
        __init__.py             #documentation module purposes
        backtest.py             #main loop
        data.py
        execution.py
        initial_conditions.py   #input conditions
        performance.py
        portfolio.py
        strategy.py
        plot.png                #output plot
        results.json            #output json

Packages

Download the following through pip install .... It is recommended a venv is set up to handle package dependencies.

  • python-dotenv
  • matplotlib
  • requests
  • alpaca-py (refer to the alpaca-py sdk docs)
  • mkdocs mkdocs-material mkdocstrings[python] (used for generating a documentation page)

Overview

Inputs

Use the initial_conditions.py file to set the input parameters.

Main

The backtest.py file contains the loop. Note that the modular features are implemented as instantiantions of an abstract class. Simply specificy which class (data API, execution API, strategy) you are using.

Note that Execution is a class that wraps the execution_api class. This is because all APIs must perform checks before making the buy/sell call. Since abstract base class methods cannot have logic, the class must be wrapped.

For the backtester, the execution_api will always by MockExecutionAPI, since it is using historical and not current prices.

Ouputs

The performance.py file prints statistics at the end of the loop

Documentation

For a new python file in Backtesting/, create a markdown file in execPlatform/my-project/docs/files/. It should contain ::: Backtesting.file_name, where the extension is not included. Then run mkdocs serve to confirm locally and then mkdocs build for the html files.

The project is hosted on netlify. Upload the my-project/site/ directory to the netlify project.

To do

  • handle rate limiting by making get_prices just a read in a db
  • make a documentation page and add to blog