Visual Studio Code development#
In this document, we show how to develop trading strategies using Visual Studio Code.
Using Visual Studio Code is recommended for development on your local laptop, unless you know any other favorite Jupyter Notebook editors.
Prerequisites for developing trading strategies with Visual Studio Code are:
Python programming basics
Command line usage basics
Install Visual Studio Code, git, and Python locally
These instructions currently work 1:1 for macOS and Linux systems only. Microsoft Windows based installations need additional tools like Microsoft Visual Studio installed and are not yet covered in these instructions.
While the software is in beta,
git command must be installed,
as we are using it to download code from Github.
Python 3.10 or higher version is needed.
Installing Visual Studio Code#
Start Visual Studio Code.
Install Python extension through Extensions view inside Visual Studio Code.
Install Jupyter extension through Extensions view inside Visual Studio Code.
In Visual Studio Code, open the terminal (Terminal > New terminal)
Check that your Python installation is configured
Python 3.9.12 (main, Mar 26 2022, 15:44:31) [Clang 13.1.6 (clang-13188.8.131.52)] on darwin Type "help", "copyright", "credits" or "license" for more information.
Use CTRL+D to exit.
Then try git commad on command line:
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
Now install Poetry command needed for the project installation:
curl -sSL https://install.python-poetry.org | python3 -
Creating Python environment#
Create an empty folder where you will place your backtesting workspace files.
Start Visual Studio Code. Go to File > Open folder and choose your newly created folder.
Open a terminal inside Visual Studio Code: Terminal > New Terminal.
Now we need to check out the source code tree using
git to your workspace folder:
git clone https://github.com/tradingstrategy-ai/trade-executor.git
Then we set up Python environment with
trade-executor package installed:
cd trade-executor git submodule update --init --recursive poetry shell poetry install
This should output:
Installing the current project: trade-executor (0.1.0)
Now Poetry has created a new Python environment with required packages for you.
You can find the Python environment
python command location on your hard drive with the following command:
poetry env info
This should output your Virtualenv where the Python packages are installed.
Virtualenv Python: 3.9.12 Implementation: CPython Path: /Users/moo/Library/Caches/pypoetry/virtualenvs/trading-strategy-docs-jBbc2tTM-py3.9 Valid: True
Your Python intepreter path is the above path plus added
E.g. in the above case this is:
You can test that Poetry installation works by running your Python interpreter now. Copy-paste the full Python interpreter path to your Visual Studio Code terminal. You will also need this path of the command later:
Then in Python prompt running:
… should not give any errors.
Download strategy backtesting template#
Save it in your workspace folder.
Open the notebook#
Use File… Open to open the template in Visual Studio Code.
Adding Python environment to Visual Studio Code#
In Visual Studio Code, we need to tell the Visual Studio Code what Python environment to use for running the notebook.
Choose View > Command palette.
Type in to search for the command Python: Select interpreter.
Choose Enter interpreter path.
Copy-paste the Virtualenv path from
poetry env output you did earlier.
For more information, see configuring enviroments in Visual Studio Code and Python documentation by Microsoft.
Press Run all to execute the template notebook.
It will prompt you to choose a Python environment. Choose the one we just added.
Visual Studio Code should ask for the Trading Strategy API key on the first run
The run should complete with a checkmark on the last notebook cell
If you get an error:
ModuleNotFoundError: No module named 'tradeexecutor'
It means Visual Studio Code is not picking the Python environment where we installed
Make sure that Visual Studio code is displaying the correct Python interpreter in the top right corner: