With this article on ‘Python Libraries and Platforms’, we would be covering the most popular and widely used Python Trading Platforms and Python Trading Libraries for quantitative trading.

We have also previously covered the most popular backtesting platforms for quantitative trading, you can check it out here.

Python is a free open-source and cross-platform language which has a rich library for almost every task imaginable and also has a specialized research environment. Python is an excellent choice for automated trading in case of low/medium trading frequency, i.e. for trades which do not last less than a few seconds. It has multiple APIs/Libraries that can be linked to make it optimal and allow greater exploratory development of multiple trade ideas.

In this blog, along with popular Python Trading Platforms, we will also be looking at the popular Python Trading Libraries for various functions like:

• Technical Analysis
• Data Manipulation
• Plotting structures
• Machine Learning
• Backtesting
• Data Collection

Python Trading Library for Technical Analysis

TA-Lib

TA-Lib or Technical Analysis library is an open-source library and is extensively used to perform technical analysis on financial data using technical indicators such as RSI (Relative Strength Index), Bollinger bands, MACD etc. It not only works with Python but also with other programming languages such as C/C++, Java, Perl etc. Here are some of the functions available in  TA-Lib: BBANDS – For Bollinger Bands, AROONOSC – For Aroon Oscillator, MACD – For  Moving Average Convergence/Divergence, RSI – For Relative Strength Index. Read about more such functions here.

Python Trading Libraries for Data Manipulations

NumPy

NumPy or Numerical Python, provides powerful implementations of large multi-dimensional arrays and matrices. The library consists of functions for complex array processing and high-level computations on these arrays. Some of the mathematical functions of this library include trigonometric functions (sin, cos, tan, radians), hyperbolic functions (sinh, cosh, tanh), logarithmic functions (log, logaddexp, log10, log2) etc.

Pandas

Pandas is a vast Python library used for the purpose of data analysis and manipulation and also for working with numerical tables or data frames and time series, thus, being heavily used in for algorithmic trading using Python. Pandas can be used for various functions including importing .csv files, performing arithmetic operations in series, boolean indexing, collecting information about a data frame etc.

SciPy

SciPy, just as the name suggests, is an open-source Python library used for scientific computations. It is used along with the NumPy to perform complex functions like numerical integration, optimization, image processing etc. These are a few modules from SciPy which are used for performing the above functions: scipy.integrate (For numerical integration), scipy.signal (For signal processing), scipy.fftpack(For Fast Fourier Transform) etc.

Python Trading Library for Plotting Structures

Matplotlib

It is a Python library used for plotting 2D structures like graphs, charts, histogram, scatter plots etc. Along with the other libraries which are used for computations, it becomes necessary to use matplotlib to represent that data in a graphical format using charts and graphs. Few of the functions of matplotlib include scatter (for scatter plots), pie (for pie charts), stackplot (for stacked area plot), colorbar (to add a colorbar to the plot) etc.

Python Trading Libraries for Machine Learning

Scikit-learn

It is a Machine Learning library built upon the SciPy library and consists of various algorithms including classification, clustering and regression, and can be used along with other Python libraries like NumPy and SciPy for scientific and numerical computations. Some of its classes and functions are sklearn.cluster, sklearn.datasets, sklearn.ensemble, sklearn.mixture etc. You can read more about the library and its functions here.

TensorFlow

TensorFlow is an open source software library for high performance numerical computations and machine learning applications such as neural networks. It allows easy deployment of computation across various platforms like CPUs, GPUs, TPUs etc. due its flexible architecture. Learn how to install TensorFlow GPU here.

Keras

Keras is deep learning library used to develop neural networks and other deep learning models. It can be built on top of TensorFlow, Microsoft Cognitive Toolkit or Theano and focuses on being modular and extensible. It consists of the elements used to build neural networks such as layers, objectives, optimizers etc. Installing Keras on Python and R is demonstrated here. This library can be used in trading for stock price prediction using Artificial Neural Networks.

An event-driven library which focuses on backtesting and supports paper-trading and live-trading. PyAlgoTrade allows you to evaluate your trading ideas with historical data and see how it behaves with minimal effort. Supports event-driven backtesting, access of data from Yahoo Finance, Google Finance, NinjaTrader CSVs and any type of time series data in CSV. The documentation is good and it supports TA-Lib integration (Technical Analysis Library). It outperforms other libraries in terms of speed and flexibility, however, the biggest drawback is that it doesn’t support Pandas-object and pandas modules.

Zipline (Used by Quantopian)

It is an event-driven system that supports both backtesting and live-trading. Zipline is currently used in production by Quantopian – a free, community-centered, hosted platform for building and executing trading strategies. Zipline is well documented, has a great community, supports Interactive Broker and Pandas integration. At the same time, since Quantopian is a web-based tool, cloud programming environment is really impressive. However, Zipline is slower compared to commercial platforms with backtesting functionality in a compiled application and isn’t very convenient for trading multiple products.

Pybacktest

Vectorized backtesting framework in Python/pandas, designed to make your backtesting — compact, simple and fast. It allows the user to specify trading strategies using the full power of pandas while hiding all manual calculations for trades, equity, performance statistics and creating visualizations. Resulting strategy code is usable both in research and production environment. Currently, only supports single security backtesting, Multi-security testing could be implemented by running single-sec backtests and then combining equity. It is under further development to include multi-asset backtest capabilities.

Python Trading Libraries for Data Collection

FMZ Quant

Supporting strategy development, analysis optimization, backtesting, and market-simulation.
Providing most of mainstream programming languages for global blockchain trading assets www.fmz.com

Trading on Interactive Brokers using Python

Interactive Brokers is an electronic broker which provides a trading platform for connecting to live markets using various programming languages including Python. It provides access to over 100 market destinations worldwide for a wide variety of electronically traded products including stocks, options, futures, forex, bonds, CFDs and funds. IB not only has very competitive commission and margin rates but also has a very simple and user-friendly interface. Here we will discuss how we can connect to IB using Python.

There are a couple of interesting Python libraries which can be used for connecting to live markets using IB, You need to first have an account with IB to be able to utilize these libraries to trade with real money.

IBridgePy

It is an easy to use and flexible python library which can be used to trade with Interactive Brokers. It is a wrapper around IB’s API which provides a very simple to use solution while hiding IB’s complexities. To learn to utilize this library you can check out this youtube video or this fantastic blog

IBPy

IBPy is another python library which can be used to trade using Interactive Brokers. Details about installing and using IBPy can be found here. As mentioned above, each library has its own strengths and weaknesses. Based on the requirement of the strategy you can choose the most suitable Library after weighing the pros and cons. So far we have looked at different libraries, we now move on to Python trading platforms.