the application of pairs trading to stock markets

31
7/23/2019 The Application of Pairs Trading to Stock Markets http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 1/31 THE APPLICATION OF PAIR TRADING TO DIFFERENT STOCKS USING R A research project submtte! " the  parta# $u#$##me"t o$ the re%ureme"ts $or the !e&ree o$ '(Tech " Data Sce"ce  b) Gu"ja" Da!hch A*+,-  UNDER SUPER.ISION OF  pROF( sI/A PANDA

Upload: dadhich-gunjan

Post on 18-Feb-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 1/31

T H E A P P L I C A TI O N O F P AI R T R A D I N GT O D I F F E R E N T S T O C K S U S I N G R  

A research project submtte! " the

 parta# $u#$##me"t o$ there%ureme"ts $or the !e&ree o$

'(Tech

"

Data Sce"ce

 b)Gu"ja" Da!hch

A*+,-

  UNDER SUPER.ISION OF

 pROF( sI/A PANDA

Page 2: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 2/31

0 , 1 2 * 0 , 1 - D E C L A R A T I O N

I hereb) !ec#are that the research project tt#e!3 4The

App#cato" o$ Par Tra!"& to Stoc5 'ar5ets63 submtte!

 b) me s base! o" or&"a# 7or5 carre! out b) me( I

cert$) that t has "ot bee" submtte! a")7here e#se( 8e

$urther !ec#are that 'u5esh Pate# Schoo# o$ Tech"o#o&)

'a"a&eme"t a"! E"&"eer"&*N'I'S 9!eeme!*to*be*

u":erst); 7## ha:e the cop)r&ht o" the project report

submtte! b) me to the co##e&e 9'PST'E;(

Tha"5"& <ou

Gu"ja" Da!hch

Page 3: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 3/31

A C K N O 8 L E D G ' E N T

It s m) prou! pr:#e&e to re#ease the $ee#"&s o$ m)&rattu!e to se:era# perso"s 7ho he#pe! me !rect#) or "!rect#) to co"!uct ths research project 7or5( I e=pressm) heart $u## "!ebt"ess a"! o7e a !eep se"se o$ &rattu!e to m) $acu#t) &u!e Pro$( Sba Pa"!a3 Pro$(Sara!a Sama"tara) $or ther s"cere &u!a"ce a"!"sprato" " comp#et"& ths project( I am e=treme#)

tha"5$u# to the 'r( A"shu# Gupta3 'r( Hema"t Pa#:e#aa"! a## $acu#t) members o$ '(Tech Data Sce"ce o$ 'PST'E $or ther coor!"ato" a"! cooperato" a"! $or ther 5"! &u!a"ce a"! e"coura&eme"t( I a#so tha"5 a##m) $re"!s 7ho ha:e more or #ess supporte! a"!e"coura&e! me to comp#ete ths project( I 7## be a#7a)s"!ebte! to them( The stu!) has "!ee! he#pe! me toe=p#ore more 5"o7#e!&eab#e a:e"ues re#ate! to m) topca"! I am sure t 7## he#p me " m) $uture(

Gu"ja" Da!hchA*+,-'(Tech 9Data Sce"ce;

TABLE OF CONTENTS

Page 4: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 4/31

ABSTRACT

Ths project s to mp#eme"t the use$u#"ess o$ a he!&e $u"! tra!"& strate&) 5"o7" as4pars tra!"&6 app#e! to !$$ere"t stoc5s( The pro$t retur" o$ a smp#$e! parstra!"& strate&) s mo!e#e! b) us"& a mea"*re:ert"& process o$ the $utures prce

sprea!( As per the comparat:e statcs o$ the mo!e#3 the h&h mea"*re:erso" a"! h&h:o#at#t) o$ the sprea! &:e rse to the h&h o:era## retur" $rom tra!"&( A"a#)>"&e"er&) $utures 9more spec$ca##)3 HPCL a"! /PCL; tra!e! o" the Nato"a# Stoc5 E=cha"&e3 7e prese"t emprca# e:!e"ce that pars tra!"& ca" pro!uce a re#at:e#)stab#e pro$t( 8e are us"& the statc mo!e# " ths project 7here 7e are ca#cu#at"& thehe!&e rato $rom the hstorca# prces( 8e are us"& #"ear re&resso" to $"! out theHe!&e rato3 a"! !o"& ADF test to chec5 the Co "te&rato" bet7ee" the stoc5s( 8eare ca#cu#at"& the retur" $rom the par tra!"& a"! p#ott"& the s&"$ca"t tra!"&strate&) o" the sprea! 7here 7e are se##"& the e=pe"s:e a"! bu)"& the cheap stoc5 7he" the sprea! s mo:e! abo:e certa" e=te"!( The !ata has bee" ta5e" $rom <ahoo$"a"ce 7ebste a"! c#ea"e! a"! $ormatte! as per the project re%ureme"t us"& R3

A#so 7e are us"& R too# $or the mp#eme"tato" o$ the par tra!"&( The a"other Stoc5  par o$ AAPL a"! ??? s ta5e" to mp#eme"t the par tra!"& " R 3ths has bee" !o"e

4

Page 5: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 5/31

7th the Lbrar) 4partra!"&6(8e a#so su&&este! that the par tra!"& ca" be &oo!7th the h&h $re%ue"c) !ata 7th the e"tr) po"t a"! e=t"& po"t s ca#cu#ate! o" theh&h $re%ue"c) !ata as compare to the statc mo!e#( 8e ha:e "c#u!e! HFT process"&as the $uture scope o$ ths project( Ths project s more $ocuse! o" the " !epth stu!)o$ the par tra!"& co"cept a"! "orma# mp#eme"tato" o$ the par tra!"& co"cept "

the R us"& ?ua"t #brar) o$ the R(

0( INTRODUCTION

The Par tra!"& or commo"#) 5"o7" as statstca# arbtra&e3 s the most popu#ar 

tra!"& strate&) amo"& he!&e $u"!s3 as the) are per$ect $or the m"m>e! rs5 a"!

ab#t) to pro!uce retur"s " a") o$ mar5et e":ro"me"t that the par tra!"& strate&)

&:es( Par tra!"& s bee" there s"ce the ":e"to" o$ mar5ets3 @esse L:ermore3 s theo"e o$ the most $amous tra!ers o$ hs tme he use! par tra!"& bac5 " the #ate 1,,s3

he 7ou#! reco&">e a stro"& stoc5 the" short 7hat he ca##e! the Bsster stoc5( Par 

tra!"& rea##) use! 7th #ar&e ":estme"t ba"5s a"! he!&e $u"!s " the 1,s 7th the

he#p o$ "crease! uses o$ computers(

I" pars tra!"& strate&) the tra!er !e"t$es t7o bra"!s o$ stoc5 prces that are h&h#)

corre#ate! 7hch mea"s the t7o stoc5 prces mo:es s&"$ca"t#) to&ether base! o"

ther prce hstores a"! the" starts the tra!es b) ope""& #o"& a"! short posto"s o$ 

those t7o bra"!s se#ecte!( The par tra!"& strate&) so#e#) !epe"!s o" the corre#ato"

o$ the bra"! o$ stoc5s a"! the he!&e rato3 a rato that 7## compares the :a#ue o$ $utures posto"s that ha:e bee" bou&ht or so#! to the :a#ue o$ the u"!er#)"&

Page 6: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 6/31

commo!t) be"& he!&e!( It a#so ca" be " re$ere"ce to the rato that compares the

:a#ue o$ some part o$ a securt) posto" be"& he!&e! 7th the s>e o$ the e"tre

 posto" tse#$( I$ 7e are $or e=amp#e #o"& o"e u"t o$ P3 ho7 ma") u"ts o$ ? shou#!

