AlgoTrading Review

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

review articles

doi:10.1145/ 2500117

The competitive nature of AT, the scarcity


of expertise, and the vast profits potential,
makes for a secretive community where
implementation details are difficult to find.
By Philip Treleaven, Michal Galas, and Vidhi Lalchand

Algorithmic
Trading
Review
growing rapidly across
Al gor ith m ic t rad i ng 1,9,13,14 i s
all types of financial instruments, accounting for
over 73% of U.S. equity volumes in 2011 (Reuters and
Bloomberg). This has been a fascinating research
area at University College London, where for eight
years algorithmic trading systems and an Algorithmic
Trading/Risk platform7 have been developed with Stock market data, as visualized by artist
Marius Watz, using a program he created to
leading investment banks/funds. represent the fast-paced “flows” of data as
virtual landscapes.
To tell this story, first we must clarify a number of
closely related computational trading terms that are key insights
Stockspace ( 200 9) , M arius Watz. Cu stom so f t wa re a rt based on
stock ma rket data. Commissioned by Knigh t Ca pita l Group.

often used interchangeably:  A lgorithmic Trading (AT) refers to any


form of trading using sophisticated
• Algorithmic trading (AT) refers to any form of algorithms (programmed systems) to
automate all or some part of the trade
trading using sophisticated algorithms (programmed cycle. AT is data-driven and usually
involves learning, dynamic planning,
systems) to automate all or some part of the trade reasoning, and decision taking.
cycle. AT usually involves learning, dynamic planning,  T he key stages in AT are the pre-trade
anaylsis, signal generation, trade
reasoning, and decision taking. execution, post-trade analysis, risk

• Systematic trading refers to any trading strategy management, and asset allocation.
 D evelopers use various types of
that is a “rule-based” systematic/repetitive approach simulations, including backtests and
optimizations, to evaluate and improve
to execution trading behaviors. This is often achieved utility of their algorithms.

76 comm unicatio ns o f the ac m | nov em ber 201 3 | vo l . 5 6 | n o. 1 1


through utilization of an expert system AT presents huge research chal- variables; often a minor change to a
that replicates previously captured ac- lenges, especially given the economic variable can have a catastrophic im-
tions of real traders. consequences of getting it wrong, such pact on performance.
˲˲ High-frequency trading (HFT) is as the May 6, 2010 Flash Crash11,18 in ˲˲ Algorithms’ interaction: Very lit-
a more specific area, where the execu- which the Dow Jones Industrial Aver- tle is known about the interaction of
tion of computerized trading strate- age plunged 9% wiping $600 billion off AT systems within a market (or even
gies is characterized by extremely short the market value and the Knight Capi- within a firm) leading for example to
position-holding periods in excess of a tal loss of $440 million on August 1, flash crashes.
few seconds or milliseconds. 2012, due to erratic behavior of its trad- ˲ ˲ High-performance computing:
˲˲ Ultra high-frequency trading or ing algorithms. Current research chal- Low-latency trading is a major driver
low-latency trading refers to HFT ex- lenges include: for performance, and also algorithm
ecution of trades in sub-millisecond ˲˲ Data challenges cover the quantity/ research in Graphics Processing
times through co-location of servers quality of the data, processing data at Units (GPUs) and Field-Programma-
and stripped down strategies, direct ultra-high frequency and increasingly ble Gate Arrays (FPGAs).2
market access, or individual data incorporating new types of data such
feeds offered by Exchanges and others as social media and news. Market Microstructure,
to minimize network and other types ˲˲ Algorithm behavior: An AT system Data, and Research
of latencies. may have a few or many hundreds of To understand AT, it is useful to under-

n ov e mb e r 2 0 1 3 | vo l. 56 | n o. 1 1 | c om m u n ic at ion s of t he acm 77
review articles

