A definitive guide to learning Python for Algorithmic Trading

Women Who Code
4 min readSep 8, 2018


Algorithmic trading (also known as black-box trading, automated trading, or simply algo-trading) refers to the process of using computer programmes that follow an algorithm (defined set of instructions) for placing a trade, in order to generate profits at speeds and frequencies that are impossible to achieve manually. These algorithms are based on timing, pricing, quantity, or any other mathematical model. Apart from just offering better profit opportunities for the trader, these algo-trading models also make the market more liquid and make the process a lot more systematic by ruling out any impact of human emotions on the trading activities.

Finding the perfect algorithm to successfully trade in financial markets is the holy grail in finance. Not so long ago, algo-trading was only for the big players with heavy pockets and innumerable assets under management. However, the last couple of decades have seen tremendous developments in the fields of open source software/tools, cloud computing, open data, as well as online trading platforms. This has made it absolutely possible to get started in this field just by being equipped with a modern notebook (read laptop) and an internet connection only.

The growth of data science over the years has resulted in a much more widespread use of Python programming language. Over the years, Python has grown to be the one-stop solution for everything in and around data — from visualizations to algo-trading. Before we get talking more about this, it’s important to let you know that there are various sophisticated data science courses at your disposal that’ll help you understand the actual science behind data science. It is undeniably important to stay fully informed about the finer points of data science that’ll help you get better at accomplishing bigger tasks.

Getting back to the topic, Python and its ecosystem of powerful packages have emerged as the most desired technology choice for algorithmic trading. Among other benefits, Python allows you to perform efficient data analysis (with pandas), to apply ML techniques to stock market prediction (with sci-kit-learn), or even make use of Google’s deep learning technology (with tensorflow). Imagine writing a Python script which can automatically buy 200 shares of a company when its price hits an all-time low, and sell it when it rises by 3% (or based on some different strategy, whatever floats your boat). Sounds fun, right?!

But, to do any of that, you’ll need to familiarize yourself with the following items:

  • Financial data: Financial data forms the core of each and every algorithmic trading project. Python offers a number of packages that do a great job in handling and working with structured financial data of any kind (intraday, end-of-day, high-frequency, you name it.). Let’s look at some such packages and libraries that are extensively build to ease down your workload while working with unstructured financial data:
  • numpy — Numpy is the most fundamental library for scientific computing using Python. It is used for numerical programming and finds an extensive use in finance as well as academia.
  • scipy — SciPy supplements the popular Numeric module, Numpy. It is a Python-based ecosystem of open-source software for mathematics, science, and engineering. It is also used extensively for financial and scientific computations.
  • pandas — The pandas library offers easy-to-use, high-performance data structures for data analysis. Pandas focus on the fundamental data types and their methods, leaving other packages to add more sophisticated statistical functionality
  • Real-time data: Algorithmic trading requires dealing with fast in-coming real-time data. This involves a little bit of socket programming (preferably with ZeroMQ). Python comes in extremely handy while visualizing this real-time data to derive actionable insights. Here are some visualization libraries that help in analyzing this real-time data:
  • matplotlib: It is the O.G. of Python data visualization libraries. Although it is over a decade old, it is still most extensively used for plotting. It was designed to closely resemble MATLAB. Being the first visualization library, matplotlib supports various other packages and libraries that are built on top of it or are designed to work in tandem with it.
  • seaborn: It harnesses the power of matplotlib to create beautiful and aesthetically pleasing charts in a few lines of code. Seaborn offers various default styles and color pallets, but since it is built on top of matplotlib, it is recommended to have a fair idea of the working of matplotlib to tweak seaborn’s defaults.
  • Online platforms: Trading isn’t possible without a trading platform. If you’re looking to get going with algorithmic trading using Python, you’re expected to have an idea of the various trading platforms, to choose which one is the best for you. The most popular trading platforms are:
  • Automation: Automation is what makes the algorithmic trading beautiful as well as challenging. You should be well versed with how to deploy Python in the cloud and how to set up an environment appropriate for automated, algorithmic trading. Let’s look at a couple of such automated hosting platforms that are extensively used today:
  • Quantiacs: Quantiacs is an open-sourced Python platform which provides a toolbox for you to develop and backtest your trading ideas. It also offers free and clean financial data and allows you to develop as many strategies as you want, and the most profitable ones can be submitted in the Quantiacs algorithmic trading competitions.
  • Quantopian: Quantopian is another popular open source python platform for testing and developing trading ideas and strategies. It allocates capital for selected trading algorithms and you get a share of your algorithm’s net profit. It is also supported by an extremely active community wherein trading ideas and problems get discussed among the members.

With this, we come to the of our discussion. Having a clear understanding of the things mentioned above will ensure that you’re on the right track in the world of algo-trading!

Originally published at www.womenwhocode.com.



Women Who Code

We are a 501(c)(3) non-profit organization dedicated to inspiring women to excel in technology careers. https://www.womenwhocode.com/