Python is a widely used high level programming language. It has emerged as a robust scripting language particularly useful for complex data analysis, statistics, data mining and analytics. It has found its application in automation which is another reason why it is the best choice for Algorithmic Trading. The beauty of this language lies in its simplicity and readable syntax. Any complex logic can be coded in fewer lines in Python when compared to other programming languages. In this tutorial series, we would go through the step by step method to implement algorithmic trading using python. The tutorial starts from very basics like python installation and down the line we’ll explore trading system development, backtesting, optimization etc.
Note: This isn’t a Python tutorial from the scratch. but still we’ll try to make it as simple as possible so that newbies can follow. In order to learn python basics (which I recommend you should), please check out the below two courses at Udemy. I have taken both these courses myself, and it has helped me a lot in last few years.
Step 1: Installing Python in your machine
Python is an open source language freely available for download. The latest version is 3.x but we recommend 2.7 as it is the most stable version of python released till now. Access the download location from this link. Download the correct file depending on your OS. The installation steps are very simple. Just follow the GUI and use all the default options. It wouldn’t take more than 60 secs to complete the installation
Step 2: Setup Environment Variables
Assuming that Python is installed at “C:\Python27\” folder, append the below to your PATH variable and PYTHONPATH variable:
In windows machine, Environment variables can be accessed from My Computer–>Properties–>Advanced System Settings–>Environment Variables
Step 3: Install Jupyter Notebook
Jupyter Notebook or iPython Notebook is a lightweight interactive GUI for Python. You can even access Python and execute all the scripts through command prompt, but GUI makes it more interesting and adaptable. In order to install Jupyter Notebook, goto command prompt and execute below statement:
pip install jupyter
It will download the installation package automatically and continue installation. The installation will take few minutes depending on your internet speed. Below is the screenshot taken after installation completion.
Note: If the installation fails download and install Microsoft Visual Studio C++ compiler.
Step 4: Launch Python using Jupyter Notebook
In order to launch notebook, first of all create a folder at your local machine where you will store all your scripts. It can be under My Documents or any other location except the parent C Drive. This folder will act like a workspace for all your programs. Now, open command prompt again, and goto this folder you created. Once you are in the folder location, type the below command to start notebook:
This will automatically open your web browser and open the notebook interface which looks similar to below:
Navigate to New–>Python2, it will open up the editor where you can execute python statements. See below for a simple Python statement:
This completes your first step to learn Algorithmic Trading using Python!
In the later part of this “Algorithmic Trading Using Python” tutorial series we’ll learn many other interesting stuffs. If you have followed this tutorial and installed Python in your machine successfully, then the most difficult part is over. Now just sit back and wait for our next article. Also, try to complete the Udemy courses we recommended earlier.
I guess many of you must be curious to know why to learn Python when we have Amibroker and other full suite trading softwares. Well, the simplest explanation to this is, python is open source and totally free of cost. Also, it is flexible enough and there are hardly any limitations, which I guess is the major pain point associated with all other tools. Python can handle large data sets super efficiently, see it yourself later in this tutorial.