7e se## short That %ua"tt) s 5"o7" as He!&e Rato( I" ths stu!) 7e are !o"& the

 par tra!"& o" the t7o I"!a" stoc5s $rom the same "!ustres H"!usta" petro#eumcorporato" #mte! 9HPCL; a"! /harat Petro#eum Corporato" #mte! 9/PCL;( 8e

7## be $"!"& the corre#ato" bet7ee" these t7o stoc5s a"! the" tr)"& to $t

hstorca# prces o$ these mo!e#s " to the re&resso" mo!e# to ca#cu#ate the He!&e

rato3 the" creat"& the sprea! $or these stoc5s( The statstca# pro&ram"& #a"&ua&e3 R 

s use! $or the mp#eme"tato" o$ the strate&) a"! the R pac5a&es ?UANT'OD(

The Gate:*Goet>ma""3 a"! Rou7e"horst " 90,,+; per$orm the emprca# tests o$ 

 pars tra!"& o" the commo" stoc5( The) !emo"strate! that a pars tra!"& strate&) s

much more pro$tab#e3 e:e" a$ter ta5"& "to accou"t such as tra"sacto" costs( The

@ure5 a"! <a"& 90,,-; e%uate the per$orma"ce o$ ther optma# mea"*re:erso"

strate&) 7th that o$ Gate:3 Goet>ma""3 a"! Rou7e"horst 90,,+; us"& the smu#ate!

!ata( The) !emo"strate that ther strate&) pro:!es e:e" better per$orma"ce tha" the

Gate:*Goet>ma""3 a"! Rou7e"horst( A#thou&h a pars tra!"& strate&) has bee"

app#e! prmar#) as a stoc5 mar5et tra!"& strate&)3 there s "o "ee! to #mt the

strate&) to that asset c#ass( A pars tra!"& strate&) &e"era##) re%ures t7o h&h#)

corre#ate! prces(

H&h Fre%ue"c) Data a#so ma) be use! " co"ju"cto" 7th a pars tra!"& strate&)( I"

 pars tra!"& strate&es3 a tra!er ta5es co"$#ct"& #o"& a"! short posto"s " t7o

assets 7he" the !$$ere"ce ther prces hts a !ec!e! ope""& thresho#!( These posto"s are the" c#ose! 7he" a !e$"te c#os"& thresho#! s reache!( The !$$ere"ce

" prces that the tra!er uses to ju!&e 7he" to ope" a"! c#ose a posto" s commo"#)

re$erre! to as the sprea! bet7ee" the par o$ assets( The t7o stoc5s !e"t$e! are

e=pecte! to mo:e to&ether !ue to ther status as c#ose substtutes $or each other(

E=amp#es o$ pars "c#u!e o# ma"u$actur"& compa"es3 #ar&e $"a"ca# "sttuto"s3

a"! some cre!t car! compa"es( The Pars tra!"& strate&es see5 to e=p#ot

temporar) msprc"& o$ assets 7th" the mar5et a"! thus3 the) re#) o" mea"*

re:erso" a"! !e:e#op mar5et*"eutra# port$o#os 7hose "et mar5et e=posure s

"e&#&b#e(

Rece"t#)3 7th the &ro7"& a!mrato" o$ HFT :arous stu!es 7hch e=am"e that the

app#cab#t) o$ pars tra!"& strate&es to h&h $re%ue"c) e":ro"me"ts ha:e bee"

 per$orme!( The /o7e" et a#( 90,1,; e=am"e the mporta"ce o$ h&h $re%ue"c)

strate&es to mar5et attrbutes3 "ot"& that prmar) retur"s to ther strate&) arse " the

:er) $rst hour a"! #ast hour o$ tra!"& !a)s3 7he" the tra!"& :o#ume s e=pecte! to

 be h&hest(

( /ac5&rou"! o$ Pars Tra!"&

3.1 History

6

Page 7: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 7/31

The hstor) o$ par tra!"& s bt "terest"& some7here " m!*1,s the 8a## Street%ua"t Nu">o Tarta&#a !ec!e to assemb#e! a team o$ &oo! ph)scsts3 &oo!mathematca"s a"! some o$ computer sce"tsts to u"co:er some arbtra&eopportu"tes " the e%utes mar5ets( Dur"& that pero! Tarta&#as &roups o$ $ormer 

aca!emcs use! some sophstcate! statstca# metho!s to !e:e#op a h&h*tech tra!"& pro&rams3 7hch are e=ecutab#e throu&h automate! tra!"& s)stems that too5 the"tuto" a"! tra!ers s5## out o$ arbtra&e a"! rep#ace! t 7th !scp#"e!a"! moreco"sste"t $#ter ru#es( Amo"& other th"&s Tarta&#as pro&rams !e"t$e! such parso$ securtes 7hose prces are te"!e! to mo:e to&ether( The) tra!e! these pars 7thhu&e success " 1- a )ear 7he" the &roup reporte!#) ma!e a 2, m##o" pro$t $or the $rm tota##)( A#thou&h the 'or&a" Sta"#e) &roup s !sba"!e! " 1 a$ter acoup#e o$ ba! )ears o$ per$orma"ce but par tra!"& become a" "creas"&#) popu#ar mar5et*"eutra# ":estme"t strate&) 7hch s a$ter7ar!s use! b) "!:!ua# a"!"sttuto"a# tra!ers as 7e## as he!&e $u"!s( The amp#$e! popu#art) o$ %ua"ttat:e*

 base! o" statstca# arbtra&e strate&es has a#so appare"t#) a$$ecte! pro$ts " a Ne7

<or5 Tmes "ter:e73 Da:! Sha7 hea! o$ o"e o$ the most success$u# mo!er" %ua"tshops a"! hmse#$ a" ear#) Tarta&#as aco#)te3 su&&ests that rece"t pc5"&s $or %ua"t*shops ha:e become s#m he attrbutes the success o$ hs $rm D(E( Sha7 to ear#) e"tr)"to the bus"ess( The Tarta&#as o7" e=p#a"ato" $or pars tra!"& strate&) s

 ps)cho#o&ca#( He c#ams that 4Huma" be"&s !o"t #5e to tra!e a&a"st huma""ature3 7hch 7a"ts to bu) stoc5s a$ter the) &o up "ot !o7"(16 Cou#! pars tra!ers bethe se#$*co"tro##e! ":estors ta5"& a!:a"ta&e o$ the u"!scp#"e! o:er*reacto"!sp#a)e! b) "!:!ua# ":estors(

3.2 The Data Snooping and Ee!ti"e #ar$et Response

I" our project 7e ha:e "ot e=p#ore! o:er the $u## strate&) space to !e"t$) e$$ect:etra!"& ru#es but rather 7e ha:e "terprete! practto"er !escrpto" o$ pars tra!"& asstra&ht $or7ar!#) as possb#e( Our ru#e $o##o7 the &e"era# out#"e o$ $rst $"! stoc5s

that mo:e to&ether a"! seco"! ta5e a #o"&*short posto" 7he" the) !:er&e a"!u"7"! upo" co":er&e"ce o$ the stoc5s( The test re%ures that both o$ the abo:e stepsmust be parameter>e! " some 7a)( The ma" %uesto"s 7hch put up s ho7 to $"!the stoc5s 7hch are mo:"& s&"$ca"t#) sm#ar a"! ho7 7e 7## be !ec!"& theope" posto" a"! c#ose posto" o$ the tra!"&( 8e ha:e ma!e stra&ht$or7ar! chocesabout each o$ these %uesto"s( 8e !ra7 posto"s o" at a sta"!ar! !e:ato" sprea!7hch m&ht "ot a#7a)s co:er tra"sacto"s costs e:e" 7he" stoc5 prces co":er&e(E:e" thou&h t s tempt"& to tr) pote"ta##) more pro$tab#e schemes3 the !a"&er "!ata*s"oop"& e"ha"ceme"ts out7e&hs the pote"ta# "s&hts &a"e! about the h&her 

 pro$ts that cou#! resu#t $rom the #ear""& throu&h test"& ( As 7th a## $#ter ru#es us"&hstorca# asset prc"& !ata3 !ata*s"oop"& s a b& co"cer"( A#so the o"e approach

