The Gateway to Algorithmic and Automated Trading

Dequantification: Optimal Balance Pairs

Published in Automated Trader Magazine Issue 27 Q4 2012

A common problem encountered by Automated Trader readers who use strategies such as pairs trading is determining the optimal ratio of securities to buy/sell when executing a trade. Automated Trader talks to Agnes Tourin of the Department of Finance and Risk Engineering at the Polytechnic Institute of NYU about how the stochastic control approach proposed in a recent paper1 she co-authored may offer a possible solution.

Agnes Tourin

Automated Trader: Why did you decide to explore this approach to modelling the relative dollar amounts to apply in pairs trading?

Agnes Tourin: I've been working in the area of stochastic control for some 15 years. Originally the applications I worked on were fairly academic, so not necessarily particularly relevant for the trading industry. The idea in the paper originally came from my co-author Raphael Yan, who is in charge of risk management in an internal hedge fund at Blackrock, although this question was not directly linked to his work there. I helped him formulate the model, compute the solution and illustrate with the example. Raphael was previously a PhD student of mine at McMaster University in Canada and he had been thinking for a while about using stochastic control for computing optimal trading strategies.

Automated Trader: Stochastic control techniques don't seem to have seen much use in the finance industry. Why is that?

Agnes Tourin: It is probably not regarded as a 'new' field, as the techniques have been developed progressively over many years. The concepts are demanding to grasp and require an extensive training at the PhD level for several years, plus years of experience gained from doing research.

Finally, stochastic control techniques have obvious limitations in the sense that the problems are still very hard to solve in most cases.

Automated Trader: In which case, why choose to use them for the problem of determining the optimal dollar ratio of securities in a pairs trade?

Agnes Tourin: Stochastic control techniques are good for computing optimal decisions under uncertainty, a situation that clearly applies to the problem of determining the relative quantities of the two instruments to buy/sell.

Another advantage to stochastic control is that it is dynamic in time, so you can adapt your strategies as you receive more information on the asset price, volume, volatility etc. The time series to which you are applying the technique needs to exhibit the Markov property ('memorylessness'2) for this approach to work, but fortunately this is true at least some of the time in the case of many financial time series.

Finally - as was the case in the example we developed for the paper - the problem may have a closed form solution3, which massively reduces the computation and complexity involved.

nyu poly

Tough Trade Off

As the use of statistical arbitrage (and especially pairs trading) has become more commonplace, making a profit has become increasingly difficult. Increasing competition squeezes available opportunity - a problem that has been further compounded in the case of pairs trading in stocks by thin liquidity. Determining the optimal relative quantities to buy/sell is no longer something that can be solved with trivial techniques. Most Automated Trader readers we talk to who are active in pairs trading have long since discarded linear regression as a tool for this, and are instead using techniques ranging from Kalman filters to artificial intelligence.

A further issue is that the buy/sell ratio is seldom static - what is optimal when the trade is opened may well not be shortly thereafter - and the volatility of this 'optimality' appears to be increasing in many instruments. This then raises the trade-off decision between the benefits of rebalancing versus the associated execution costs. Therefore any technique that successfully strikes a balance between optimal initial ratio and the subsequent stability of that ratio is of interest.

Historically, this problem has been couched in approximately equal dollar value terms - if $50K of stock Y is being bought, approximately $50K of stock X is sold short. However, this obviously does not take into account considerations such as the relative volatility of the two stocks - an active point of research for several Automated Trader readers we have spoken to over the past year - and also something that Dr Tourin and Dr Yan's paper considers.

On that point, it is striking how radically different the two optimal dollar values per leg in the example in the paper are from the conventional assumption of equal dollar value. At the start of the trading session, the optimal long position value in GS is approximately $1380, but the corresponding short position value in JPM is approximately $4650. Another interesting characteristic is the stability of the ratio between these values (for much of the first half of the trading session in the example it drifts very slightly either side of 3.375), which from a practical perspective would be valuable in terms of minimising frictional costs.

Automated Trader: Will a closed form solution necessarily always be available for a pairs trading problem of this nature?

