Algorithmic Trading Using Python: Introduction and Setup

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.

Complete Python Bootcamp: Go from zero to hero in Python

Python Algo Stock Trading Platform

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.

Algorithmic Trading Using Python

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:

jupyter notebook

This will automatically open your web browser and open the notebook interface which looks similar to below:

Jupyter Notebook

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.

Related Posts


  1. sir not able to install jupyter directly it says install anaconda so how to install via pip installer kindly guide.

  2. sir i am not able to install juypter notebook kindly help . i install only python 2.7 in C:\Python27 after that stucked please help

  3. Are there built in libraries for indicators and time frames? For example, is it possible to buy when CCI(14) crosses zero up and to sell when there is a 1% profit without even looking at indicators?

  4. Sir, when is the next tutorial on this thread going to be published?
    This is really interesting topic.

  5. Sir, Starting from step 3 got stuck with. Unable to download the Jupyter and stating needed to download Anaconda 2 first and its heavy like 650 MB. Even tried downloading the same however getting failed in the middle. Unsure of what’s next, kindly help. Thanks!

  6. How to change timezone to India for following code
    import pandas as pd
    from alpha_vantage.timeseries import TimeSeries
    import time

    api_key = “XXXXXXXXXXXXXX”

    ts = TimeSeries(key=api_key, output_format=’pandas’)
    data, meta_data = ts.get_intraday(symbol=”NSE:SBIN”, interval = ‘1min’, outputsize = ‘full’)


  7. I want to develop an automated trading platform with my signals using puthon and zerodha

Leave a Reply

Your email address will not be published.