to7ar!s the !ata s"oop"& ssue s to test the resu#ts out*o$*samp#e( 8e are us"& !atathrou&h the e"! o$ 0,1(

Page 8: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 8/31

3.3 Re%ati"e &ri!ing

The asset prc"& ca" be :e7e! " abso#ute as 7e## as re#at:e terms( The abso#ute prc"& :a#ues stoc5s $rom $u"!ame"ta#s such as !scou"te! $uture cash $#o7( Ths s a

e=treme#) !$$cu#t process 7th a 7!e mar&" $or error( The papers b) /a5sh a"!Che" 91-; a"! Lee et a#( 91-; $or e=amp#e are &reat attempts to bu#! %ua"ttat:e:a#ue $or ":est"& mo!e#s( Re#at:e prc"& s o"#) some7hat easer( The re#at:e

 prc"& mea"s that a") t7o securtes 7hch are c#ose substtutes $or each other shou#!se## $or the same prce J t !oes "ot sa) ho7 much that prce 7## be( Thus re#at:e

 prc"& a##o7s $or bubb#es " the eco"om)3 but s "ot "ecessar#) arbtra&e or  pro$tab#e specu#ato"(La7 o$ O"e Prce LOP J a"! a 4"ear*LOP6 s o"#) app#cab#e to re#at:e prc"& J e:e" $ that prce s 7ro"&( The I"&erso## 91-; !e$"es the LOP as the4proposto" ((( that t7o ":estme"ts 7th the same pa)o$$ " e:er) state o$ "aturemust ha:e the same curre"t :a#ue(6 I" smp#e 7or!s t7o securtes 7th the same

 prces " a## states o$ the 7or#! shou#! be se##"& $or the same amou"t( The Che" a"!K"e> 912; e=te"! ths b) &:"& ar&ue that 4closely integrated mar5ets shou#!ass&" to sm#ar pa)o$$s prces that are close(6 The) ar&ue that t7o securtes 7thsm#ar but "ot "ecessar#) match"& pa)o$$s across states shou#! ha:e sm#ar prces(Ths s o$ course a 7ea5er co"!to" a"! subject to bou"!s o" prces $or u"usua#states3 ho7e:er t a##o7s the e=am"ato" o$ 4"ear e$$ce"t6 eco"omes3 or " Che"a"! K"e> case3 "ear "te&rate! mar5ets( Notce that ths theor) correspo"!s to the!esre to $"! t7o stoc5s 7hose prces mo:e to&ether as #o"& as 7e ca" out#"e stateso$ "ature as the tme*seres o$ obser:e! hstorca# tra!"& !a)s(8e ha:e use a" a#&orthm to se#ect pars base! o" the crtero" that the) ha:e ha! thesame state prces hstorca##)( The" 7e tra!e pars 7hose prces c#ose#) match "hstorca# state*space3 s"ce the LOP su&&ests that " a" e$$ce"t mar5et3 ther prcesshou#! be "ear#) !e"tca#( I" ths project3 the curre"t stu!) ca" be :e7e! as a test o$ the LOP a"! "ear*LOP " the e%ut) mar5ets3 u"!er certa" stato"ar) co"!to"s(Here 7e are e$$ect:e#) test"& the "te&rato" o$ :er) #oca# mar5ets J the mar5ets $or spec$c "!:!ua# securtes( Ths s sm#ar to /ossaerts 91; test o$ co*"te&rato"o$ securt) prces at port$o#o #e:e#( 8e $urther specu#at"& that the mar&"a# pro$ts to

 be ha! $rom rs5 arbtra&e o$ these temporar) !e:ato"s are cruca# to thema"te"a"ce o$ $rst*or!er e$$ce"c)( 8e cou#! "ot ha:e the $rst e$$ect 7thout theseco"!(

3.' Co(integrated &ri!es

The pars tra!"& tech"%ue ma) be just$e! 7th" s)mmetrca# asset*prc"&$rame7or5 7th "o"*stato"ar) commo" $actors #5e /ossaerts a"! Gree" 91; a"!@a&a""atha" a"! .s7a"atha" 91;( I" 7hch $ the #o"& a"! short compo"e"ts$#uctuate 7th commo" "o"*stato"ar) $actors the" the prces o$ the compo"e"t

 port$o#os 7ou#! be co*"te&rate! a"! the pars tra!"& strate&) 7ou#! be e=pecte! to7or5( E:!e"ce o$ e=posures to commo" "o"*stato"ar) $actors 7ou#! support a "o"*stato"ar) $actor prc"& $rame7or5( Co*"te&rato" shou#! "ot be co"$use! b)corre#ato" spec$es the co*mo:eme"t o$ retur"s ths &:es the short termre#ato"shps3 7hereas the Co*I"te&rato" spec$es the co*mo:eme"t o$ the prces a"!

t &:es #o"& term re#ato"shp(

8

Page 9: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 9/31

The area o$ "orma#>e! a"! cum*!:!e"! prces3 (e( cumu#at:e tota# retur"s 7th!:!e"!s re*":este!3 s the basc space $or the pars tra!"& strate&es " ths project(The ma" obser:ato" about our mot:at"& mo!e#s o$ the HPCL*/PCL :aret) s thatthe) are 5"o7" to mp#) per$ect co##"eart) o$ prces 7hch s rea!#) rejecte! b) the!ata( O" the other ha"!3 /ossaerts 91; $"!s e:!e"ce o$ prce co*"te&rato" $or 

