Вы находитесь на странице: 1из 26

This Project is submitted as part of the requirements for the award of the

MSc in Mathematical Trading and Finance.

Dissertation Topic

High Frequency Pairs trading with real transaction costs, bid-ask spread and speed of
execution

Ajay Kumar Kakarania

Supervisor: Gianluca Fusai,PhD

MSc. Mathematical Trading and Finance

CASS Business School

Aug 20,2013

Keywords: Beta, Cointegration, High-frequency data, Pairs trading, Residual


modelling, Spread, Statistical arbitrage, Threshold modelling, Time adaptive models

Abstract

The aim of this research paper is to suggest .


Contents
Abbreviation............................................................................................................... 4
1. Executive Summary............................................................................................. 4
2. Introduction.......................................................................................................... 4
1.1 Definition....................................................................................................... 4
1.2 Motivation for this research...........................................................................5
3. Literature Review................................................................................................. 6
2.1 Pairs Trading...................................................................................................... 6
2.2 Data-Snooping and Relative Pricing..................................................................7
2.3 Pairs trading and high frequency data...............................................................7
2.4 Engle-Granger test for Co-integration Analysis and Granger Causality.............9
4. Methods and Methodology................................................................................... 9
3.1 Nifty 50 Index and Financial Data....................................................................10
3.1.1 Data Cleansing and Grouping....................................................................10
........................................................................................................................... 11
........................................................................................................................... 11
........................................................................................................................... 11
........................................................................................................................... 11
........................................................................................................................... 11
........................................................................................................................... 11
* Our Research Proprietary model......................................................................11
3.2.1 Co-integration Modeling............................................................................ 12
3.2.2 Beta Modeling........................................................................................... 13
3.2.3 Volatility Modeling..................................................................................... 14
3.2.5 Residual Modeling..................................................................................... 15
3.2.5 Technical Indicators ( Bollinger Bands/Rising Curve Flag).........................16
3.2.6 Half-Life calculation................................................................................... 17
3.3 Trade signal generation................................................................................... 17
3.4 Trade execution............................................................................................... 18
3.5 Pairs selection upon statistical arbitrage.........................................................19
4. Research outcome............................................................................................. 21
Conclusion and outlook......................................................................................... 21
Appendix............................................................................................................... 22
Bibliography.......................................................................................................... 22
Abbreviation

a.k.a: Also Known As

EOD: End of the Day

NSE: National Stock Exchange

HFT High Frequency Trading

Market Neutral : Position(Portfolio) independent of market direction

USP : Unique Selling Point

EM : Expectationmaximization

DESP : Double Exponential Smoothing Prediction

OLS: Ordinary Least Square

ADF: AUGMENTED DICKEY FULLER TEST

KF/EKF : Kalman Filter/ Extended Kalman Filter

1. Executive Summary

2. Introduction
In our research, we have explored and attempted to enhance some of the existing methodologies for high
frequency pairs trading strategy on emerging economy, India by selecting all the constituents stocks of the
index NIFTY 50, the most liquid index.

The research is segregated in four chapters. The first chapter is introductory and cites the key motivation
and objective for this research. The second chapter critically reviews some of the existing literature. The
third and a crucial chapter, details all the methods and models used in the research. The final two chapter
summarizes the research outcomes and concludes about the overall strategy with future scope of work.
1.1 Definition

As Megginson (1963) states

According to Darwins Origin of Species, it is not the most intellectual of the species that
survives; it is not the strongest that survives; but the species that survives is the one that is able
best to adapt and adjust to the changing environment in which it finds itself.

This analogy fits quite well to the world of trading and pairs trading is one such strategy which attempted
to adopt to changing world of quantitative and algorithmic trading.

