Join the Quantcademy private membership portal that caters to the rapidly-growing retail quant trader community. You'll find a knowledgeable, like-minded group of quant traders ready to answer your most pressing quant trading questions.
Check out my ebook on quant trading where I teach you how to build profitable systematic trading strategies with Python tools, from scratch. Take a look at my new ebook on advanced trading strategies using time series analysis, machine learning and Bayesian statistics, with Python and R. In this article the concept of automated execution will be discussed. Broadly speaking, this is the process of allowing a trading strategy, via an electronic trading platform, to generate trade execution signals without any subsequent human intervention.
Most of the systems discussed on QuantStart to date have been designed to be implemented as automated execution strategies. The article will describe software packages and programming languages that provide both backtesting and automated execution capabilities.
The first consideration is how to backtest a strategy. My personal view is that custom development of a backtesting environment within a first-class programming language provides the most flexibility.
Conversely, a vendor-developed integrated backtesting platform will always have to make assumptions about how backtests are carried out. Despite this, the choice of available programming languages is large and diverse, which can often be overwhelming. It is not obvious before development which language is likely to be suitable. When codifying a strategy into systematic rules the quantitative trader must be confident that its future performance will be reflective of its past performance.
There are generally two forms of backtesting system that are utilised to test this hypothesis. Broadly, they are categorised as research back testers and event-driven back testers. We will consider custom backtesters versus vendor products for these two paradigms and see how they compare. When identifying algorithmic trading strategies it usually unnecessary to fully simualte all aspects of the market interaction.
Instead, approximations can be made that provide rapid determination of potential strategy performance. Such research tools often make unrealistic assumptions about transaction costs, likely fill prices, shorting constraints, venue dependence, risk management and position sizing. Despite these shortcomings the performance of such strategies can still be effectively evaluated.
These software packages ship with vectorisation capabilities that allow fast execution speed and easier strategy implementation. With such research tools it is possible to test multiple strategies, combinations and variants in a rapid, iterative manner, without the need to fully "flesh out" a realistic market interaction simulation.
While such tools are often used for both backtesting and execution, these research environments are generally not suitable for strategies that approach intraday trading at higher frequencies on sub-minute scale. These libraries do not tend to be able to effectively connect to real-time market data vendors or interface with brokerage APIs in a robust manner.
Despite these executional shortcomings, research environments are heavily used within the professional quantitative trading industry. They provide the "first draft" for all strategy ideas before promotion towards more rigourous checks within a realistic backtesting environment. Once a strategy is deemed suitable in research it must be more realistically assessed. Such realism attempts to account for the majority if not all of the issues described in previous posts. The ideal situation is to be able to use the same trade generation code for historical backtesting as well as live execution.
This is achieved via an event-driven backtester. Event-driven systems are widely used in software engineering, commonly for handling graphical user interface GUI input within window-based operating systems. They are also ideal for algorithmic trading as the notion of real-time market orders or trade fills can be encapsulated as an event. Consider a situation where an automated trading strategy is connected to a real-time market feed and a broker these two may be one and the same.
New market information will be sent to the system, which triggers an event to generate a new trading signal and thus an execution event. These systems run in a continuous loop waiting to receive events and handle them appropriately.
It is possible to generate sub-components such as a historic data handler and brokerage simulator, which can mimic their live counterparts. This allows backtesting strategies in a manner extremely similar to that of live execution. The disadvantage of such systems lies in their complicated design when compared to a simpler research tool. Hence "time to market" is longer. They are more prone to bugs and require a good knowledge of programming and software development methodology.
In engineering terms latency is defined as the time interval between a simulation and a response. In quantitative trading it generally refers to the round-trip time delay between the generation of an execution signal and the receipt of the fill information from a broker that carries out the execution. Such latency is rarely an issue on low-frequency interday strategies.
The expected price movement during the latency period will not affect the strategy to any great extent. The same is not true of higher-frequency strategies where latency becomes extremely important.
The ultimate goal in HFT is to reduce latency as much as possible to reduce slippage. Decreasing latency involves minimising the "distance" between the algorithmic trading system and the ultimate exchange on which an order is being executed. This can involve shortening the geographic distance between systems, thereby reducing travel times along network cabling.
It can also involve reducing the processing carried out in networking hardware or choosing a brokerage with more sophisticated infrastructure. Many brokerages compete on latency to win business. Decreasing latency becomes exponentially more expensive as a function of "internet distance", which is defined as the network distance between two servers. Thus for a high-frequency trader a compromise must be reached between expenditure of latency-reduction and the gain from minimising slippage.
These issues will be discussed in the section on Colocation below. Some issues that drive language choice have already been outlined. Now we will consider the benefits and drawbacks of individual programming languages.
These are subjective terms and some will disagree depending upon their background. One of the most important aspects of programming a custom backtesting environment is that the programmer is familiar with the tools being used. For those that are new to the programming language landscape the following will clarify what tends to be utilised within algorithmic trading.
This means that they can be used without a corresponding integrated development environment IDE , are all cross-platform, have a wide range of libraries for nearly any imaginable task and allow rapid execution speed when correctly utilised.
It offers the most flexibility for managing memory and optimising execution speed. This flexibility comes at a price. Development time can take much longer than in other languages.
Despite these shortcomings it is pervasive in the financial industry. C and Java are similar since they both require all components to be objects with the exception of primitive data types such as floats and integers.
Garbage collection adds a performance overhead but leads to more rapid development. These languages are both good choices for developing a backtester as they have native GUI capabilities, numerical analysis libraries and fast execution speed. This is only if I felt that a Python event-driven system was bottlenecked, as the latter language would be my first choice for such a system. It has gained wide acceptance in the academic, engineering and financial sectors. It has many numerical libraries for scientific computation.
It boasts a rapid execution speed under the assumption that any algorithm being developed is subject to vectorisation or parallelisation. Despite these advantages it is expensive making it less appealing to retail traders on a budget. R is a dedicated statistics scripting environment. It is free, open-source, cross-platform and contains a wealth of freely-available statistical packages for carrying out extremely advanced analysis.
R is very widely used in academic statistics and the quantitative hedge fund industry. While it is possible to connect R to a brokerage is not well suited to the task and should be considered more of a research tool.
It also lacks execution speed unless operations are vectorised. It is free, open-source and cross-platform. However, it contains a library for carrying out nearly any task imaginable, from scientific computation through to low-level web server design. In particular it contains NumPy, SciPy, pandas, matplotlib and scikit-learn, which provide a robust numerical research environment that when vectorised is comparable to compiled language execution speed.
Python also possesses libraries for connecting to brokerages. This makes it a "one-stop shop" for creating an event-driven backtesting and live execution environment without having to step into other, more complex, languages. Execution speed is more than sufficient for intraday traders trading on the time scale of minutes and above.
For these reasons we make extensive use of Python within QuantStart articles. The term IDE has multiple meanings within algorithmic trading. Software developers use it to mean a GUI that allows programming with syntax highlighting, file browsing, debugging and code execution features. While some quant traders may consider Excel to be inappropriate for trading, I have found it to be extremely useful for "sanity checking" of results.
Brokerages such as Interactive Brokers also allow DDE plugins that allow Excel to receive real-time market data and execute trading orders. Despite the ease of use Excel is extremely slow for any reasonable scale of data or level of numerical computation.
I only use it to error-check when developing against other strategies. In particular it is extremely handy for checking whether a strategy is subject to look-ahead bias. This is straightforward to detect in Excel due to the spreadsheet nature of the software. If you are uncomfortable with programming languages and are carrying out an interday strategy then Excel may be a good choice. The market for retail charting, "technical analysis" and backtesting software is extremely competitive.
Features offered by such software include real-time charting of prices, a wealth of technical indicators, customised backtesting langauges and automated execution. Some vendors provide an all-in-one solution, such as TradeStation.
TradeStation are an online brokerage who produce trading software also known as TradeStation that provides electronic order execution across multiple asset classes. I am currently unaware of a direct API for automated execution. Instead orders must be placed through the GUI software.More...