PART TWO: Setup — Building a Production-Ready Algorithmic Trading Framework

Joseph Edginton-Foy
5 min readApr 19, 2023

--

Photo by Luisa Frassier on Unsplash

Hello there, and welcome to PART TWO of THREE on how to set up the project. If you still need to complete PART ONE (link), we installed our tools, python version and IDE.

If you want a specific part of this series, you can find all the information here!

This article will discuss Python Environments, the projects directory layout and the packages we will need to install.

Photo by Linus Mimietz on Unsplash

Python Environments

When you first installed Python through anaconda or whatever avenue of installation you chose, that version of Python became your system’s global version. And if you desire, you can use this version with no problems. However, if you want to start building multiple complex projects, you will begin to run into issues related to packages and the version of Python they use.

I am not going to go deep into the reasoning behind Python environments. Some great articles on here already go into the weeds of it. So instead, I will show you how to set one up in PyCharm and install your packages there to avoid conflicts of versioning and not to affect your system’s global version and packages.

Please open up PyCharm and start a new project. Choose a location, and name your project, I used ‘DataSpace’ for the rest of the project — you don’t need to use the same name, but things might get complicated later on — take a look at the image below. You will see ‘New environment using’; this is our Python environment. We can choose a version as well, and our version is 3.9. Hit ‘create’, and we are ready to rock and roll.

New Project Screen in PyCharm

Project Directories

Once everything is ready, an empty project will present itself. So you will need to head over to the top left of our screen, where it says ‘Project’, right-click on the folder that says ‘DataSpace’ and go into ‘New’ to create a ‘Directory’ called ‘src’. Next, you will right-click on ‘src’ and create six new directories, take a look at the image below.

Project Directory Structure

Packages

The final stage is installing all the packages we will use in future articles. As I said in the beginning, you should always do your due diligence on any packages you install on your machine.

Next, head to the terminal located within PyCharm; it is at the bottom of your screen, somewhere near the middle. You should see something similar to the screenshot below.

PyCharm Terminal

Be sure it says (DataSpace) on the left-hand side or what ever you named the project; that is how you know you are in your Python environment. If it says ‘(base)’, enter the following, and you should enter the environment.

conda activate AlgoTrading

To install most python packages, we use ‘pip’. Of course, the acronym can mean many things depending on who you ask — “Python Install Packages”, “Pip Installs Python”, “Preferred installer program” — the list goes on. But to install a basic package, we type into the terminal the following:

pip install target_package

To make life easy for you, you can copy and paste the following into the terminal, and it will install everything in one go.

MACOSX:

pip install oandapyV20
pip install numpy
pip install pandas
pip install - upgrade git+https://github.com/yhilpisch/tpqoa.git
pip install - upgrade mplfinance
pip install TA-Lib
wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz \
&& sudo tar -xzf ta-lib-0.4.0-src.tar.gz \
&& sudo rm ta-lib-0.4.0-src.tar.gz \
&& cd ta-lib/ \
&& sudo ./configure - prefix=/usr \
&& sudo make \
&& sudo make install \
&& cd ~ \
&& sudo rm -rf ta-lib/ \
&& pip install ta-lib
pip install ta
pip install yagmail

WINDOWS:

Unfortunately, for the windows users out there, your installation is more complex.

Step 1: For the windows architecture, you right-click on your ‘computer’ (typically named ‘This-PC’ or ‘My Computer’) icon and click properties, and your system details will be displayed.

Windows System Details
Windows Architecture

Step 2: We cannot directly use the ‘pip install’ command when installing Ta-Lib. Therefore, we will first install the ‘whl’ file, found here:

https://www.lfd.uci.edu/~gohlke/pythonlibs/#ta-lib

The website is a helpful resource for many Python extensions, but we are concerned about Ta-Lib installation for now. You can scroll down to the section where you will find the relevant links, as shown below:

whl Files for TA-Lib

Download the file representing your python version and Windows architecture (32-bit or 64-bit). E.g. Since we have python version 3.9 installed and a 64-bit Windows 7 system, we will download the file ‘TA_Lib‑0.4.24‑cp39‑cp39m‑win_amd64.whl’.

‘cp39’ implies Python version 3.9, and ‘win_amd64’ means Windows 64-bit operating system.

Step 3: Move the file into the location of our project folder:

Example: C://User//PycharmProjects//DataSpace

Step 4: Since we have downloaded the file “TA_Lib‑0.4.24‑cp39‑cp39m‑win_amd64.whl”, the command we enter into our PyCharm terminal would be:

pip install TA_Lib-0.4.24-cp39-cp39m-win_amd64.whl

Step 5: And then you will be able to run:

pip install numpy
pip install pandas
pip install - upgrade git+https://github.com/yhilpisch/tpqoa.git
pip install - upgrade mplfinance
pip install ta
pip install yagmail

And that’s it, wait for the packages to install, and you should be ready to rock and roll. If you have any issues, please leave a comment, and I will endeavour to help and update the guide for your fellow readers.

Photo by Matt Duncan on Unsplash

If you want to help buy me a coffee that fuels the late nights of research and development of these articles, please consider donating to my PayPal link below. Thanks so much, and have a great day.

If you want to help buy me a coffee that fuels these articles’ late nights of research and development, please consider donating to my PayPal link below. Thanks so much, and have a great day.

paypal.me/JEFSBLOG

May you forever be profitable.

--

--