the US stoc5 mar5et( 8e 7ou#! #5e to 5eep the co"cept o$ the emprca##) obser:e!co*mo:eme"t o$ prces3 7thout u""ecessar#) restrct:e assumpto"s3 he"ce 7e

 procee! " the sprt o$ the co*"te&rate! prces metho!('ore precse#)3 our match"& " prce space ca" be "terprete! as $o##o7s( Supposethat prces obe) a statstca# mo!e# o$ the $orm3

 p it M il p lt + it 3 k Q n 91;

7here it !e"otes a 7ea5#) !epe"!e"t error " the se"se o$ /ossaerts 91;( Assumea#so that pit s $eeb#) !epe"!e"t a$ter !$$ere"c"& o"ce( U"!er these assumpto"s3 the

 prce :ector  pt s co*"te&rate! o$ or!er 1 7th co*"te&rat"& ra"5 r = n-k 3 " these"se o$ E"&#e a"! Gra"&er 91-; a"! /ossaerts 91;( Thus3 there e=st r #"ear#)

"!epe"!e"t :ectors qqM1(( r such that >% M q `pt are 7ea5#) !epe"!e"t( That mea"s3r #"ear comb"ato"s o$ prces 7## "ot !r:e" b) the k commo" "o"*stato"ar)compo"e"ts  pl ( A#so "ote that ths "terpretato" !oes "ot mp#) that the mar5et s"e$$ce"t3 " co"trar) t sa)s that certa" assets are 7ea5#) re!u"!a"t3 so that a")!e:ato" o$ ther prce $rom a #"ear comb"ato" o$ the prces o$ other assets se=pecte! to be temporar) a"! retur""&(I" par tra!"& to "terpret the pars as co*"te&rate! prces3 7e "ee! to assume that $or n k 3 there are some co*"te&rat"& :ectors 7hch ha:e o"#) t7o "o">ero coor!"ates(I" the case #5e ths the sum or !$$ere"ce o$ sca#e! prces 7## be re:ert"& to >ero a"!a tra!"& ru#e cou#! be co"structe! to e=p#ot the e=pecte! temporar) !e:ato"s( Our strate&) re#es upo" e=act#) same co"c#uso"( I" pr"cp#e 7e cou#! co"struct tra!"&

strate&es 7th tros3 %ua!rup#es3 etc( o$ stoc5s 7hch 7ou#! presumab#) capture moreco*"te&rate! prces a"! 7ou#! &:e better pro$ts(The h)pothess that a #"ear comb"ato" o$ t7o stoc5s ca" be 7ea5#) !epe"!e"t ma)

 be u"!erstoo! as sa)"& that a co*"te&rat"& :ector ca" be partto"e! " t7o parts3such that the t7o correspo"!"& port$o#os are prce! 7th" a 7ea5#) !epe"!e"t error o$ a"other stoc5( 8th &:e" the #ar&e u":erse o$ stoc5s3 ths stateme"t s a#7a)semprca##) :a#! a"! pro:!es the bass o$ our $ormato" o$ proce!ure(3.) The Ban$r*pt!y Ris$ 

The u"pre!cte! rs5 o$ ba"5ruptc) s o"e o$ the reaso"s 7h) the retur"s o" "!:!ua#securtes ca""ot be ta5e" as stato"ar)( Se"st:t) o$ the pars tra!"& to the !e$au#t

 premum su&&ests that the strate&) ca" 7or5 because 7e are par"& t7o $rms3 the$rst o$ 7hch ma) ha:e a co"sta"t or !ecreas"& probab#t) o$ ba"5ruptc) 9shorte"!;3 7h#e the seco"! ma) ha:e a mome"tar#) "creas"& probab#t) o$ ba"5ruptc)9#o"& e"!;(A"! the 47o"!er mpro:eme"ts6 " the short e"! are the" $o##o7e! b)mpro:eme"t " the #o"& e"! $ that stoc5 sur::es( I" other 7or!s3 the source o$ the

 pro$t s the mpro:"& e=*post 9"o"; rea#>ato" o$ ba"5ruptc) rs5 " the #o"& 9#oser;stoc5( I" such case3 7e 7ou#! e=pect to ha:e as)mmetr) " the pro$ts $rom the #o"&a"! the short compo"e"ts3 7th most o$ the pro$ts com"& $rom the #o"& e"!( 8eha:e to test #o"& a"! short posto"s separate#) to see $ ths s !r:"& our resu#ts(

Page 10: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 10/31

