Home

Awesome

Getting started with algorithmic trading with TradingStrategy.ai

splash

Support and social media

Got any questions? Pop into our Discord.

Prerequisites

In order to get started you need

If you use Github Codespaces, no additional software is needed, you can do the first tests in your web browser.

To get a quick primer on the Trading Strategy framework, check the Trading Strategy workshop video recording.

Development environment options

You can either run and edit these examples

Example strategy backtests

Here are example notebooks for backtesting. Each of the backtest code can be taken to a live trading strategy as is. The examples vary between from old fashioned technical indicator based algorithms to portfolio construction and DeFi yield optimisation.

Individual backtests:

Example grid and optimisation searches

Grid searches run several backtests over multiple strategy parameter combinations. This allows you to "brute force search" better strategies and explore the behavior of a strategy with different parameters.

Example research only notebooks

Example live trading

How to run on Github Codespaces

In this tutorial, we open a single backtest in Github Codespaces and run it. You can do all in your web browser using your Github account, no software is needed.

Press Create codespace master on Github repository page (master refers to the primary development branch of Git version control system).

This will give you a page showing your codespace is being launched.

After a while your Github Codespaces cloud environment is set up. The first launch is going to take a minute or two.

In the file explorer on the left, open a notebook: notebooks/single-backtest/matic-breakout.ipynb.

After opening the notebook click Clear all Outputs and then Run all button Jupyter toolbar.

When you are asked to Select kernel. Choose Python Environments.. and then /usr/local/bin/python.

img.png

You should see now notebook running, indicated by the progress indicator and run time count down in each notebook cell.

img.png

After the notebook is running successfully, you should be able to press Go to on the toolbar and see the backtesting progress bar going on. You will see a separate progress bar for 1) downloading data (done only once) 2) calculating technical indicators 3) running the backtest.

img.png

Note: If you see a text "Error rendering output item using 'jupyter-ipywidget-renderer. this is undefined. it means Visual Studio Code/Github Codespaces has encountered an internal bug. In this case press Interrupt on a toolbar, close the notebook, open it again and press Run all again. It happens only on the first run.

Shortly after this backtests results are available.

You can find them by scrolling down to the different sections

img.png

And now you are done with our first backtest! Continue below to learn more how you can get started with your own strategies.

Setting up Python environment from command line

Example how to run notebooks and scripts from the command line.

# Get all Python source code we need
# (A lot of code)
git clone --recursive https://github.com/tradingstrategy-ai/trade-executor.git deps/trade-executor

# Create virtual environment
poetry install

# Active Pytohn virtual environment
poetry shell

# Run script
python scripts/prefilter-uniswap-v3-ethereum.py

Strategy backtest notebook structure

Each strategy backtest notebook will consist of following phases.

This is a rough skeleton. You mix and match can easily add your own trading signals and output charts using with all tools available in Pandas and Jupyter notebook ecosystem. There aren't any limitations on what you can do.

Learning resources

Troubleshooting

Note to Mac users: The current Docker image is built for Intel platform. If you run Dev Container on your Mac computer with Visual Studio Code, the backtesting speed is slower than you would get otherwise.

Testing the Dev Container build:

devcontainer up --workspace-folder . 

Checking installed packages wihtin Codespaces terminal:

pip list

Running the example notebooks using command line ipython (useful for debugging)

ipython notebooks/single-backtest/bitcoin-breakout-atr.ipynb