stand how a trade is executed by an Ex- types (market orders, limit orders, stop AT System Components
change, the different types of trading, orders, among others).9 In develop- The trading process (as illustrated by
and the objectives and challenges. ing an AT system, understanding the Figure 2) may be divided into five stages:
Trade execution: Dealers generally market microstructure—the detailed ˲˲ Data access/cleaning: Obtaining
execute their orders through a shared process that governs how trades occur and cleaning (financial, economic, so-
centralized order book that lists the and orders interact in a specific mar- cial) data that will drive AT.
buy and sell orders for a specific secu- ket—is of paramount importance. ˲˲ Pre-trade analysis: Analyzes prop-
rity ranked by price and order arrival The “ideal” AT prerequisites in- erties of assets to identify trading op-
time (generally on a first-in-first-out clude: portunities using market data or finan-
basis). This centralized order-driv- ˲˲ Centralized order book: Shared cial news (data analysis).
en trading system continuously at- centralized order book, listing the buy ˲˲ Trading signal generation: Identi-
tempts to match buy and sell orders. and sell orders. fies the portfolio of assets to be accu-
As shown in Figure 1, the order book ˲˲ Liquid markets: A highly liquid mulated based on the pre-trade analy-
is divided into two parts: buy orders market and typically one suitable for sis (what and when to trade).
on the left ranked highest price at high-frequency trading of securities ˲˲ Trade execution: Executing orders
top and sell orders with lowest price (for example, equities, FX). for the selected asset (how to trade).
at top. Orders are generally listed by ˲˲ Order book depth provides an in- ˲˲ Post-trade analysis: Analyzes the
price and time priority, which means dication of the liquidity and depth (the results of the trading activity, such as
most Exchanges prioritize orders number of buy and sell orders at each the difference between the price when
based on the best price and first-in- price) for that security or currency. a buy/sell decision was made and the
first-out framework. ˲˲ Financial information protocols final execution price (trade analysis).
There are many variants to the order (for example, the Financial Information Although we might think of AT as au-
book model described here. Different eXchange protocol, or FIX) for the com- tomating all stages, much of the activ-
Exchanges will accept different order puter communication of information. ity in the industry is devoted to the data
access/cleaning and pre-trade analysis
Figure 1. Trade order book. stages, with the latter stages of the trad-
ing process being supervised by humans.
Figure 2 illustrates the major
Order Book – ABC Inc. Order Book – ABC Inc.
components of each stage of an AT
Buy Sell Buy Sell system. The pre-trade analysis com-
Quantity Price Price Quantity Quantity Price Price Quantity prises computing analytical features
5,000 99 99 4,000 1,000 99 100 10,000 through three main components: Al-
8,000 98 100 10,000 8,000 98 101 1,000 pha model, the mathematical model
10,000 97 101 1,000 10,000 97 103 15,000 designed to predict the future behav-
15,000 95 103 15,000 15,000 95 104 3,000 ior of the financial instruments that
(a) Before matching a trade (b) After matching a trade
the algorithmic system is intended to
trade; Risk model that evaluates the
levels of exposure/risk associated with
the financial instruments; and Trans-
Figure 2. Components of an AT system. action Cost model that calculates the
(potential) costs associated with trad-
ing the financial instruments.
Data
Research (Real-time/Historical; At the Trading Signal stage, the
Market/non-Market) Portfolio Construction model takes
as its inputs the results of the Alpha
Pre-trade Analysis
model, the Risk model, and the Trans-
Alpha Risk Transaction action Cost model and decides what
Model Model Cost Model
portfolio of financial instruments
should be owned and in what quanti-
ties, in the next time horizon.
Trading Signal
At the Trade Execution stage, af-
ter the trading signal has been gener-
Portfolio Construction Model
ated and the portfolio constructed,
Trade Execution the Execution model performs several
decisions with constraints on (actual)
Execution Model transaction costs and trading dura-
tion: the most general decision is the
Post-trade Analysis Trading Strategy followed by the Venue
and Order type, decisions handled by
smart order routing.

78 comm unicatio ns o f the ac m | nov em ber 201 3 | vo l . 5 6 | n o. 1 1


review articles

Finally, at the Post-trade analysis ˲˲ Fundamental analysis: Evaluates


stage, the results of the trading activi- variables that can affect a security’s
ty—for example, the difference between value, including macroeconomic fac-
the expected price and the final execu- tors (like the overall economy and
tion price and P&L—are evaluated.
Narang13 and other industry ex- Buying (raw industry conditions) and company-
specific factors (like financial reports
perts emphasize the importance of
the (quantity and frequency of) “clean”
and especially and management).
˲˲ Technical analysis: The approach
data available for analysis to the suc- cleaned) data is is mainly concerned with trend analy-
cess of the trading system. Data sourc-
es broadly comprise:
hugely expensive sis as well as identification and inter-
pretation of chart pattern formations
˲˲ Financial data: Price data on finan- and cleaning data (for example, head and shoulders) in
cial instruments from Exchanges and
electronic communication networks
is highly time price/volume. It summarizes trading
history of securities (for example, com-
(ECNs), and also financial information consuming, but pany stocks) by analyzing changes in
from services, such as Bloomberg and
Thomson Reuters. essential due to their price or traded volumes.
˲˲ Quantitative analysis: Applies wide
˲˲ Economic data: Fundamental eco- the sensitivity of range of computational metrics based
nomic data, such as the overall state
of the countries’ economies (for ex- trading algorithms. on statistics, physics, or machine
learning to capture, predict, and ex-
ample, unemployment figures), inter- ploit features of financial, economic,
est rates, gross domestic product, and and social data in trading.
national policy.
˲˲ Social/news data: Sentiment data Alpha Models
“scraped” from social media (Twitter, For the Alpha model, as illustrated by
Facebook), RSS feeds, and news ser- Figure 3, there are essentially two alter-
vices; subdivided into: native basic strategy approaches:
˲˲ Real time: Live data feeds from ˲˲ Theory-driven: The researcher/
Exchanges, ECNs, news services, or programmer chooses a hypothesis for
streamed social media. the way the securities are likely to be-
˲˲ Historic: Previously accumulated have and then uses modeling to con-
and stored financial, economic, and firm their hypothesis.
social/news data; ˲˲ Empirical: The researcher/program-
and into: mer uses an algorithm to data mine
˲˲ Raw data: Unprocessed computer and identify patterns in the underlying
data straight from source that may con- data, without any preconceived views
tain errors or may be unanalyzed. on the behavior of a security.
˲˲ Cleaned data: Correction or re- Constructing the Alpha model and
moval of erroneous (dirty) data, caused more specifically setting the variables
by contradictions, disparities, keying can be a highly complex task. Nu-
mistakes, missing bits, and so on. merous factors influence the actual
Analyzed data: Context-specific algorithm implementation: forecast
features of raw and cleaned data that goals, like direction, magnitude, du-
emphasize principal components of ration, probability); forecast time ho-
underlying data. These data sources, rizon, such as millisecond, day, week;
real time and historic, are the cor- the mix of instruments; the data avail-
nerstone of the research, design, and able; actual setting of the model’s
back testing of trading algorithms variables; and the frequency of run-
and drive the decision making of all ning the model.
AT system components. Buying (raw
and especially cleaned) data is hugely Risk Models
expensive and cleaning data is highly Risk models1,13 focus on the risks asso-
time consuming, but essential due to ciated with a target portfolio of finan-
the sensitivity of trading algorithms. cial instruments and the relevant fac-
Pre-trade analysis, specifically the tors that affect the economic climate
Alpha model, analyzes (for example, and hence the current/future value of
data mines) real-time and historic the financial instruments. It does so by
data to identify potential trade op- attempting to quantify both the risk as-
portunities. The three principal tech- sociated with individual instruments
niques are: and with the portfolio. Figure 4 illus-

n ov e mb e r 2 0 1 3 | vo l. 56 | n o. 1 1 | c om m u n ic at ion s of t he acm 79
review articles

Figure 3. Alpha models—predicting the future. trates the two principal approaches to
risk that we refer to as:
˲˲ Limiting amount of risk: Limiting
Alpha Model the size of risk is managing the expo-
sure through limiting by penalty or
Quant Style constraint, such as leverage; or calcu-
Theory-driven Empirical Data-driven lating volatility and dispersion; and
(hypothesizing market behavior) (data mining market behavior)
˲˲ Limiting type of risk: Eliminating
Input
whole types of exposure. As with oth-
Price-data Fundamental Sentiment Real-time Historical er models, the approaches subdivide
broadly into Theory-driven and Empiri-
Approach cal using historical data.
In limiting these two, we take care of
Momentum Mean Reversion Yield Growth Quality Market Data Non-market Data optimizing the risk-reward ratio.

Strategy Transaction Cost Models


Stat Arb Lastly, the Transaction Cost model
calculates all possible transaction
costs, providing the Portfolio Con-
struction model with the ability to
estimate the theoretical spectrum of
Figure 4. Risk models—sizing of exposures. transaction costs associated with the
trading options when constructing
the portfolio. These include commis-
Risk Model sions, slippage and market impact,
and so on.
At the Trading Signal Generation,
Limiting Amount of Risk
(Exposure) the Portfolio Construction model takes
as inputs the results of the Alpha mod-
Size Limits Measuring Risk
el, Risk model and Transaction Cost
(constraints, penalty) (standard deviation) model and optimally selects the “best”
portfolio of financial instruments to
hold to maximize potential profits,
Volatility Dispersion
while limiting risk and minimizing
trading costs.
VaR
Portfolio Construction Models
Limiting Type of Risk
() Portfolio Construction models, as il-
lustrated in Figure 5, broadly subdivide
Theory-driven Empirical into:
(systematic risk) (using historical data)
˲˲ Rule-based models are heuristic
specifications defined by the Quant
concerning how to assemble the port-
Regime Change Risk Exogenous Shock Risk Endogenous Risk
folio of instruments. For Rule-based
models there are essentially four class-
es of models.13 For example, with Equal

Figure 5. Portfolio construction models—assembling portfolio.

Portfolio Construction Model

Rule-based Models Optimization Models

Equal Position Equal Risk Alpha-driven Decision-tree Unconstrained Constrained Black-Litterman …


Weighting Rating Weighting Weighting Optimization Optimization Optimization

80 comm unicatio ns o f the ac m | nov em ber 201 3 | vo l . 5 6 | n o. 1 1


review articles

Position Weighting all chosen instru- will be followed by additional gains and beta of a stock or portfolio is a number
ments are given equal weighting. vice versa for declining values. describing the correlation of its returns
˲˲ Optimization models use algo- ˲˲ Mean Reversion: A trading strat- with those of the financial market as a
rithms with an objective function that egy assuming prices and returns even- whole.) ‘Long’ and ‘short’ positions are
iterates to a portfolio that gives, for ex- tually move back toward the mean or also managed to eliminate net expo-
ample the highest rate of return. Exam- average. A popular strategy is mean sure through diversification.3,16
ples include the Black-Litterman—a so- reversion (pairs trading) where two his- ˲˲ Statistical arbitrage (“stat arb”)
phisticated optimizer popular with AT.13 torically correlated securities that have is an equity trading strategy that em-
The trade execution stage decides diverged are assumed to converge in ploys time series methods to identify
where, what, and when to trade, requir- the future. relative mispricings between stocks.
ing several decisions with constraints To illustrate trading strategies, we One popular technique is pairs trad-
on (actual) transaction costs and trad- discuss so-called market-neutral and ing; pairs of stocks whose prices tend
ing duration. risk-neutral AT,13,16 defined as: to move together; that is they are iden-
˲˲ Market-neutral strategies are trad- tified as correlated.5,12
Execution Models ing strategies, widely used by hedge The purpose of market-neutrality
The execution model (Figure 6) decides: funds or proprietary traders that go of a portfolio is hedging away risk, cre-
˲˲ Trading venue selects the Exchang- “long” on certain instruments while ated by large collective movements
es where the orders are to be placed, “shorting” others in such a way that the of the market. The idea is that such a
with many securities being potentially portfolio has no net exposure to broad portfolio should not be affected by any
tradable on multiple Exchanges. market moves. The goal is to profit type of such price movement, neither
˲˲ Execution strategies cover sched- from relative mispricings between re- up nor down. To achieve such neutral-
uling of trades, such as the popular Vol- lated instruments. ity, one must simultaneously manage
ume Weighted Average Price (VWAP) ˲˲ Risk-neutral strategies are trading (buying) long and (selling) short posi-
that executes a buy order in a financial strategies insensitive to risk, meaning tions in the market.
instrument (for example, stock), as a strategy, which is indifferent to the
close as possible to its historical trad- risk involved in an investment and is Algorithm System Architecture
ing volume. only concerned about expected return. We now look at the trend following or
˲˲ Order type subdivides in market This strategy type is used by market momentum strategy in more detail us-
orders, where a buy or sell order is to makers concerned more with continu- ing Equities as an example.
be executed by the system immediately ous financial flow rather than risk aver- Momentum strategy. A typical mo-
at current market prices; and limit or- sion/seeking. mentum trading strategy for stocks
ders, where an order to buy a security is For example, in equity markets, aims at capturing trends in stock pric-
specified at no more (or sell at no less) market-neutral strategies take two es. It uses the contention that stocks
than a specific price. forms. with an upward momentum will con-
Finally, post-trade analysis com- ˲˲ Equity market-neutral emphasizes tinue rising and should be bought and
pares the expected and actual per- fundamental stock picking, where a stocks with downward momentum will
formance of the executed trades. portfolio of ‘long’ and ‘short’ positions continue falling and should be sold.
This involves cost measurement and is maintained to be beta neutral. (The We use the nomenclature of “winners”
performance measurement. For ex-
ample, cost can be measured between Figure 6. Execution models—venue, strategy, order type.
the actual realized execution price
achieved and the so-called bench- Execution Model
mark price.

AT Strategies Trading Venue

When we use the term an “algorith- NYSE LSE NASDAQ CME LME
mic trading strategy” we are typically
referring to the precise nature of
the entire spectrum of activities em- Execution Strategies
ployed by a software system starting
from pre-trade analysis, model selec- Aggressive/Passive Large/Small Order Scheduling Routing

tion, signal generation, trade execu-


tion, and post-trade handling. Two Order Type
common strategies are detailed in
Market Limit
Dunis et al.4 and Kaufman:10
˲˲ Momentum: A trend following
trading strategy that aims to capitalize
Time in force Conditional Discretionary
on the continuance of existing trends (day, GTC) Orders Orders
in the market. The algorithm assumes
large increases in the price of a security

n ov e mb e r 2 0 1 3 | vo l. 56 | n o. 1 1 | c om m u n ic at ion s of t he acm 81
review articles

Figure 7. Download Yahoo! finance data in Python. incurred consecutive losses or the to-
tal unrealized loss exceeds a predeter-
mined value (another parameter).
-> import ystockquote
-> Input ticker Real-time strategy implementation
-> Input start date and optimization. The basic building
-> Input end date block of our implementation of the mo-
-> Store data in variable “data”
mentum strategy is the unit generating
specific realizations of the trading sce-
Actual Code Fragment from Python: nario for any particular set of control-
ling parameters. Its responsibility is
import ystockquote
to traverse all the concurrent strands
ticker = ‘GOOG’ of stock data day-by-day, calculate the
start = ‘20080520’ scores, grade the stocks, and carry out
end = ‘20080523’
the resulting trades. At the same time
data = ystockquote.get_historical_prices (ticker, start, end) it keeps track of its own stock holding
inventory and current cash balance. Its
output is the time development curve
of the total value of its holdings (stock
Figure 8. Alpha model pseudo code. and cash), for which the Sharpe Ratio
is then calculated. (The Sharpe Ratio is
a measure of the excess return (or risk
-> Choose a look0back period for a specific security [example: 1 hr, 30
mins, 10 mins, 1 min, 30 seconds]
premium) per unit of deviation in an
-> Access tick data for the look-back period investment asset or a trading strategy.)
-> Compute a simple moving average metric [SMA] The strategy runs, described here,
-> In order to calculate SMA we need to select
must be repeated for every combina-
1) Time-scale for historical data (e.g. 1 min)
2) Number of data points to be used in the SMA tion of parameters’ values (different
(e.g. 120 data points) scoring thresholds, investment hori-
-> SMA [60} = {current price + (price 1 min before) + zons) via exhaustive enumeration. Out
(price 2 mins before) + ..... (price 59 mins before)}/60
of this set of all possible realizations,
-> Repeat for all stocks [i.e. all 406 stocks in the S&P500] the optimal strategy, with best Sharpe
Ratio, is then selected.
-> We now have enough data to enter the signal generation stage of the
Alpha Model
Trading System Implementation
We now present a simple AT system
based on momentum, which is market
for the former and “losers” for the lat- we determine the amounts of each neutral and risk neutral, together with
ter. In our implementation of the mo- stock to hold. A simple portfolio con- pseudo-code fragments to illustrate
mentum strategy, we use the Simple struction rule is to invest equal dollar its implementation. We have removed
Moving Average for the last 60 minutes amounts in each stock that needs to be all possible extraneous details with
(SMA) metric to capture upward/down- traded since we do not know how each the goal of making the implementa-
ward trends. stock would perform. After we run the tion easy to understand. For a more
The strategies commence by con- strategy for at least a day, we can com- intricate discussion of momentum
ducting pre-trade analysis on stock pute stock-specific performance met- trading, read Wang and Kochard.17
price data of a specific granularity. rics to invest aggressively in specific Our simple implementation is
Pre-trade analysis usually entails com- stocks that performed well. based on the concept of price mo-
puting the value of one or more tech- Our Trade Execution model as- mentum; that is a tendency of rising
nical indicators. sumes there is a fixed strategy update stocks, the winners, to keep rising,
For the purpose of the strategy pre- cycle where the strategy does the pre- and falling stocks, the losers, to fall
sented here we have used a single tech- trade analysis for the look-back period, further. Momentum, as a property of
nical indicator SMA. The value of SMA scans for trading signals and places the Stock Market, is somewhat con-
is used for signal generation. trades and this sequence of actions is troversial, but its existence in stock
If the stock price for one of the repeated at regular intervals (the most returns has been confirmed by em-
shortlisted stocks exceeds the value of optimal frequency is chosen during pirical studies. The strategy discussed
the SMA, the system generates a buy optimization over multiple back-tests, here will consist of trading stocks
signal and vice versa. This stage is usu- as we will discuss later) Each trade from a broad fixed collection select-
ally called signal generation. During has an investment horizon—the maxi- ed to represent the S&P500 universe.
signal generation the stocks that need mum duration one can hold a position At any time we will hold a portfolio
to be traded get picked via the signals. (a parameter of the strategy) and we of long positions in top winners and
The next phase of the strategy con- may also temporarily withdraw from short positions in bottom losers8 se-
sists of Portfolio construction, where trading any stock whose number of lected from these stocks.