V( Resear!h #ethodo%ogy.

I" ths stu!)3 7e $rst se#ect the par o$ stoc5s HPCL a"! /PCL a"! ther hstorca# prces a"! the" 7e 7## chec5 $ these t7o stoc5s are corre#ate! or "ot( O"ce thecorre#ato" s $ou"! 7## ru" the re&resso" mo!e# to co"$rm the corre#ato" a"! $"!

the he!&e rato 37hch s "oth"& but &:es the e%uato" o" $ 7e ha:e o"e #o"& u"to$ HPCL ho7 ma") u"ts o$ /PCL 7e shou#! se##( Ths rato 7## he#p " creat"& theSprea! o" the prces o$ HPCL a"! /PCL( No7 7e 7## be !ec!"& our tra!"&strate&) such that(

1; For each tme po"t " the tme seres3 ca#cu#ate the rs5*a!juste! sprea! bet7ee" the t7o assets o$ the par(

0; Ca## the amou"t the sprea! !e:ates $rom a measure o$ the hstorca# sprea!the 4s&"a#6( I$ the s&"a# s &reater tha" or e%ua# to the ope""& thresho#!3ope" a posto" $ "ot a#rea!) " o"e(

; I$ the sprea! s abo:e ts hstorca# mea"3 the" 7e e=pect that stoc5 1 so:erprce! a"! stoc5 0 s u"!er*prce!( Thus3 7e short*se## stoc5 1 a"! bu)

10

Page 11: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 11/31

stoc5 0( O" the other ha"!3 $ the sprea! s u"!er ts hstorca# mea"3 7e bu) stoc5 0 a"! short*se## stoc5 1(

V; I$ the s&"a# s #ess tha" the c#os"& thresho#!3 c#ose a") e=st"& posto"" the par(

2; I$ the s&"a# s &reater tha" the stop*#oss thresho#!3 7e c#ose the posto"(

+; I$ a posto" s ope" o" the #ast tme po"t " the !ata seres3 7e c#ose the posto"(Re#ato" /et7ee" the t7o prces $or the )ear#o"& "ter:a# 0,10*0,1 s

 be" !o7"#oa!e! b) us"& the ?ua"tmo! pac5a&e " R $or the &:e" tme pero!(

F&1W It &:es the prces p#ots o$ the t7o stoc5s Re! s $or HPCL a"! Gree" s $or /PCL(

'.1 Regression Ana%ysis

Re&resso" s a :er) "terest"& topc( Re&resso" s a 7!e#) use! as a statstca# too#

" eco"omcs3 X"a"ce a"! tra!"&( R pro:!es the pre*7rtte" $u"cto"s that per$orm

#"ear re&resso"s " a :er) up*$ro"t ma""er( A#so there e=st mu#tp#e a!!*o"

 pac5a&es that a##o7 $or more a!:a"ce! $u"cto"a#t)( I" ths project 7e 7## o"#)

ut#>e the %+,- $u"cto" 7hch s a:a#ab#e " the base "sta##ato" o$ R( The $o##o7"&

e=amp#e !emo"strates the use o$ ths $u"cto"W

outR Q * %+9Stoc5Y) Z Stoc5Y=;

s*++ary9outR ;

The ca##"& to the $u"cto" %+ , - per$orme! a" OLS 9Or!"ar) Least S%uares; Xt to

the $u"cto"W ) M b, [ b1= [ e3 7here e 7as !strbute! as N9mu3 s&ma\0;(

Page 12: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 12/31

The Z s&" s use! to separate the "!epe"!e"t $rom the !epe"!e"t :arab#es( The

e=presso" Stoc5Y) Z Stoc5Y= s a $ormu#a that specXes the #"ear mo!e# 7th o"e

"!epe"!e"t :arab#e a"! a" "tercept( I$ 7e 7a"te! to Xt the same mo!e#3 but

itho*t the inter!ept3 7e 7ou#! spec$) the $ormu#a as Stoc5Y) Z Stoc5Y= J 1( Ths

te##s R to omt the "tercept 9$orce t to >ero;(I" the tra!"& app#cato" 7e ha:e to ru"

the mo!e# 7thout the "tercept as the tra!er 7## o"#) be "tereste! o" the s&"$ca"ce

coe$$ce"t o$ the t7o stoc5s a"! "ot 7th the "tercept(

'o!e#1 Q* %+9p!tHPC Z p!t/PC *1;

8he"e:er a re&resso" s per$orme!3 t s :er) mporta"t to a"a#)>e the res!ua#s 9e;

o$ the Xtte! mo!e#( I$ e:er)th"& &oes accor!"& to p#a"3 the res!ua#s 7## be

"orma##) !strbute! 7th "o :sb#e patter" " the !ata3 "o auto*corre#ato" a"! "oheteros5e!astct)( The res!ua#s ca" be e=tracte! $rom the re&resso" object b) us"&

the resid*a%s 5e)7or!(

resQ* mo!e#1res!ua#s

 p#ot9res;

ac$9res;

 The given function acf ( ) computes and by default plots the estimates ofthe autocovariance or autocorrelation function. And we can check the

correlation of the two stocks with this test.

Fig2 : gure below shows the randomness of the residulas.

12

Page 13: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 13/31

F&W The ACF p#ot to sho7 the Autocorre#ato" o$ the t7o stoc5s(

The be#o7 summar) 5e)7or! s use! to obta" the resu#ts o$ the #"ear re&resso"mo!e# Xt( Summary(model)

A#o"& 7th the other :arab#es the p*:a#ues a"! t*statstcs s use! to e:a#uate the

statstca# s&"Xca"ce o$ the coe$Xce"ts( The #esser the p*:a#ue3 the more certa" 7e

are that the coe$Xce"t estmate s c#ose to the actua# popu#ato" coe$Xce"t( /oth the

"tercept a"! the "!epe"!e"t :arab#e coe$Xce"t s s&"Xca"t " ths e=amp#e( The

e=tracto" o$ the coe$Xce"ts ca" be !o"e b) coe$$ce"t :arab#e "ame(

Page 14: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 14/31

Regression On Ret*rns o H&CL and B&CL ,2//0(2/12-

Res!ua# sta"!ar! error   1,0( o" 10+2 !e&rees o$ $ree!om

 p*:a#ue Q 0(0e*1+

Coe$$ce"tsW  1(20,2

A!juste! R*s%uare!W  ,(+-

Tab#e 1 W Re&resso" o" the prces o$ HPCL a"! /PCL

'.2 &AR TRADN us"& t7o stoc5s HPCL a"! /PCL(

8e 7## e=p#ore a smp#e t7o*#e&&e! sprea! bet7ee" /PCL a"! HPCL( O"ce 7e!o7"#oa! a"! tra"s$orm the tmeseres $or both stoc5s3 7e 7## !e$"e a smp#etra!"& ru#e a"! e=p#ore the tra!es that our s&"a# &e"erates( .arous tra!e statstcsa"! &raphs 7## be prese"te!(

Step 1 O4tain data "ia 5*ant+od.

]I"c#u!"& %ua"tmo! to #oa! the securt) s)mbo#s

re5*ire9%ua"tmo!;

sy+4o%s Q* !,^HINDPETRO(NS^3^/PCL(NS^; &etS)mbo#s9sy+4o%s6 ro+782/1/(/1(/186to 7 82/13(12(318;

 No7 that our !ata $rames $or HPCL a"! /PCL are #oa!e! "to memor)3 #ets e=tractsome prces(The !ata s " be#o7 ma""er(

/PCL(NS(Ope"

/PCL(NS(H&h

/PCL(NS(Lo7

/PCL(NS(C#ose

/PCL(NS(.o#ume

/PCL(NS(A!juste!

+2(2 +2(2 +2(2 +2(2 , 0+,(02

+2(22 +2-(+ +0 +20 1V0,,, 0+-(2-

+2+(V2 +2+(V2 +(0 +V,(0 1+,+,, 0+0(-2V

+V0 +V(V +0(1 +0(- 1V1,, 02(VVV

+1 +-(2 +1V(1 +0, 1V22,, 02V(V+

+1 +2(2 +1 +0( 11VV0,, 02(11+

Tab#e 0W The $ormat o$ the !ata !o7"#oa!e! $rom the )ahoo F"a"ce b) the?UANT'ODE #brar)

The !ata s o" !a#) bassOPENW The prce o" the ope" !a) o$ the stoc5 mar5et(HIGHW The h&hest prce the stoc5 reache! that !a)(

LO8W The #o7est prce the stoc5 reache! that !a)(CLOSEW The prce o$ the #ast tra!e 7he" the mar5et c#ose! that !a)(

14

Page 15: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 15/31

.OLU'EW The "umber o$ share tra!e! that !a)(AD@USTED CLOSEW C#ose prce a!juste! $or !:!e"!s a"! sp#ts(

Step 2 E9tra!t pri!es and ti+e ranges.

]7e are !e$""& the tra""& set StartYT Q* ^0,1,*,1*,1^

E"!YT Q* ^0,1*,1*,1^

Ra"&eYT Q* paste9StartYT3̂ WW^3E"!YT3sep M^^;

t/PCL Q* HINDPETRO(NS 3VRa"&eT

tHPCL Q* /PCL(NS 3VRa"&eT

]7e are the" !e$""& out o$ samp#e set

StartYO Q* ^0,1*,0*,1^

E"!YO Q* ^0,1*10*,1^

Ra"&eYO Q* paste9StartYO3^WW^3E"!YO3sep M^^;

o/PCL Q* HINDPETRO(NS3VRa"&eYO

oHPCL Q* /PCL(NS3VRa"&eYO

8e ha:e to be care$u# ho7 to !e$"e "Ysamp#e a"! outYo$Ysamp#e ra"&e( 8hch 7e7## use the "*samp#e !ata to ca#cu#ate a smp#e he!&e rato a"! the" 7e 7## app#)ths he!&e rato to the out o$ samp#e !ata( The " samp#e s ta5e" 7th the t7o )ear !ata a"! out samp#e s o"#) o"e )ear !ata 37e 7## be !e:e#op"& the mo!e# 7th thehstorca# !ata a"! 7## the" ru" t o" the out !ata(

Step 3 Co+p*te ret*rns and ind hedge ratio.

]compute prce !$$ere"ces o" "*samp#e !ata

 p!t/PC# Q* di 9t/PCL;*1

 p!tHPCL Q* di 9tHPCL;*1

]bu#! the mo!e#

mo!e# Q* %+9 p!t/PCL Z p!tHPCL * 1;

]e=tract the he!&e rato

hr Q* as.n*+eri!9mo!e#coe$$ce"ts1; ]hr s ,(1V-(

Regression On Ret*rns o H&CL and B&CL ,2//0(2/12-Res!ua# sta"!ar! error 1+(V o" 10+V !e&rees

Page 16: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 16/31

 p*:a#ue ,(,,-01

Coe$$ce"tsW ,(1V-

A!juste! R*s%uare!W ,(2,+1

Tab#e W Re&resso" Resu#ts o" the retur" o$ the t7o stoc5s(

Step ' Constr*!t the spread

Co"struct the sprea! bet7ee" the t7o stoc5s a$ter strpp"& out the e$$ects o$ co"te&rato" 7here the sprea! at tme t 3 S t M P 1_coint ! P 0(

Sprea! ca#cu#ato" $or each tme po"t " the tme seres3 ca#cu#ate the rs5*a!juste!sprea! bet7ee" the t7o assets o$ the par( Ca#cu#ato" o$ the sprea! s spec$e! "Tab#e 1 a"! !epe"!s o" the a##ocato" rato chose"(

]ca#cu#at"& sprea! prce 9"*samp#e;

Sprea!YT Q* t/PCL * hr ` tHPCL

]compute statstcs o$ the sprea! 'ea"YT Q* as.n*+eri!9+ean9Sprea!YT3"a(rmMTRUE;;

S!YT Q* as.n*+eri!9sd9Sprea!YT3"a(rmMTRUE;;

UpperYThr Q* 'ea"T [ 1 ` S!T

Lo7erYThr Q* 'ea"T * 1 ` S!T

UpperYThr0 Q* 'ea"T [ 0 ` S!T

Lo7erYThr0 Q* 'ea"T * 0 ` S!T

]:sua#>ING the "*samp#e sprea! [ stats

p%ot9Sprea!YT3 ma" M ^/PCL :s( HPCL sprea! 9"*samp#e pero!;^;

a4%ine9h M 'ea"YT 3 !o% M ^re!^3 #7! M0;

a4%ine9h M 'ea"YT [ 1 ` S!YT 3 !o% M ^b#ue^3 #7!M0;

a4%ine9h M 'ea"YT * 1 ` S!YT 3 !o% M ^b#ue^3 #7!M0;

a4%ine9h M 'ea"YT [ 0 ` S!YT 3 !o% M ^b#ue^3 #7!MV;

a4%ine9h M 'ea"YT * 0 ` S!YT 3!o% M ^b#ue^3 #7!MV;

16

Page 17: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 17/31

  F& VW Sprea! $or the )ear 0,, to 0,10(

  F& 2W Sprea! s $or the pero! 0,10 to 0,1 (

Lets #oo5 at the !strbuto" o$ the sprea!(

hist 9Sprea!YT3 !o% M ^/LUE^3 brea5s M 1,,3 ma" M ^Sprea! Hsto&ram

9/PCL :s( HPCL;^; a4%ine9: M 'ea"YT3 !o% M ^RED^3 #7! M 0;

  F& +W Dstrbuto" o$ sprea!(

Step ) Deine the trading r*%e.

Page 18: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 18/31

8e ha:e to !ec!e "o7 our tra!"& strate&) 3o"ce the sprea! 7## e=cee!s ourupper thresho#!3 7e se## /PCL a"! bu) HPCL( O"ce the sprea! !rops be#o7our #o7er thresho#!3 7e bu) /PCL a"! se## HPCL(

I"!YSe## Q* hi!h9Sprea!YT M mea"T [ s!T;

I"!Y/u) Q* hi!h9Sprea!YT QM mea"T * s!T;

Step : Fig*re o*t the trades.

Sprea!YL Q* %ength9Sprea!YT;

PrcesY/ Q* !9rep9 NA3Sprea!YL;;

PrcesYS Q* !9rep9 NA3Sprea!YL;;

SpYT Q* as.n*+eri!9S prea!YT;

Tra!eY?t) Q* 1,,

Tota#YP Q* ,

or9 in 1WSprea!YL; 

  spTemp Q* SpYT  i 9spTemp Q Lo7erYThr ; 

  i 9Tota#YP QM ,;  Tota#YP Q* Tota#YP [ Tra!eY?t)  PrcesY/ Q* spTemp     e%se i 9spTemp  UpperYThr ; 

  i 9Tota#YP M ,;    Tota#YP Q* Tota#YP J  Tra!eY?t)  PrcesYS Q* spTemp   

 

18

Page 19: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 19/31

F& -W The &raph &:es the posto" 9re! Dots; 7here 7e ha:e ope" our posto" o$ tra!"& a"! )e##o7 !ot 7here 7e ha:e stop tra!"&(

  F& W ths &:es the per$orma"ce o$ the retur"s(

Page 20: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 20/31

'.3 &AR TRADN ;SN LBRAR<

 No7 ta5"& t7o !$$ere"t par o$ stoc5s AAPL a"! ??? a"! $"!"& out $ there sco"t&rato" bet7ee" these t7o stoc5s(Ths tme 7e are us"& the Lbrar) ParTra!"& " R(

F& W Sho7s the t7o stoc5s APPL a"! ??? are mo:"& to&ether (

#brar)9ParTra!"&;

 par(prceQ*cb"!9tAAPL3t???;

Here 7e are ta5"& a!juste! :a#ues o$ the t7o stoc5s 7hch "c#u!e the a!justme"t o$the !:!e"!s(

re&1Q*EstmateParameters9par(prce3 metho! M #m;

Estmate Parameters $u"cto" ca#cu#ate the sprea! o$ the t7o stoc5s a"! he!&e rato o$ the t7o stoc5s a"! the premum( Its a pre*!e$"e! $u"cto" " Lbrar) ParTra!"&(

re&1he!&e(rato

 p#ot9re&1sprea!;

20

Page 21: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 21/31

  F&1,W the sprea! o$ the re&resso" o" the prces(

Ths sprea! has bee" ca#cu#ate b) the $o##o7"& $ormu#aSprea! M #o&9); J A#pha [ /eta#o&9=;333333333= a"! ) are stoc5 prces(

 params Q* EstmateParametersHstorca##)9par(prce3

 pero! M 1,;Ths comma"! s use! to &et the :a#ues o$ he!&e rato $rom the pre:ous :a#ues " thscase 7e ha:e ta5e" 1, hstorca# prces to ca#cu#ate the he!&e rato a"! "o7 thesprea! 7## be create! accor!"& to ths he!&e rato"(  p#ot9paramssprea!;

F& 11W Ths the sprea! a$ter &ett"& the he!&e rato $rom the hstorca# :a#ues

s&"a# Q* Smp#e9paramssprea!3,(,0;

s&"a#

Page 22: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 22/31

 barp#ot9s&"a#3co#M^b#ue^3space M ,3 bor!er M

  ^b#ue^3=a=tM^"^3)a=tM^"^3=#abM^^3)#abM^^; par9"e7MTRUE;

  p#ot(ts9paramssprea!3 t)peM^#^3 co# M ^re!^3  #7! M 3 ma" M ^Sprea! S&"a#^;

  ab#"e9h M upperThr3 co# M ^b#ue^3 #7! M 0;

retur"(partra!"& Q* Retur"9par(prce3 #a&9s&"a#;3

#a&9paramshe!&e(rato;;

retur"(partra!"&

 p#ot91,, ` cumpro!91 [ retur"(partra!"&;3

  ma" M ^Per$orma"ce o$ par tra!"&^;

  F& 1W the per$orma"ce o$ the retur"s(

22

Page 23: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 23/31

 

). Res*%ts and Con!%*sion

8e e=am"e a he!&e $u"! e%ut) tra!"& strate&) base! o" the "oto" o$ co*"te&rate!

 prces " a reaso"ab#) e$$ce"t mar5et3 5"o7" as pars tra!"&( Pars are stoc5s 7hchare c#ose substtutes accor!"& to a m"mum !sta"ce crtero" us"& a metrc " prcespace( 8e $"! that tra!"& sutab#) $orme! pars o$ stoc5s e=hbts pro$ts3 7hch arerobust to co"ser:at:e estmates o$ tra"sacto" costs( 8e ha:e mp#eme"te! par tra!"& " R us"& the ?ua"t #brar)3 7e ha:e success$u##) $ou"! out the ope" posto"a"! the c#ose posto"s $or the &:e" stoc5s( A"! sho7e! that the e=pa"so" o$ the

 prce sprea! 7## "crease the retur"(

:. F*t*re S!ope

I" ths project 7e ha:e 7or5e! o" the statc mo!e#3 the he!&e rato s ca#cu#ate! o" the

hstorca# :a#ues o$ the prces a"! the tra!"& strate&) s !ec!e! $or the #ar&e "ter:a#

o$ tme( Rece"t#)3 7th the &ro7"& popu#art) o$ HFT3 :arous stu!es 7hch e=am"e

the app#cab#t) o$ pars tra!"& strate&es to h&h $re%ue"c) e":ro"me"ts ha:e bee"

 per$orme!( /o7e" et a#( 90,1,; e=am"e the se"st:t) o$ h&h $re%ue"c) strate&es to

mar5et attrbutes3 "ot"& that the prmar) retur"s to ther strate&) arse " the $rst hour a"! #ast hour o$ tra!"& !a)s3 7he" tra!"& :o#ume s e=pecte! to be h&hest(

As the $uture scope 7e ca" bu#! the !)"amc mo!e# to ca#cu#ate the he!&e rato!)"amca##) a"! the" cha"&"& our tra!"& strate&) $re%ue"t#) to ma=m>e the pro$t( 

=. Reeren!es

The paper o$ /a5sh3 G( a"! ( Che"3 1-3 4Stoc5 .a#uato" " D)"amcEco"omes36 working paper, OhioState Uniersity!

The #terature o$ DA:o#o3 G(3 0,,03 4The 'ar5et $or /orro7"& Stoc5  ," #ournal o$  %inancial &conomics, '',*-'!

The #terature o$ /ossaerts3 P(3 13 4Commo" No"stato"ar) Compo"e"ts o$ AssetPrces ," #ournal o$ 

Page 24: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 24/31

 &conomic ynamics and .ontrol, *, /-'/!

The #terature o$ @a&a""atha"3 R( a"! S( .s7a"atha"3 13 4L"ear Factor Prc"&3Term Structure o$ I"terest Rates a"! the Sma## Frm A"oma#)36 0orking Paper 1,

 2orthwestern Uniersity!

The #terature o$ Gate:3 Goet>ma""3 a"! Rou7e"horst 90,,+;36  Pars Tra!"&WPer$orma"ce o$ a Re#at:e .a#ue Arbtra&e Ru#e63 3ale 4.% 0orking Paper 2o! 5-!

The #terature o$ Kshore3 .a)u3 ^Optm>"& Pars Tra!"& o$ US E%utes " a H&hFre%ue"c) Sett"&^ 90,10;(0harton 6esearch Scholars #ournal!Paper 0(

httpWdd777(r$ortra!ers(comd 3 $or the R a#&orthm

<ahoo F"a"ce3 to &et the !ata $or !$$ere"t stoc5s((

0. Co!"&(7getting 8etter understanding o$ linear regression

 9:- rnorm(*)

 y:- (9-) + rnorm(*)lmout:- lm(y;9)

 summary(lmout)

7y=-!+!<'9 plot (lmoutresiduals)

7residual error is high it means that the > and 3 are highly corellated 

 plot(lmout)

7also the residual plot is 6andom not $ollowing any patten

res:- lmoutresiduals plot(res,type=?l?)

7 ac$ will the 8et scenario o$ checking wheather the arail8les is corellated

ac$(res)lmoutcoe$$icients

require(quantmod)

 sym8ols :- c(?@42P&A6O!2S?,?BP.C!2S?)7write!cs(BP.C!2S,?BP.C!.SD?)

7write!cs(BP.C!2S,?BP.C!.SD?)

 getSym8ols(sym8ols,$rom=E*-*-*E,to = E*-*-*E)

24

Page 25: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 25/31

 summary(@42P&A6O!2S)

 @42P&A6O!2SF,'G

t@P. :- @42P&A6O!2SF,'G

tBP. :- BP.C!2SF,'G

 plot(t@P.,tBP.)

 plot!ts(t@P.,type=ElE,col=?red?,main = ? Price @P.(6&) s! BP.(Hreen)?,yla8=EId!PriceE,ylim=c(*,1),9lim=c(,*))

 par(new=A6U&)

 plot!ts(tBP.,type=ElE,col=?green?,yla8=EId!PriceE,ylim=c(*,1),9lim=c(,*))

Diew(t@P.)Diew(tBP.)

length(tBP.)length(t@P.)tBP.:- tBP.F*J'G7length(tBP.)

cor(t@P.,tBP.) 7!5*5* 70e will use the data to compute a simple hedge ratio

7and then we will apply this hedge ratio to the out o$ sample data!

7.IC.UCIA& A@& 6&AU62  pdt@P. :- di$$(t@P.)F-*G

 pdtBP. :- di$$(tBP.)F-*G

cor(pdt@P.,pdtBP.)7!< there is corelation

7 the a8oe plot gies the good understanding o$ the relationship o$ 8oth the stocks!

 plot!ts(pdt@P.,type=ElE,col=?red?,main = ? 6&turn @P.(6&) s!

 BP.(Hreen)?,yla8=E6&AU62E,ylim=c(-*1,*1),9lim=c(,*)) par(new=A6U&)

 plot!ts(pdtBP.,type=ElE,col=?green?,yla8=E6&AU62E,ylim=c(-*1,*1),9lim=c(,*))

78uild the model 

length(pdt@P.)length(pdtBP.)

model :- lm(pdt@P. ; pdtBP. -*)

model :- lm(pdtBP. ; pdt@P.,-*) summary(model)

modelcoe$$icientsF*Gres*:- modelresiduals

 plot(res*)

ac$(res*)Kac$ 

modelcoe$$icientshr:- as!numeric(modelcoe$$icientsF*G)

Page 26: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 26/31

hr 

Kac$ 

 spreadLA7spread price (in-sample)7tIIPC = > + hr MtNNN

7 >= tIIPl - hrMtNNN

7 > is nothing 8ut the spread  spreadLA :- t@P. - hr M tBP. 

  $i9(spreadLA)

7 to calculate the mean $o the spread meanA :- as!numeric(mean(spreadLA,na!rm=A6U&)) meanA 

7 to calculate the Standard deeiation $or the spread!

 sdA :- as!numeric(sd(spreadLA,na!rm=A6U&)) sdA 7similarlly calculating the $irst and the second S $or the spread!

upperAhr :- meanA + * M sdA lowerAhr :- meanA - * M sdA 

upperAhr :- meanA + M sdA lowerAhr :- meanA - M sdA 

 sdA upperAhr

lowerAhr

Ka8line plot(spreadLA)

 spreadLA  plot(spreadLA, main = ?@P. s! BP. spread (in-sample period)?)

a8line(h = meanA, col = ?red?, lwd =)

a8line(h = meanA + * M sdA, col = ?8lue?, lwd=*!1)a8line(h = meanA - * M sdA, col = ?8lue?, lwd=*!1)

a8line(h = upperAhr, col = ?8lue?, lwd=)

a8line(h = lowerAhr, col = ?8lue?, lwd=) points(9ts(pricesLB,inde9(spreadLA)), col=?green?, ce9=*!<, pch=*<)

 points(9ts(pricesLS,inde9(spreadLA)), col=?red?, ce9=*!<, pch=*<)

 points(9ts(pricesLB,inde9(spreadLA)), col=?green?, ce9=*!<, pch=*<)

 points(9ts(pricesLS,inde9(spreadLA)), col=?red?, ce9=*!<, pch=*<)

77Once the spread e9ceeds our upper threshold,

7we sell BP.C and 8uy @P.C! Once the spread drops 8elow our lower threshold,7 we 8uy BP.C and sell @P.C!

indLSell :- which!min (spreadLA := meanA + sdA)

 spreadLAF*/G

indLBuy :- (spreadLA = meanA - sdA)

indLSell :- which(spreadLA = meanA + sdA)

indLBuy :- which(spreadLA := meanA - sdA) spreadLAF*/G spreadLAF/<GspreadLAF1/G7 all the alues are a8oe the $irst Sd 

26

Page 27: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 27/31

indLBuy

 spreadLAF*G spreadLAF*1G 7all the alues are 8elow the *sd

 spreadLA  spreadLC :- length(spreadLA)

 pricesLB :- c(rep(2I,spreadLC))

 pricesLS :- c(rep(2I,spreadLC))

 pricesLB pricesLS

 sp :- as!numeric(spreadLA) sp

 spreadLC

Diew(spreadLA)tradeNty:-*

totalP :- tradep:-

 $or (i in *JspreadLC) Q   spAemp:- spFiG  i$(spAemp : lowerAhr) Q 

  i$(totalP := )Q   totalP :- totalP + tradeNty

  pricesLBFiG :- spAemp

  R  R else i$(spAemp upperAhr) Q 

  i$(totalP = )Q   totalP :- totalP - tradeNty

  pricesLSFiG :- spAemp

  R  R

 R

 plot(spreadLA, main = ?IIPC s! NNNN spread (in-sample period)?)

a8line(h = meanA, col = ?red?, lwd =)a8line(h = meanA + * M sdA, col = ?8lue?, lwd = )

a8line(h = meanA - * M sdA, col = ?8lue?, lwd = )

 points(9ts(pricesLB,inde9(spreadLA)), col=?green?, ce9=*!<, pch=*<) points(9ts(pricesLS,inde9(spreadLA)), col=?red?, ce9=*!<, pch=*<)

Kce9 9ts(pricesLB,inde9 (spreadLA) )

Kpoints

7 the B&CO0 .O42H 4S %O6 A@& SAO.S IIPC I2 NNN US42Hli8rary(PairArading)

li8rary(PairArading)

7.OTB4242H A@& P64.&S O% @& A0O SAO.S  pair!price:-c8ind(tIIPC,tNNN)

head(pair!price)

 summary(pair!price)tNNN

Page 28: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 28/31

76U2242H A@& 6&H6&S44O2 O2 A@& COH DICU&S O% A@& A0O SAO.S 

reg*:-&stimateParameters(pair!price, method = lm)

reg* str(reg*)

7COO42H IA A@& h&H& 6IA4O

reg*hedge!ratio7PCOAA42H A@& SP6&I

 plot(reg*spread)ad$!test(reg*spread)

7 US42H A@& %U2.A4O2 AO &SA4TIAA& A@& SP6&I7I2 A@& @&H& 6IA4O 04A@ A@& @4SAO64.IC DICU&S (*5 dI3S)

 params :- &stimateParameters@istorically(pair!price,  period = *5)

7.IC.UCIA42H A@& T&I2 %O6 A@& SP6&I AO &.4& A@& A6I42HSA6IAH3 

meanA :- as!numeric(mean(paramsspread,na!rm=A6U&))meanA 

 sdA:- as!numeric(sd(paramsspread,na!rm=A6U&))

 sdA upperAhr :- meanA + * M sdAupperAhr 

lowerAhr :- meanA - * M sdA 

upperAhr :- meanA + M sdA lowerAhr :- meanA - M sdA 

7PCOA42H A@& SP6&I O% A@& 6&AU62 O% A@& H4D&2 SAO.S!

 plot(paramsspread)

7 H4D42H A@& S4H2IC AO A@& S3SA&T 0@2 AO AI& A@@& POS4A4O2 42

A@& TI6&A

742 A@4S .IS& 0& I6& US42H A@& *SA sd! signal :- Simple(paramsspread,!)

 signal 

8arplot(signal,col=?8lue?,space = , 8order =

  ?8lue?,9a9t=?n?,ya9t=?n?,9la8=??,yla8=??) par(new=A6U&)

 plot!ts(paramsspread, type=?l?, col = ?red?,  lwd = , main = ?Spread Signal?)

a8line(h = upperAhr, col = ?8lue?, lwd = )

a8line(h = lowerAhr, col = ?8lue?, lwd = )

7.IC.UCIA42H A@& 6&AU62 O% A@& A6I&!return!pairtrading :-

  6eturn(pair!price, lag(signal),

  lag(paramshedge!ratio))return!pairtrading 

7PCOA42H A@& 6&AU62 O% A@& A6I&!

 plot(* M cumprod(* +

28

Page 29: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 29/31

  return!pairtrading), main =

  ?Per$ormance o$ pair trading?)

 plot(tIIPC) par(new=A6U&)

 plot(tNNN)

 plot!ts(t@P.,type=ElE,col=?red?,main = ?IIPC(6&) s! NNN(Hreen)?) par(new=A6U&)

 plot(tBP.,type=ElE,col=?green?)

] NO8 INCLUDING THE CODE FOR THE PRE DEFINEDFUNCTION FOR PAIR TRADING7.alculate the spread 8etween two stock prices!

7Issume that log(price) is random walk 

7Issume that prices has two column as matri9 &stimateParameters :- $unction(price!pair, method = lm)

Q   9 :- log(price!pair) 

reg :- method(9F, G ; 9F, *G)  hedge!ratio :- as!numeric(regcoe$FG)

  premium :- as!numeric(regcoe$F*G)

  spread :- 9F, G - (hedge!ratio M 9F, *G + premium)  list(spread = spread, hedge!ratio = hedge!ratio, premium = premium)

 R

 &stimateParameters@istorically :- $unction(price!pair, period, method = lm)Q 

  Ipplied :- $unction(price!pair)Q   reg :- &stimateParameters(price!pair, method)

  c(spread = as!numeric(last(regspread)), hedge!ratio = reghedge!ratio, premium= regpremium)

  R

  as!9ts(rollapplyr(price!pair, period, Ipplied, 8y!column = %ICS&)) R

76eturn wether spread is stationary or not  4sStationary :- $unction(spread, threshold)

Q   4s!passed!PP!test :- PP!test(as!numeric(spread))p!alue := threshold   4s!passed!ad$!test :- ad$!test(as!numeric(spread))p!alue := threshold 

  c(PP!test = 4s!passed!PP!test, ad$!test = 4s!passed!ad$!test) R

 @edge6atio0eight :- $unction(hedge!ratio)

Q   hedge!ratio :- a8s(hedge!ratio) M (-*)

  7   normaliVation!$actor :- * W (* + a8s(hedge!ratio))

  return(c8ind(* M normaliVation!$actor, hedge!ratio M normaliVation!$actor))

 R

Page 30: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 30/31

 6eturn :- $unction(price!pair, signal!lagged, hedge!ratio!lagged)

Q   7 

  signal :- na!omit(c8ind(signal!lagged, -*M(signal!lagged)))

  return!pair :- na!omit(!return(price!pair, type=?discrete?))  weight!pair :- na!omit(@edge6atio0eight(hedge!ratio!lagged))

  7   names(return!pair) :- names(price!pair)

  names(signal) :- names(price!pair)  names(weight!pair) :- names(price!pair)

  7

7as!9ts(apply(signal M weight!pair M return!pair, *, sum) M leerage)  9 :- signal M weight!pair M return!pair 

  i$(Xlength(dim(9)))Q 

  9ts(rep(2I, nrow(price!pair)), order!8y = inde9(price!pair))  RelseQ   9ts(rowSums(9), order!8y = inde9(9))

  R R

!return :- $unction(9, type = c(?continuous?, ?discrete?), na!pad = A6U&)

Q   type :- match!arg(type)

  i$ (type == ?discrete?) Q   result :- 9Wlag(9, na!pad = na!pad) - *

  Relse i$ (type == ?continuous?) Q 

  result :- di$$(log(9), na!pad = na!pad)  R

  return(result)

 RSimple :- $unction(spread, spread!entry)

Q   signal :- i$else(spread = spread!entry, -*, 2I)

  signal :- i$else(spread := -spread!entry, *, signal)

  return(na!loc$(signal)) R

Simple0ithAakePro$it :- $unction(spread, spread!entry, spread!take!pro$it)Q 

  signal :- i$else(spread = a8s(spread!entry), -*, )

  signal :- i$else(spread := -a8s(spread!entry), *, signal) 

take!pro$it!upper :- a8s(spread!take!pro$it)

  take!pro$it!lower :- -take!pro$it!upper 

  7@it take!pro$it line J

  7other case J continue preious position  $or(i in Jnrow(signal))

  Q   i$(signalFiG == )Q 

30

Page 31: The Application of Pairs Trading to Stock Markets

7/23/2019 The Application of Pairs Trading to Stock Markets

http://slidepdf.com/reader/full/the-application-of-pairs-trading-to-stock-markets 31/31

  i$(signalFi - *G == *)Q 

  i$(spreadFiG = take!pro$it!lower)Q 

  signalFiG :-   RelseQ 

  signalFiG :- signalFi - *G

  R  Relse i$(signalFi - *G == -*)Q 

  i$(spreadFiG := take!pro$it!upper)Q   signalFiG :-

  RelseQ   signalFiG :- signalFi - *G

 R

  R  R

  R  return(signal)

 R

MMMMMMMMMMMMMMMMMMMMMMMMMMMM&2 O% 6&PO6AMMMMMMMMMMMMMMMMMMMMMMMMMM