Python Trading Strategy in Quantiacs Platform

By Milind Paradkar

Algorithmic trading has seen great traction in recent years and the numbers of students, engineering graduates, and finance professionals looking to explore this lucrative domain has been growing exponentially with each passing year.

Are you among the ones looking to learn quant skills and also make money with your trading ideas? Let us explore the Quantiacs platform which allows one to create, run and implement your Python trading strategy. Quantiacs offers great earning opportunities for successful quants.

Quantiacs Toolbox

The Quantiacs toolbox is free and open-source. Quantiacs provides up to 25 years of free data for 49 futures and S&P 500 stocks. The toolkit allows the user to create a trading strategy and backtest it with data all the way back to 1990.  In addition to futures data, Quantiacs has recently added macro-economic data which can be used in conjunction with the price time series data to improve the trading algorithms. Quantiacs supports both Python and Matlab. In this post, we will explore the Python toolbox and illustrate a toy strategy using it.

Quantiacs Python Toolbox

Quantiacs has created a simple yet powerful Python framework which can be used to create different types of algorithmic strategies. It provides for defining trading system settings like loading market data, trading costs, custom fields, capital etc. Others features of the Python toolbox include evaluating the trading system, optimization, visualization of results etc. Let us explore some features of the Python framework here.

Loading the market data:

Quantiacs trades in both stock and futures markets. Here is what the data fields look like for a stock:


Source: Quantiacs.com

We can load the stock data in Python using the quantiacsToolbox.loadData function.

As can be seen, the data is in the form of a Python dictionary. Let us check the data type of the key-value pairs.

To create a Python trading strategy we will have to manipulate the numpy array and it is required that you have a good understanding of Python numpy arrays and the myriad functions that it supports. Here’s a list of some useful functions – https://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html

Candle High-Low Python Strategy

Now let us take a very simple candle high-low strategy and try to code it using the Quantiacs toolbox. The step-by step process has been illustrated below.

Step 1: Define the Settings

We test our sample strategy on Apple Inc. (AAPL) and Amazon Inc. (AMZN) stocks. The backtest period is defined in settings[‘beginInSample’] and  settings[‘endInSample’]  variables. We also define the lookback days, capital and the slippage.

Step 2: Python Trading Strategy

We have kept our strategy simple. In the first step, we define the number of candles which represent the number of the previous prices that will be considered for generating a buy/sell signal. We then compute the price difference of the last ‘n’ candles. If all the price differences are positive we go short expecting a mean reversion behavior. If all the price differences are negative we go long.

The long position is indicated by the value 1, while the short position takes value of -1.

Step 3: Run the Strategy

To execute our strategy, we use the quantiacsToolbox.runts command and specify the respective Python file.

Step 4: Visualize the results

Upon execution, the Python framework displays a very informative chart which includes the markets, an option to select the exposure type, various performance metrics etc.

As can be seen the Quantiacs Python framework is easy to use and can be used to develop varied trading strategies.

Next Step

If you want to learn various aspects of Algorithmic trading then check out the Executive Programme in Algorithmic Trading (EPAT™). The course covers training modules like Statistics & Econometrics, Financial Computing & Technology, and Algorithmic & Quantitative Trading. EPAT™ equips you with the required skill sets to be a successful trader. Enroll now!

You can also check out our interactive course, ‘Python for Trading‘, you’ll get hands-on experience on Python coding. You’ll get to code your own strategy and backtest it as well plus a joint certification from QuantInsti and MCX.

Leave a Reply

Your email address will not be published. Required fields are marked *