82 communicatio ns o f th e ac m | nov em ber 201 3 | vo l . 5 6 | n o. 1 1


review articles

It is important to note the descrip- Figure 9. Risk model pseudo code.


tion of the strategy does not assume
any particular frequency. Essentially -> Compute Historical VAR per security (10%, 1 –day VAR)
this strategy can be applied at differ- -> Collect price data for the security for the
ent frequencies (a parameter chosen past 500 days Pre-trade:
-> You have 500 data points Selecting
by the trader and typically optimized -> Look at the 50th worst outcome entrants to
during multiple back-testing runs, as -> This is the 10% 1 day VAR for the security the portfolio
we will discuss later). -> If Current Price of Security < Historical VAR
Financial data. The first step toward -> Do not include in portfolio Risk signaling
building an AT system is building an -> Else
-> Include in portfolio
infrastructure to handle huge amounts -> Compute portfolio VAR
of real-time data, and the accumulation -> Historical VAR (10%, 1 day-VAR)
of historical data of specific granularity -> Steps:
1) Go back 500 days
to compute the values of fundamen- 2) Re-value the portfolio on market prices
tal, technical, and quantitative met- on the past 500 days
rics that fuels the pre-trade analysis. 3) You now have 500 data points for the last
Figure 7 provides Python pseudo-code 500 days which indicate how the portfolio
must have behaved on the last 500 days
for data access from sources, such as 4) For 10% VAR 0.1*500 = 50th worst value is
Yahoo! Finance, using ystockquote, to the 10%, 1-day VAR
import Google ticker data. -> Monitor portfolio for risk violations
-> If Portfolio value < VAR Risk signaling
As discussed, the strength of the -> Close all positions in portfolio Risk Feedback
pre-trade analysis is partially reliant on to execution
the quality and granularity of data be- -> Suspend Algorithm until manual intervention
ing pushed into the system. Granular-
ity specifies whether the data is tick, or
one-minute candle, three-minute can- Figure 10. Trade signal generation stage—Alpha model.
dle, five-minute candle, daily candle,
and so on. A candle specifies the high- -> Carefully monitor the value of SMA [60] for each security {1, 2, 3…..n}
est, lowest, open, and close price in the where n = 406
period specified. -> For: each security {1, 2, 3.....n} where n = 406
-> If SMA [60] score < current price [classify security
Pre-trade analysis. Having gathered for bullish divergence – “Winner”]
and cleaned the data, the two compo- -> Flag buy signal
nents of the pre-trade analysis stage -> If SMA [60] score > current price [classify security
for bearish divergence – “Loser”]
discussed here are the Alpha model
-> Flag sell signal
and the Risk model. We start with the
pseudo-code for the Alpha model stage
(Figure 8) for the S&P500.
Figure 11. Trade execution.
During pre-trade analysis, the trad-
ing system digests the data input and
-> Upon Buy signal for a security
computes statistical metrics that indi- -> Place market buy order for security [such that (quantity*price)
cate or highlight different features in = dollar allocation for security] Apply same logic to all 406 stocks
the data. For equities these features -> Upon Sell signal for a security
could be volatility, trend, co-integra- -> Place market sell order for security [such that (quantity*price)
= dollar allocation for security]
tion, mean-reversion. The “indicative- -> Upon forming a portfolio of greater than 1 stock
ness” of the metrics is crucial to the -> Compute portfolio beta [the degree of sensitivity of the portfolio
success of any trading strategy. Stan- value to movements in the market index]
-> If beta > 0 [this means positive exposure w.r.t the index]
dard metrics include: simple moving -> Short/Sell the right amount of the S&P 500 index [this will
averages or proprietary metrics. generate a negative beta which will cancel
Risk Model (Pre-trade and Signal your portfolio’s positive bet [Hedging: Market neutrality]
generation). Next the Risk model code -> If beta < 0 [this means negative exposure w.r.t the index]
-> Buy/Long the right amount of the S&P500 index [this will
(illustrated in Figure 9) calculates the generate a positive beta which will cancel
risk metrics for the various instru- your portfolio’s negative beta]
ments that are candidates for the port- -> For: Each security {1, 2, 3….406} -Track existing positions
periodically [example: every 15 mins]
folio to be calculated at the Trading -> If Profit threshold reached for a specific security
Signal generation stage. As shown by -> Liquidate profits & add to cash
the pseudo-code this uses a standard -> If Loss threshold reached for a specific security
VAR (Value at Risk) calculation. -> Close position, take in losses
-> If Investment Horizon reached
The risk model of the trading -> Close position irrespective of profits/loss
system periodically computes risk
metrics for each security and for the

n ov e mb e r 2 0 1 3 | vo l. 56 | n o. 1 1 | c om m u n ic at ion s of t he acm 83
review articles

portfolio of securities. If a VAR break trade analysis calculates Implementa-


occurs (a VAR break is when the port- tion Shortfall, P&L, among others.
folio value falls below the Value at Once the trades have been executed,
Risk threshold), a set of predefined the results need to be monitored and
rules kick in. In this pseudo-code, a
VAR break triggers the algorithm to While back-testing managed. The P&L generated from
the trades must be analyzed such that
close all positions, that is, liquidate
the portfolio and suspend its running
does not allow stocks that perform badly are allocated
less money in allocation than the ones
until again manually restarted. In a one to predict how that do well.
similar way, customized rules can be
predefined for each risk metric that
a strategy will Back-testing and Performance
states how the system must behave perform under Before implementation, the whole
in the event any of the risk metrics
breaching thresholds.
future conditions, algorithmic trading strategy is thor-
oughly back-tested.15 Back-testing is
At Trade Signal Generation (illus- its primary a specific type of historical testing
trated by the code in Figure 10) we use
the features computed in the pre-trade benefit lies in that determines the performance of
the strategy if it had actually been em-
analysis for the Alpha model and de- understanding ployed during past periods and market
fine a set of heuristic rules for signal
detection. A classic example is de- the vulnerabilities conditions. While back-testing does
not allow one to predict how a strategy
scribed here:
If the current price hovers above
of a strategy will perform under future conditions,
its primary benefit lies in understand-
the 60-minute SMA, it is expected to be through a simulated ing the vulnerabilities of a strategy
trending upward and vice versa. This
logic is implemented in the trade execu-
encounter with through a simulated encounter with re-
al-world conditions of the past. This en-
tion. real-world ables the designer of a strategy to “learn
Next we look at the Trade Execu-
tion stage. The Trade Execution code
conditions from history” without actually having to
make them with actual money.
(illustrated by Figure 11) typically de- of the past. The implementation of the AT system
cides the trading venue of the order to might be back-tested on daily price data
be issued based on an assessment of from the S&P500, taken from the dates
liquidity. However, here we stick to the of July 1, 2005 to July 1, 2011 (six years)
assumption of a single trading venue. from Yahoo! Finance. It is important
Once a buy signal is flagged by the sys- to note the granularity of the data the
tem, it reacts by placing a buy order strategy is back-tested and optimized
worth a certain amount of money on on determines the minimal frequency
the market. (For example: if we start level of the strategy. In this case, since
with 10 stocks and $1 million in cash the strategy is back-tested on daily data,
and equal allocation, a buy signal for it should have one run per day—a run re-
GOOG Google Inc. when the price is fers to calculation of pre-trade, scanning
591.93 would trigger a buy order for for signals, and placing trades.
168 stocks of GOOG amounting to On data cleaning: We have based
168*591.93 = $100,000). our trading portfolio case study on the
Market neutrality is maintained definition of the S&P500 from April
by beta-hedging (holding a portfolio 16, 2007. It is the last reasonably com-
such that beta is as close to zero as plete list we could find in the public
possible) by buying or selling appro- domain. (S&P forbids free circulation
priate amounts of the stock index to of the current list of the S&P500 com-
which the equities belong. In this case, ponents.) After removal from this list
since we have shortlisted equities from of all the stocks for which there are no
S&P500 index market neutrality is complete coverage of the entire six-year
maintained by going long or short the stretch of our experiment, we are left
S&P500 index. with 414 stocks. With regard to clean-
Post-trade analysis. As discussed, in ing, we found that for eight of these
trading the so-called Implementation stocks the price data contains abnor-
Shortfall is the difference between the mal daily returns, with absolute values
decision price and the final execution exceeding three. As realistic trading
price (including commissions, taxes, systems would have prevented these
among others) for a trade. This is also stocks from being traded during those
known as the “slippage.” The post- extreme price jumps, we have decided,

84 communicatio ns o f th e ac m | nov em ber 201 3 | vo l . 5 6 | n o. 1 1


review articles

for simplicity, to remove them entirely. Calculation of Sharpe Ratio financialcomputing.org). We thank
The remaining 406 stocks will form the If we denote by Rt the daily returns, Dan Brown and Jan Grochmalicki, and
initial contents of our trading portfolio. that is, the daily relative (%) changes students contributing to the AT and risk
It must be noted here that, as the of value of our total wealth (the sum platform, and the extensive research
composition of the S&P Index keeps of the trading account, the net value conducted with the banks and funds. We
changing, not all of the stocks we of the portfolio and the current value also thank Trading Technologies, Chi-
picked will necessarily still be part of of the SPX-hedge), then the associated X, and Knight (HotSpotFX) for granting
the Index at the end of our experiment. Sharpe Ratio (SR) is given as us access to their datafeed streams for
However, by insisting on the complete- research; Barclays, Citigroup, BNP Pa-
ness of the pricing information for all SR = mean(Rt) / std(Rt); ribas Fortis, and BAML for their advice
the stocks in our portfolio we ensure and support, Clive Hawkins (Barclays),
they were all actively traded through- where mean(Rt) and std(Rt) are respec- Nick Edwards (Trading Technologies),
out. As the adjustments of the Index tively the average and the standard de- Martin Frewer (BNP Paribas Fortis),
are impossible to monitor, we will ig- viation of the returns calculated over the Kevin Gillespie (HotSpotFX), and Piotr
nore them, as if the Index was frozen. entire training period of our strategy. Karasinski (EBRD).
Our initial trading account starts with As the mean value represents the gains
a unit of wealth, representing $1 million. and the standard deviation conveys the References
1. Chan, E.P. Quantitative Trading: How to Build Your Own
Back-testing. We can divide the back- risk, the maximum value of the Sharpe Algorithmic Trading Business. Wiley Trading, 2009.
testing simulation into two phases. The Ratio offers the best compromise be- 2. Che, S., Li, J., Sheaffer, J., Skadron, K. and Lach, J.
Accelerating compute-intensive applications with GPUs
first five years constitute the in-sample tween the performance and risk. and FPGAs. In Proceedings of the IEEE Symposium on
Application Specific Processors (June 2008).
period, when we train the algorithm, Back-testing results. The strategy 3. Chincarini, L. and Kim, D. Quantitative Equity Portfolio
in order to choose the parameters (for variation with the best Sharpe Ratio and Management: An Active Approach to Portfolio
Construction and Management. McGraw-Hill Library
example: the optimal look-back period, out of sample performance is chosen of Investment & Finance, 2006.
investment horizon, risk thresholds) to be implemented in real time. Back 4. Dunis, C. L., Laws J. and Naïm P. Applied Quantitative
Methods for Trading and Investment. Wiley Finance
giving the best P&L performance. Then, testing is a key step in any algorithmic Series, 2003.
the following year, the out-of-sample strategy construction as without back- 5. Ehrman, D.S. The Handbook of Pairs Trading:
Strategies Using Equities, Options, and Futures. Wiley
period, is the test run used to validate testing we would not know which com- Trading, 2006.
the selected parameters. bination of parameters gives the high- 6. Financial Information eXchange (FIX) Protocol;
http://en.wikipedia.org/wiki/Financial_Information_
In-sample training: Optimization. est profit for a given strategy. eXchange or http://fixprotocol.org/
During this phase, different variations 7. Galas, M., Brown, D. and Treleaven, P. A computational
social science environment for financial/economic
of the strategy are applied to past data. Conclusion experiments. In Proceedings of the Computational
Variations of a strategy can be defined As noted at the outset, the research chal- Social Science Society of the Americas (2012).
8. Jegadeesh, N. and Titman, S. Returns to buying
as the same underlying model with dif- lenges (and the consequences of getting winners and selling losers: Implications for stock
ferent time parameters for computa- it wrong) are still poorly understood. In- market efficiency. J. Finance 48, 1 (Mar. 1993), 65-91.
9. Johnson, B. Algorithmic trading & DMA: An
tion of pre-trade metrics. For example: deed, challenges persist and span data introduction to direct access trading strategies, 2010.
10. Kaufman, P.J. The New Trading Systems and Methods.
the look-back period for computing the handling—cleaning, stream process- Wiley Trading, 2005.
metrics could range from few seconds ing, storage, and using new types such 11. Lo, A. Finance is in need of a technological revolution.
Financial Times, Aug. 27, 2012.
to few hours. A variation can also mean as social data and news for forecasting; 12. Meucci, A. Review of Statistical Arbitrage,
applying the same model with different algorithm behavior—selecting the best Cointegration, and Multivariate Ornstein-Uhlenbeck.
SSRN preprint 1404905, 2010.
time frame for investment horizons of computational statistics and machine 13. Narang, R.K. Inside the Black Box: The Simple Truth
trades. For example: a strategy could learning algorithms, and setting their About Quantitative Trading. Wiley Finance, 2009.
14. Nuti, G., Mirghaemi, M., Treleaven, P. and Yingsaeree,
be tested where the maximum holding variables to optimize performance; al- C. Algorithmic trading. IEEE Computer 44, 11 (Nov.
time for positions is three minutes or gorithms’ interaction—understanding 2011), 61–69.
15. Pardo, R. The Evaluation and Optimization of Trading
30 minutes or an hour. After each varia- the interactions of AT systems within Strategies, Wiley Trading 2008.
tion is applied to past data, the P&L per- a firm and within a market; and high- 16. Stokes, E. Market Neutral Investing. Dearborn Trade
Publishing, 2004.
formance is recorded and the Sharpe performance computing—support of 17. Wang, P. and Kochard, L. Using a Z-score Approach
ratios computed. The strategy variation low-latency trading and the use of novel to Combine Value and Momentum in Tactical Asset
Allocation. SSRN preprint 1726443, 2011.
with the best P&L performance and hardware such as GPUs and FPGAs. 18. Zigrand, J.P., Cliff, D. and Hendershott, T. Financial
Sharpe Ratio is chosen to be applied to We hope this article serves to en- stability and computer based trading. The Future of
Computer Trading in Financial Markets, U.K. Gov., 2011.
the out-of-sample period. courage computer scientists to pursue
There are two adjustable parameters research in the AT area. Our goal was Philip Treleaven ([email protected]) is a professor
controlling the trading in this strategy: to provide a comprehensive presenta- of computer science and head of the U.K. Ph.D. Centre in
˲˲ Time-window used to calculate the Financial Computing at University College London, U.K.
tion of AT systems, including pseudo-
pre-trade metrics. code fragments, and as a case study, a Michal Galas is a Research Fellow and chief programmer
in the U.K. Ph.D. Centre in Financial Computing at
˲˲ Time-frame between portfolio ad- simple market-neutral trend following University College London, U.K.
justments-investment horizon. AT strategy. Vidhi Lalchand is a research student at University
Their optimal values are established College London, U.K.
by looking for the best in-sample strat- Acknowledgments
egy performance, as measured by the This article was produced by the U.K. Copyright held by Owner/Author(s). Publication rights
Sharpe ratio. Centre for Financial Computing (www. licensed to ACM. $15.00

n ov e mb e r 2 0 1 3 | vo l. 56 | n o. 1 1 | c om m u n ic at ion s of t he acm 85

You might also like