Agnes Tourin: One cannot say that for certain. However, a closed-form solution may or may not be available, depending upon the particular structure of the stochastic control problem.

Automated Trader: You make it very clear in the paper that your testing was by no means exhaustive, but assuming further testing validates the approach, is there any reason why it could not be commercialised as an off the shelf software product?

Agnes Tourin: The basic techniques of stochastic control are well known but they have to be adapted to each specific problem and that is what takes the work, so it cannot just be completely automated. However, while it would involve considerable effort, there is no technical reason why it could not be potentially commercialised by streamlining its application to practical trading problems, for those who did not wish to learn the underlying techniques from scratch.

It is also important to note that the computing demands of this technique can be enormous. However, although it will depend on the specific problem under consideration, it may be possible in some cases to parallelise the problem so that the calculations could be expedited by using something like GPU technology.

Automated Trader: In the paper, your example uses one minute price bars, but did you test other time frames as well?

Agnes Tourin: We did also look at daily data, but because our testing wasn't exhaustive, we didn't discover an optimum timeframe. We tested once for cointegration right at the beginning of the test period (one day's worth of one minute data from October 17, 2011) to determine whether the two stocks concerned (GS and JPM) were cointegrated.4

The test was immediately profitable, with P&L peaking some twenty minutes after the trading session opened and forming a second slightly lower peak about three hours after the session opened.

Apart from these two peaks, the P&L meandered to and fro in profitable territory during the trading session and also closed profitably (we didn't use any form of intraday exit signal). We were also able to estimate the maximal time horizon for which our solution would be valid, which was 38 seconds.

Even though that is obviously a shorter period than just a single time step in the intraday time series being considered, it was interesting that the solution remained profitable throughout the day (albeit this was only a single pair modelled during a single trading session).

Automated Trader: Does the stochastic control approach require certain conditions, such as Gaussian distribution?

Agnes Tourin: There are a few things of which to be aware. Distributions do not have to be strictly Gaussian; the approach can accommodate non-classical Gaussian distribution. However, if you stray too far from that you may not be able to compute a closed form solution, which was obviously a major advantage in this particular case. The stochastic control approach can also accommodate jumps, which is useful in financial markets where one can have major instrument-specific events.

Automated Trader: So how widely applicable could stochastic control be in financial markets?

Agnes Tourin: One issue is that it becomes problematic to use as the number of variables increases. If you go beyond three variables, then you start to have major problems in terms of computational load, unless there is a closed form solution. In the case of estimating the optimal ratio between two securities in a pairs trade it wasn't an issue, as the variables concerned were just the two stock prices - so for that type of problem it should be appropriate; although in our particular example, this didn't matter as there was a closed form solution.

Automated Trader: Agnes, thank you for your time.

Stochastic Control

The early development of control theory was primarily concerned with the analysis of control systems for industrial and electronic processes, but over time it has been found applicable to numerous other areas as well. One branch that evolved shortly after WW2 to deal with complex problems with very demanding performance requirements was deterministic control theory. However, one limitation of this approach with regard to problems such as those commonly found in financial markets is that no realistic models for disturbances are used. In an environment such as a financial market where it is not possible to predict precisely the future value of a disturbance (such as a major volatility spike), this is obviously unrealistic.

One way of dealing with this limitation of deterministic control theory is to model disturbances by describing them as stochastic processes (in this case a sequence of random variables). By doing so, it becomes possible to design an optimal controller for a data set that incorporates a stochastic process. In the case of the problem examined here, the controller determines the optimal amount of each stock to

Tools for stochastic control are available and one such is the scsolve function in the CompEcon MATLAB toolbox, which also includes a number of demonstration scripts and can be downloaded free from:


2. Meaning that the future only depends upon the present, not the entire past.

3. "An equation is said to be a closed-form solution if it solves a given problem in terms of functions and mathematical operations from a given generally accepted set. For example, an infinite sum would generally not be considered closed-form. However, the choice of what to call closed-form and what not is rather arbitrary since a new "closed-form" function could simply be defined in terms of the infinite sum." (

4. Engle-Granger, Dickey-Fuller and Phillips-Ouliaris tests used.