Pairs trading a.k.a mean reversion in market neutral setting was the brainchild of some of the quant
experts in Morgan Stanley in the early 1980s (Gatev et al. (2006). Their idea was simple, finding the
absolute value of any stocks might be challenging since it needs to factor various micro and
macroeconomics factors however relative pricing of two stocks which exhibit certain relationship between
them is comparatively straightforward. This relative pricing is the essential idea behind pairs trading.

Starting with the simple concept of correlation, this strategy has evolved significantly with various
econometrics modeling add-ons such as concept of cointegration, stochastic residual spread and
minimum distance measures. In our research, we have attempted to incorporate some of these strategies
coupled with our own ideas for threshold modeling and residual peak behavior modeling and applied to
high frequency real bid/ask data under real transaction cost (as applicable for retail traders) and execution
delays.

The general idea of pairs trading is certain underlings ( can be stocks, futures, options, ETF, etc.) which
exhibits a patterned relationship between them gives an opportunity to identify a relatively
undervalued(Buy this) and overvalued stock(sell this). The biggest challenge is to identify this pattern
using historical behavior and leverage it to predict the future patterns for a certain period.

Technically speaking, when two co-integrated stocks diverge from their long term equilibrium
relationship(identified through econometrics models) then for statistical arbitrage trader, its an
opportunity to go long/short depending the degree of divergence and direction of the residual (the
difference between the two stocks).
Y t =t X t + t ;

Equation 1 Y t , X t are stock prices ; t=longrun equilibruim ; t=residual (spread )

For all statarb traders, the most important question is how to identify what is the right degree of
divergence of this spread to enter and exit the trade. The whole suites of sophisticated modeling tools are
just build primarily to provide this information.

1.2 Motivation for this research

We are motivated to conduct this research primarily for two reasons. Firstly, there isnt any research
available in the public domain on the impact of pairs trading on NSE market, India and secondly we believe
that our superior modeling technique can generate higher market adjusted returns. The adaptable
threshold modeling technique is the USP of our research.

In this research, identifying the best pairs among the 2450 possible pairs combinations was an
interesting and challenging task and holds the key to generate higher risk adjusted returns. The best pairs
were identified through a ranking system.

3. Literature Review

2.1 Pairs Trading

Some of the key research on pairs trading includes but not limited to, the work of Binh et al. (2006),
Bowen et al. (2010), Faff et al. (2010), Dunis et al. (2006), Gatev et al. (2006), Kukenheim (2011),
Vidyamurthy (2004). They all contributed to pairs trading from diverse perspectives and mostly with one
common conclusion, that the strategy still remains profitable for different markets and underlyings. It this
this notion that we examine critically in our research with real transaction scenarios with appropriate trade
slippages. On another note, much of the practitioners world of algorithm pairs trading continues to be
remain under proprietorship secrecy.

Faff et al. (2006) chose two years of weekly data for three stock pairs each one from US, UK and
Australia exchanges and developed a new stochastic residual spread method based on EM algorithm and
empirically showed evidence of mean reversion behavior in certain stock pairs. They compared and
contrasted their algorithm to statistical arbitrage concept.
Bowen et al. (2010) chose 60-minutes tick equities data from a set FTSE 100 constituents and measured
pairs performance under a variety of scenarios including but not limited to transaction costs, speed of
trade execution, risk factor correlation, intra-day liquidity changes. The paper concluded that transaction
cost( even a moderate 15bps per equity transaction) and speed of execution has significant impact on the
profitability of the strategy. Furthermore, the negative serial correlation in intraday stock returns
(Engle and Russell 2006) could wipe out the profits quickly. Finally, over 75% of the profits
were generated in the first and last hours of trading highlighting its positive correlation with
the typically observed opening and closing hours volatility (U-curve).

Gatev et al. (2006) carried out research on pairs trading in two different time-periods for the same
market(US), 1998 and 2006. They employed the same model for both era however only changed the
dataset for the 2006 period using the newly available data since 1998. A simple minimum squared
distance model was used to select stock pairs with the objective to keep data snooping in check, a
serious concern for sophisticated models. Gatev et al. (2006) annualized returns summarized below:

Table 1

Returns type/Annual FIVE TWENTY Period Transactio Frequency


Returns Best pairs Best pairs n cost

Only Investment 15.72% 17.28%


1962- Daily Data (with 12
Period
1997 Yes Months Training
Fully Committed 9.36% 9.92%
Period)
Capital

Gatev et al. (2006) further argued that if mean-reversion was the only key criteria for excess alpha than
any arbitrary chosen pair should also generate excess risk adjusted returns and as such performed
bootstrapping simulation on both the randomly chosen pairs and sector wise selected pairs and compared
their results. Interestingly, they concluded that systematically chosen pairs delivered higher returns
comparatively.

2.2 Data-Snooping and Relative Pricing

An White (2002) states,

Data snooping occurs when a given set of data is used more than once for purposes of inference
or model selection. When such data reuse occurs, there is always the possibility that any
satisfactory results obtained may simply be due to chance rather than to any merit inherent in the
method yielding the results.

This is one of the key issues which we have kept in check in our model by sampling the data at different
frequencies and apply modeling optimization and curve fitting on a randomly chosen pair. Thereafter this
optimized model is used for all the remaining selected pairs with different periods and frequencies. Also,
we have been very vigilant about ensuring there is no forward looking in the algorithm (a common mistake
by programmers).

(Ingersoll 1987, as cited by Gatev et al. (2006), p.800) defines the LOP as the proposition ... that two
investments with the same payoff in every state of nature must have the same current value. Under this
hypothesis, the concept of pairs trading idea incepted since this hypothesis is a good proxy to price
equilibrium between two similar stocks (i.e. which behaves similarly under different economic constraints).

2.3 Pairs trading and high frequency data

In todays era, algorithm trading commands a significant portion in the global trading portfolio as
researched by research firm Trading Screen (2010) which opinionated that every one in three buy-side
traders is now using algorithms to trade more than 40% of equities order flow with primary reason
highlighted as productivity and cost benefits.

Tabb group (2009) stated that just a mere 2% US prop trading firms among the 20,000 odd firms
averages over 60% of all the order volume across all major asset classes. CTFC (2012) report The
Future of Computer Trading in Financial Markets clearly cites that HFT is here to stay and grow.

In these lights, its seems imperative to conduct research on the performance of pairs trading on a high
frequency setting. Currently there are only a handful of papers available in the public domain linking high
frequency with pairs trading. Dunis et al. (2010) and Kukenheim (2011) did some extensive research on
pairs trading with HF setting and concluded with profitable returns, a conclusion which we critically
examine in our research under different scenarios.

Dunis et al. (2010) research was to identify the highest possible Information ratio with Eurostoxx 50
constituents stocks under different tick sizes, sampling from 5minutes to 60minutes data frequency for
the period from July to November 2009. They used simple Engle-Granger (EG) co-integration based

residual modeling
Y t =t X t + t for both in and out sample period.
They segregated the data into two equal halves for all sampling frequencies, with the first half used to
train the data and the second part for its application. Training the data constituted of finding the optimum
rolling window for beta through Kalman filtering, DESP and OLS method and finding the right z-entry and
exit points. And then used this optimized parameters in the second half of the data( i.e. out of sample
data) for performance monitoring however still re-calibrating the time adaptive beta for every rolling
window.

Additionally, they group all the possible pairs based on the industry standard classified by Bloomberg and
then selected the top five pairs from the EOD in-sample data each on the basis of highest Information
ratio, T-ADF stats and Half-life of mean-reversion.

Dunis et al. (2010) used EOD stock analysis to apply the same measurements on high frequency data.
Two key summary from there analysis were, firstly, degree of daily data co-integration is a good indicator
for the possible returns in the HF domain with in-sample Information Ratio pattern a good proxy for the out
of sample returns. Secondly, HF data indeed generates higher Information ratio(~3 on average) compared
to Daily sampling (~1 on average), both sampling data transaction cost adjusted(~15bps per trade).

Dunis et al. (2010) captured different statistics and found that 5-minutes frequency data delivered the
best annualized returns at 16%. Their thesis is of great significance to our research wherein the similar
framework is adopted for a different market with additional modeling techniques employed to explore
higher returns.

2.4 Engle-Granger test for Co-integration Analysis and Granger

Causality

(Engle & Granger 1987) pioneered the quantitative technique of finding a relative price relationship
between two stocks. They coined a simple yet powerful idea of cointegration wherein two stochastic stocks
under certain relationship might have stationary residual. To test this theory, regress the prices of Stock Y

on Stock X and test the residual (


t ) for a unit root using Philips test (Phillips 1998) or Augmented

Dickey-Fuller -stats(Dickey & Fuller 1979).

Y t =t X t + t

The null hypothesis postulates no co-integration against alternative hypothesis of co-integration. The
suitable t-ADF test distribution needs to be applied on the estimated residual to test for stationarity.
Another more comprehensive framework for multiple co-integrating vectors is based on Maximum
likelihood estimator (MLE) technique. It was developed by Johansen (1988) which overcame some of the
limitation of EG test (two step approach testing approach and limited size for the co-integration vectors).
This framework is not only more complex to implement but also challenging since a well-specified VAR
model is a pre-requisite to test for co-integration vector rank.

Any issues with the VAR for which number of lags of the residual is one of the key criteria, any variation in
lags, impacts the vector rankings. This framework is more suitable for identifying simultaneous
relationship between a basket of stocks.

Alexandar (2001) preferred EG test to Johansen framework because of its simplicity and adequancy for
financial applications. Also he cited that EG test employs criteria of minimum variance which is more
important than Johansen criteria of maximum stationarity.

Once the stocks are found to be co-integrated, its imperative to understand, which is more suitable
regressor and regressand. This issue was addressed by granger causality. According to Granger (1981), if
price movements of Stock Y causes prices of co-integrated Stock X then regressing Stock Y on Stock X
would lead to better empirical results than the other way around. This can be validated with the below
regression and testing for the significance level for F-test against the test.
This concept has been explained also been briefly explained in the notes of Bent Sorensen (2005).

4. Methods and Methodology


This chapter explains in details the methods adopted for the research. It starts with how the data for
different ticks where downloaded and validated. Next it details all the different models used for this
research followed by how these models assist to generate the appropriate trade signals. Followed by trade
signal, we focus on its relationship with trade execution(all orders are assumed market orders) in a
leveraged and non-leveraged settings. <<Matlab overview should I or no>>

3.1 Nifty 50 Index and Financial Data

In our research, we sourced data from Bloomberg for various tick frequency for the NSE Nifty 50 index
constituents stock (bid, ask & trades). The dividend adjusted data collected for tick sizes (Daily EOD data,
5-minutes,10-minutes, 20-minutes,30-minutes and 60-minutes).

3.1.1 Data Cleansing and Grouping


For all the tick sizes, if there was any stock with a missing tick data, then we ignored that whole tick for all
the stocks. This stock cleansing was rare however necessary to maintain consistency between the stocks
prices. Also we tallied the high frequency prices with EOD dividend adjusted prices to ensure that high
frequency data is indeed dividend adjusted for all ticks.

Also we carefully checked all the bid-ask prices for all the tick frequencies to ensure that the bid-ask
spread is sensible when compared to its equivalent trade ticks. Any erroneous* trades(rare phenomenon)
were eliminated from the research. Recent month of August 2013 witnessed high market volatility with
both high peaks and trough, so we opted to include this period in our analysis for better understanding of
the pairs trading behavior.

Data was grouped as per the GICS standard, represented with Bloomberg code GIC Industry Group
Name. The grouping was essential in order to limit the otherwise over 2500 possible pairs combinations
of stocks and also to minimize cross sector risk, see Dunis et al. (2010).

4 stocks were ignored from the analysis since they were the only representative from their sector. Since
the EOD data was collected from Jan 2003 so for companies which incepted after this period, their co-
integration ranking might have been impacted due to missing data for that period.

Table 2 Total tick sizes(top left). Exception Inception period (lower left). Sector-wise
classification and omitted stocks (top right)

3.2 Methodology

An overview of the entire modeling flow can be seen below. All boxes in light blue are models, Green are
reporting solutions and Orange are decision makers.

3.2.1 Co- Risk Management


integration
Modeling 3.2.5 Residual Modeling
3.2.3 Volatility
Modeling
3.2.2 Beta Modeling

P&L Reporting Trading Execution Trading Signal

Parameter tracker (
, , Returns, Tick delay 3.2.6 Technical

Threshold, signals,
3.2.6 Rising Curve
Sharpe, Trades counts, 3.2.7 Half Life

* Our Research Proprietary model 3.2.4 Threshold


3.2.1 Co-integration Modeling Modeling*

Our research is based on the statistical relationship indicated by co-integration measure between two
stocks. So, this section is the basic building block for further understanding of pairs trading.

Markets are stochastic so should be the equities prices which we confirm by running simple order of
integration test using ADF t-stats. Details below

Table 3 adf test

STAGE 1 Description Econometrics Key Equation


Summary Using ADF test, we checked the p =1
Rel t= + Relt 1+ Rel t j+ v t
residual for stationarity. j=0

ALL Prices were found I(1).


Significance Two prices with same order of Null hypothesis accepted. Prices are not I(0).
integration can be tested for p=1
Rel t = + Rel t1 + Rel t j+ v t
residual stationary i.e. I(0) to j=0

check for co-integration.


Null hypothesis rejected. Prices are I(1).
=constant ; =coefficient ; vt = noise ; Rel t =First diffe

AIC *: Akaike information criterion

Table 4 Engle and Granger co-integration


STAGE 2 Description Key Equation
Summary Most pairs from the same sector were found to ONGC t = t REL t + t
be co-integrated with EOD data.

Significance For co-integrated stocks, although individually the


Subject the residual for ADF -
stock may move randomly however together, they
test for stationarity check similar
exhibit mean-reversion, the issue of pairs
to STAGE1 above.
trading.

Ticker shortcut Rel :: Reliance. ONGC:: Oil and Natural Gas corporation

Table 5 Granger causality

STAGE 3 Description Key Equation


Summary The lead lag pairs were accordingly tabulated ONGC t = t REL t + t
based on the significance level

Significance As discussed earlier, ..

3.2.2 Beta Modeling

Residual behavior is sensitive to beta values so it becomes imperative to calculate the best possible value
for this parameter with the available in-sample period to apply it for the out of sample range. Below we
outline the process adopted to calculate the time adaptive beta for the research.

Beta from this research perspective, is the allocation ratio between the two stocks or in econometrics
sense, the long run equilibrium relationship between the stocks. In our research, in order to demonstrate
the relationship between stock returns and beta measurement technique(Ceteris paribus), we selected
three beta models OLS, Average beta and DESP beta.

To ensure a more realistic scenario for market trading, we used walk forward optimization technique.
Details below for the windows sizes depends on the tick size. One example below.

1. Total Tick size: 9000. In-sample period(M=750). Out sample period(N=75). This parameters are
selected using 5-minutes tick data with 75 points representing one day data.
2. We calibrate beta using 750 points and then use this beta for the next 75 ticks on a rolling basis.

Average Beta methodology


As the name suggests, this method is simple, fast and effective for stock pairs with low standard
deviation in their price ratio.

M
avg ( )= ONGC t / RELt .
t =0

This average beta is applied to out of sample period on a rolling basis for spread calculations.

Rolling OLS beta methodology

The EG test results in OLS beta however this beta is criticized for having ghost effect, lagging effect and
drop-out-effect. (Bentz 2003, as cited by Dunis et al. 2010, p.6).

ONGC t = t REL t + t where t [ 0, M ] Equation 2

DESP Methodology

Simple exponential smoothing doesnt capture the trending data pattern appropriately. Brown (1956)
developed the DESP (Double Exponential-Smoothing Prediction) technique wherein the raw data is
smoothen twice to cover the trending aspect of the data, which is essential for prediction modeling.

In the scenarios of thousands of stock pairs in cross markets and composite pair baskets with live ticks
for trading signals; having a calculation method which is reliable and fast is the key to generate positive
returns. The accuracy and speed of Double Exponential-Smoothing Prediction has been tested and
contrasted against other popular forecasting methods by LaViola (2003). He concluded that DESP method
is a viable alternate to renowned KF/EKF predictor counterparts with 135 times faster.

We have explained this DESP methods step-wise below.

Step1 Step2 Step3 Step4


ONGC t S = t + (1 ) St 1 ; T t =S t + ( 1 ) T t 1 ;
t= for all t [0, M ]t at =2 S t T t ; b t= (S T t )
Rel t (1 ) t

Calculate the price ratio First Exponential Second exponential Parameters

at all in sample ticks smoothing smoothing for capturing calculation based on

the trend RMSE as below

For the subsequent out of sample time period, the forecasted beta is calculated as below
~
t +1=a t +k bt . This estimated beta is the proxy for the walk forward out of sample rolling period.

To estimate this beta, there are two unknowns, . We employ the matlab minimization technique

on the below equation. RMSE essentially tries to minimize the error between the estimated and the actual
beta.


M
( ^ t +i t +i)2
i=1 Equation 3
RMSE=
M

Since this beta behavior may vary for each stock pairs and rolling window, we calibrate the

parameters for each window for each stock pair in all the walk forward testing period.

This estimated beta is the key input for calculating the value of residual and the z-score which is
essentially the driver for trading signals.

3.2.3 Volatility Modeling

To compare and contrast, we employed three different Volatility models. Volatility is one of the parameters
for out of sample z-score(residual) calculation. This estimated volatility is derived from the in-sample
period.

Residual RMSE & EWMA Volatility model

A normal volatility equation weights all the prices time-period equally which may not capture more recent
behavior accurately. In the practitioners world, GARCH (1, 1) special case, EWMA(Exponential Weighted
Moving Average) is popular for its simplicity and robustness to forecast the volatility patterns.

Table 6 Volatility Life Cycle

Step1(Returns) Step2(Variance) Step3 (Normal SD) Step4 (EWMA)

2 2 2
EWMA : n ( ewma )= n1 +(1)u n1 Equation 4
Lambda is defaulted to .999( based on trial and error with in-sample) to give higher weightage to recent
data.

The above methods are fast and fairly accurate.

3.2.5 Residual Modeling


All the above models are used to calculate the out of sample residuals z-score. This z-score essentially is
the key driver to make the trading calls.

In this sense, this is where the live feed from the market will come in terms of stock prices and the
residual value will be calculated and a trading decision to buy or sell or do nothing will be made.

t =ONGC t t RELt for t (0, M )

To calculate the z-score of this residual( normalization), we used the below formula

t t ( o , M )
z= where are calculated using sample data; Z t
t (0, M )

Equation 5

In order to make the residual modeling more aligned with the practitioners world, we overlapped the
residual behavior with technical indicators and threshold modeling as outlined below.

Residual Risk Management: Sometimes, there can be a significant change in residual value
between two subsequent residual rolling period due to modeling issues. This can cause unnecessary
trading signals. We have captured such events in our research, and if the current residual values is
significantly different from past window, we change the beta estimation model and review the residual
values again. If the residual values are not still beyond the tolerance level of 6, then we then we switched
to OLS beta model as a last resort. This Risk management is done for DESP model based beta prediction.
Tolerance Breached Tolerance Breached
DES FIXED OLS
P

Residual Signal managements: The residual in a high frequency setting can sometime give
incorrect trading triggers based on the model estimation errors. In order to attempt to keep this behavior
in check, we employed two additional methods. First is to employ a suitable overlapping technical indicator
and secondly to make the trading signals on the falling curve on positive residual and on the rising curve
on negative residual. This is explained below.
3.2.5 Technical Indicators ( Bollinger Bands/Rising Curve Flag)
This Bollinger band, a highly useful technical tool for high frequency trading, acts as a safety value to
existing statistical arbitrage technique ensuring that erratic behavior of models can be checked to certain
extend.

In our research, we adopted Bollinger bands as the choice of technical indicator. Bollinger bands upper
and lower bands standard deviation were derived dynamic using changing trade entry values. In order for
Bollinger band to work, it required initial 40% of the out of sample tick for training and then was applied on
the remaining 60% of the out of sample dataset.

Bollinger band generates a upper and lower standard curve around the residual and everytime the residual
crosses this limit, and also the residual satisfies the criteria for trade entry threshold, then this translates
to a market trading signal.

We enhanced the above design further, by adding another layer of residual behavior on it explained with an
example below.

For the positive residual, due to mean reversion, we expect it to revert to its near zero mean. Assuming
the residual just satisfied the above entry criterias on its upward journey; the rising curve tracker
will thereafter track the residual behavior tick by tick and once the residual trend reverses, the trading
signal was generated. This is explained in more detail in the trading signal section.

3.2.4 Threshold modeling

However, the next important step is to decide at what standard deviation from the mean, we should go
long/short. Is it enough to just have a standard trading signal technique of two s.d. away or can we adapt
to different stock price behavior based on its rolling data. We tried to answer this question with our simple
threshold adaptive technique.

In our research to model the threshold, we couldnt much relevant information except for the work of
Vidyamurthy (2004) who details the sensitivity of threshold to expected returns. We then attempted to
model this threshold based on the rolling in-sample peak points behavior.

Through our research, we found that the past normalized peak (both top and bottom) behavior can assist
to set threshold entry and exit boundaries for out of sample range. We leverage this in-sample available
information for the signal peaks in the range of 0.2 to 4 s.d. and then averaged the mean of all the peaks
in this range. This averaged value will be the new found trade entry criteria. This adaptive model then
adapts to different stock pairs behavior at different point in time. The stop loss was modeled using the
correction factor of 2 on the maximum in-sample normalized peak for the rolling period.
From the modeling risk management perspective, if the entry point from the model was below 0.6, then we
defaulted the value to 2 s.d. Likewise, for the stop loss, if it was beyond 8 or below 4 then we defaulted to
6 s.d.

From the trading risk management perspective, adding the stop loss for any trade is imperative more so
for algorithmic trading.

3.3 Trade signal generation

All the above models have a single purpose to deliver, and its the right trading signals. In our research,
we have taken care to avoid any forward looking bias in our algorithm. Trade signals generated on the
tick size basis strictly follows the below sequence of events:

1. Select the parameters from the below options.

Model Type Model Values


Y: Algorithm based rolling window. Defaulted to 1 trading
Auto implement window(Y/N)
day to avoid overnight position risk.
Beta(OLS/DESP/OLS) Appropriate model selection for beta
Y: Position movement between two rolling periods. Might
Carry Forward(Y/N)
carry overnight position risk.
1: No leverage. Future market allows leverage upto ~3
Leverage Ratio(1:N)
times.
Rising Curve(Y/N) Y: Track residual curve movement. N: Dont track.
Y: Skip co-integration check for residual behaviour.
Skip Cointegration Check(Y/N)
Appropriate for highly mean-reverting stocks.
Technical Indicator(Y/N) Y: Bollinger band. N: none
Threshold( PEAK/DEFAULT) Peak: Model the threshold behaviour.
Tick Delay(0/1) 1: One tick delay in execution of trading signal
10 bps based on capital of 50,000 INR (i.e. 50 INR for each
Transaction cost stock execution. Includes Stamp duty and all other
charges.)
Volatility('GARCH11','EWMA','RMSE') Appropriate model selection for volatility

2. If cointegration flag is enabled then check for co-integration for every rolling in-sample period. For
cointegrated pairs, run the out of sample period as per the below steps.
3. Record the in-sample estimated beta and estimated volatility for out of sample period.
4. Calculate the Z-score of the out of sample residual using the information until step2.
ONGC t t REL t
`t = for t ( M , N ]
t ( ewma )

Equation 6
5. Generate signals based on the below three essential criteria. Value of +1 means going long on the
stock and -1 means going short. ONGC=Stock Y and RIL=Stock X. If residual is positive, short
ONGC and long Reliance.

if [ ( `t ) >+threshold entry ( `t ) >Bol up ( `t < t1


` ) ]then sigONGC ( t )=1sig REL=+1

if [ ( `t ) <threshold entry ( `t ) < Bol d own ( `t > t`+1 ) ]then sigONGC ( t ) =1sig REL=+1

Equation 7

6. Keep continuous check on stop loss and exit criteria. E.g. below with a long position on Reliance
and Short on ONGC.

( `t ) exit then sigONGC ( t )=0sig REL=0 t


if

( `t ) stoplossthen sigONGC ( t )=0sig REL=0 t


if

Equation 8

These systematic steps completes the life-cycle for trade signal generation. Next follows the trade
execution section.

3.4 Trade execution

The price at which we generate the signals and sent the market order signals suffers from execution delay
which depending on the trading strategy might be crucial. In order to check this notion, we allow the users
to add upto one tick delay in the market order. Signal generated at time t is executed at time t+ next tick.

If the carry forward flag is disabled, all the open positions will be squared off at the end of the
implementation window, which is generally one trading day for high frequency tick. This feature was
incorporated to measure the benefit of carrying the overnight positions.

All positions are dollar neutral which means that we go long/short on equal dollar amount. This technique
compared to co-integration based money allocation offers two distinct advantages. Firstly, its a close
proxy to self-financing strategy (although there is a margin deposit involved) and secondly being dollar
neutral minimizes the reliance on model based allocation thus possibly minimizing variance in the
portfolio.

Additionally, we dont allow any partial square-off in the no of open position, since this could lead to
complex P&L management however we incorporate real transaction cost( for retail traders) into account in
our analysis.

<< some graph would be vital here>>>

3.5 Pairs selection upon statistical arbitrage

Apart from all the suite of model employ to do their respective job, this is by far the most important thing
is making a successful pair trading returns. There are over 75000 stocks globally and millions of
combinations are possible among them, selecting the best performing pairs involves not only
mathematical computation but also a priori of the market to certain extend.

In our research, we select top 5 in-sample performing stocks on the EOD data for the period from XXX to
XXX. The selection criteria were based on one best pair stock from each sector so as to diversify as much
as possible. The selection criteria were a certain weighted allocation to five parameters as detailed in the
chart below. These weights are configurable by the user.

Type Wt. Description Formula for each


T-adf stats 10 To check how strong the Regression based (Ind(1))
of residual co-integration relationship
IND(1) is between the pair.
Value: Higher the better
Beta ratio 30 To check for the variability ONGC t
(Stddev) in pair. Value: Lesser
Ind ( 2 ) =( )ratio=Var ( Rel t )
where t [0, M ]

IND(2) the better


Relative 30 To check how frequently it po s peak thres+ peak thres
frequency of mean-reverts in the in- 100
mean sample. M
M
reversion Value: Higher the better
t =0
IND(3)
Rel ( freq )=

peaks=based onsample residual .

M =total s ample points ; thres=1


Half-Life 10 To check through OU ln (2)
Halflife=
IND(4) model, how much time it k
takes to return to its long
k=adjustment speed to mean-reversion
equilibrium. Value:
dz t =k ( z t ) dt+ dW t
Lower the better. -- this is OU model

where =longterm mean; z t=spread at timet ;

high valueindicates preferable


k=adjustment speed

faster meanreversion

=std dev ; W t=brownian motion

[ ]
Sharpe ratio 20 Returns for each pairs exp ( Ret )exp ( Rfr )
S= AnnualScaling
IND(5) with the existing model in Std ( Ret )
place. Value: Higher the
better. for simplicity , we assumed E ( rfr )=0

252Tick

AnnualScaling=

Using all the above five indicators alongside allocated weights, we calculated the rank for each rolling
window of the pair

Rank t=W 'IND t where t [ 0, M ] where W ' is the ; INDt =for all the 5indicators

Repeat for 3 rolling window dividing the EOD data in three equal parts and then the ranks were averaged to
select the best pair. This was necessary to eliminate sample bias which otherwise needs to be mitigated
with residual bootstrapping [Vidyamoorthy 2004]. Details of the rank can be found in the appendix below.

rolwin

Rank t
Rol=1
FinalRank= wherero l win=3
rol win

The five best selected pairs based on the sequential ranking as listed below.
Sector Name Stock Y Stock X
Banks HDFCB HDFC
Energy ONGC RIL
Materials ACEM ACC
Pharmaceuticals, Biotechnology LPC DRRD
Utilities TPWR NTPC

Performance measurement in Out of sample

<< returns calculation here>>

<<transaction cost adjusted>>

Matlab code

<<high level summary>> & <<flow chart>>

4. Research outcome

<<General write up here>>

4.1 Pairs trading performance under model free assumption

<<graphs & tables>>

4.2 Pairs trading with different combinations of model

<<graphs & tables>>

4.3 Pairs trading with tick delays under different modelling conditions

<<graphs & tables>>

4.4 Pairs trading under leverage setting Future market proxy

<<graphs & tables>>

Benefit :

very low transaction cost,

average leverage allowed is only 1:3 for almost all equities.


4.5 Impact of transaction cost on returns

<<graphs & tables>> << for different combinations>>

Conclusion and outlook

future works

1. model the relationship between the transaction cost and the spread to make the max bucks for the
time

2. optimize the threshold models

3.position carry forward

Appendix

<<Bloomberg formulas>>

<< all stock names>>

<<other information>>

Bibliography

Darwin: http://pandasthumb.org/archives/2009/09/survival-of-the-1.html

References
1. Abadie, L. and Chamorro, J. (2008). Valuing fexibility: The case of an integrated
gasi_cation
combined cycle power plant. Energy Economics, 30, 1850{1881.
2. Abramowitz, M. and Stegun, I. (1972). Handbook of Mathematical Functions: with
Formulas,
Graphs, and Mathematical Tables. National Bureau of Standards. No. 55 in Applied
Mathematics
Series.
3. Ait-Sahalia, Y. (2002). Maximum likelihood estimation of discretely sampled di_usions: a
closedform
approximation approach. Econometrica, 70(1), 223{262.
4. Alexander, C. and Dimitriu, A. (2002). Cointegration-based trading strategies: A new
approach
to enhanced index tracking and statistical arbitrage. Discussion Paper 2002-08, ISMA Centre
Dis-
cussion Papers in Finance Series.
5. Ancarani, L. U. and Gasaneo, G. (2008). Derivatives of any order of the conuent
hypergeometric
function 1f1(a; b; z) with respect to the parameter a or b. Journal of Mathematical Physics,
49.
6. Bertram, W. (2010). Analytic solutions for optimal statistical arbitrage trading. Physica A:
Sta-
tistical Mechanics and its Applications, 389(11), 2234{2243.
7. Brennan, M. and Schwartz, E. (1979). A continuous-time approach to the pricing of bonds.
Journal of Banking and Finance, 3, 133{155.
8. Cox, D. and Miller, H. (1977). The Theory of Stochastic Processes. Chapman & Hall/CRC.
9. Cox, J., Ingersoll, J. and Ross, S. (1985). A theory of the term structure of interest rates.
Econometrica, 53, 385{407.
10. Donati-Martin, C., Ghomrasni, R. and Yor, M. (2001). On certain markov processes
attached
to exponential functionals of brownian motion: Applications to asian options. Revista
Matematica
Iberoamericana Madrid, 17(1), 179{193.
11. Elliott, R., Van DerHoek, J. and Malcolm, W. (2005). Pairs trading. Quantitative Finance,
5(3), 271{276.
12. Engle, R. and Granger, C. (1987). Cointegration and error correction: representation,
estimation
and testing. Econometrica, 55, 251{276.
13. Feller, W. (1951). Two singular di_usion problems. Annals of Mathematics, 54, 173{182}.

14. Gatev, E., Goetzmann, W. and Rouwenhorst, G. (2006). Pairs trading: Performance of a
relative-value arbitrage rule. Review of Financial Studies, 19(3), 797{827.
15. Glosten, L., Jagannathan, R. and Runkle, D. (1993). On the relation between expected
value
and the volatility of the nominal excess return on stocks. The Journal of Finance, 48(5),
1779{1801.
16. Going-Jaeschke, A. and Yor, M. (2003). A survey and some generalizations of bessel
processes.
Bernoulli, 9(2), 313{349.
17. Granger, C. (1981). Some properties of time series data and their use in econometric
model speci-
_cation. Journal of Econometrics, 2, 121{130.
18. Hong, J. and Satchell, S. (2010). The sensitivity of beta to the time horizon when log
prices
follow an ornstein-uhlenbeck process. Working Paper.
19. Javaheri, A. (2005). Inside volatility arbitrage: the secrets of skewness. John Wiley &
Sons, Inc.
20. Jensen, B. and Poulsen, R. (2002). Transition densities of di_usion processes: numerical
comparison
of approximation techniques. Journal of Derivatives, 9, 1832.
21. Lewis, A. (2000). Option Valuation Under Stochastic Volatility: With Mathematica Code.
Finance
Press, Newport Beach, California.
22. Linetsky, V. (2004). The spectral decomposition of the option value. International Journal
of
Theoretical and Applied Finance, 7(3), 337{384.
23. | (2004a). The spectral decomposition of the option value. Internat. J. Theoretical Appl.
Finance,
7, 337{384.
24. Nelson, D. (1990). Arch models as di_usion approximations. Journal of Econometrics, 45,
7{38.
25. Olver, P. (1999). Classical Invariant Theory. Cambridge University Press, ISBN
0521558212 .
26. Pedersen, A. (1995). A new approach to maximum likelihood estimation for stochastic
di_erential
equations based on discrete observations. Scandinavian Journal of Statistics, 22(1), 55{71.
27. Pilipovic, D. (1998). Energy Risk. McGraw-Hill, , New York.
28. Ricciardi, L. and Sato, S. (1988). First-passage-time density and moments of the
ornsteinuhlenbeck
process. Journal of Applied Probability, 25(1), 43{57.
29. Sharpe, W. (1994). The sharpe ratio. Journal of Portfolio Management, 21, 49{58.
30. Stock, M., J.and Watson (1988). Testing for common trends. Journal of the American
Statistical
Association, 83(404), 1097{1107.
31. Vidyamurthy, G. (2004). Pairs Trading. John Wiley & Sons Inc.
32. Wang, Y. (2002). Asymptotic nonequivalence of garch models and di_usions. Ann.
Statist., 30(3),
754{783.
33. Zhao, B. (2009). Mean first passage times of the feller and the garch di_usion processes.
Available
at SSRN: http://ssrn.com/abstract=1465334

[CTFC, 2012] Foresight: The Future of Computer Trading in Financial Markets, 2012. Final Project
Report,
The Government office for Science, London
Appendix

Bloomberg Code: =BDH(<StockName>,"LAST_PRICE","<StartDate>,"<end


date>","BarSz=20","TZ=Calcutta","Fill=B","RecurDaily=True","UseDPDF=N","CshAdjAbnormal=N","CshAd
jNormal=N","CapChg=Y","cols=2;rows=3610")

Вам также может понравиться