Jovian
⭐️
Sign In

Cointegration Analysis and Estimation

In this report, we test cointegration realtionship between 909 pairs of funds to see if there exists a linear combination of each two funds. There are two approaches used: coint method in statsmodels package, and the Cointegrated Augmented Dickey-Fuller test.

In [17]:
import numpy as np
import pandas as pd
import pandas_datareader.data as web
import datetime
import matplotlib.pyplot as plt
from scipy import integrate
import statsmodels
In [2]:
filepath = 'D:\\650internship\\620\\'
ticker = pd.read_csv(filepath+'portformer_peers2.csv')

We test the stationarity of prices of each two funds and if it is non-stationary and same-order stationary, then test the cointegration.

In [68]:
start = datetime.datetime(2015, 1, 1)
end = datetime.datetime.today()
In [3]:
import statsmodels.api as sm
results1=[]
for t in range(len(ticker)):
    try:
        price1 = web.DataReader(ticker.iloc[t,:][0], 'yahoo', start, end)['Adj Close'].dropna()
        price2 = web.DataReader(ticker.iloc[t,:][1], 'yahoo', start, end)['Adj Close'].dropna()
        ind = list(set(price1.index)&set(price2.index))
        ind.sort()
        price1 = price1[ind]
        price2 = price2[ind]
        p1 = sm.tsa.adfuller(price1)[1]
        p2 = sm.tsa.adfuller(price2)[1]
        if (p1<0.05) or (p2<0.05):
            print(ticker.iloc[t,:].values[:],'Stable process!')
        else:
            pvalue = sm.tsa.coint(price1,price2,trend = 'ct')[1]
            if pvalue<0.05:
                print(ticker.iloc[t,:].values, "has cointegration relationship, P-value is",pvalue)
                results1.append(ticker.iloc[t,:].values)
            else:
                print(ticker.iloc[t,:].values, "no cointegration relationship, P-value is", pvalue)
    except ValueError:
        print(ticker.iloc[t,:])
        continue
['ZSL' 'DZZ'] no cointegration relationship, P-value is 0.36319043325683453 ['ZSL' 'GLL'] no cointegration relationship, P-value is 0.5936996793324224 ['ZROZ' 'EDV'] no cointegration relationship, P-value is 0.12175025124813177 ['ZMLP' 'YMLI'] no cointegration relationship, P-value is 0.9807308407302219 ['ZBIO' 'BIS'] no cointegration relationship, P-value is 0.733935497386862 ['YXI' 'FXP'] no cointegration relationship, P-value is 0.21025119779948503 ['YINN' 'CHN'] no cointegration relationship, P-value is 0.06674400367563942 ['YAO' 'GXC'] no cointegration relationship, P-value is 0.3739575170831512 ['YAO' 'CHN'] has cointegration relationship, P-value is 3.9837863113222315e-06 ['YAO' 'MCHI'] no cointegration relationship, P-value is 0.303744920087978 ['YAO' 'CQQQ'] no cointegration relationship, P-value is 0.7921256823916247 ['YAO' 'FXI'] no cointegration relationship, P-value is 0.9800846695150407 ['YANG' 'CHAD'] no cointegration relationship, P-value is 0.28205611650943424 ['YANG' 'YXI'] has cointegration relationship, P-value is 0.046575556974982606 ['YANG' 'FXP'] no cointegration relationship, P-value is 0.16410522755512735 ['XNTK' 'TDIV'] no cointegration relationship, P-value is 0.8430170248265754 ['XNTK' 'IXN'] no cointegration relationship, P-value is 0.914959584485575 ['XLY' 'IYC'] no cointegration relationship, P-value is 0.3436661616002774 ['XLV' 'VHT'] no cointegration relationship, P-value is 0.3796041329510772 ['XLV' 'IXJ'] has cointegration relationship, P-value is 0.019818962183433216 ['XLU' 'IDU'] no cointegration relationship, P-value is 0.4586973101760718 ['XLU' 'RYU'] no cointegration relationship, P-value is 0.30666805162909283 ['XLP' 'RHS'] no cointegration relationship, P-value is 0.9077882277125651 ['XLP' 'FSTA'] no cointegration relationship, P-value is 0.5173032670979395 ['XLK' 'IXN'] no cointegration relationship, P-value is 0.9635757511396617 ['XLG' 'JKD'] no cointegration relationship, P-value is 0.9011968900614498 ['XLG' 'DLN'] no cointegration relationship, P-value is 0.3828188482840175 ['XLG' 'DIA'] has cointegration relationship, P-value is 0.026955736323116486 ['XLE' 'IXC'] no cointegration relationship, P-value is 0.17397928730207213 ['XHS' 'IHF'] has cointegration relationship, P-value is 0.02530206595890936 ['XHE' 'IHI'] no cointegration relationship, P-value is 0.99822869449746 ['XHE' 'PSCH'] no cointegration relationship, P-value is 0.1481884326288745 ['WPS' 'IFEU'] no cointegration relationship, P-value is 0.591368253021846 ['WBIF' 'WBIG'] no cointegration relationship, P-value is 0.6961214080398193 ['VYM' 'OEF'] no cointegration relationship, P-value is 0.850783028260435 ['VXX' 'VXZ'] no cointegration relationship, P-value is 0.09907342198362112 ['VXX' 'VIXY'] no cointegration relationship, P-value is 0.7290007455740358 ['VXX' 'VIIX'] has cointegration relationship, P-value is 4.544573878485454e-30 ['VXX' 'SDS'] no cointegration relationship, P-value is 0.25372925052729906 ['VXUS' 'WDIV'] no cointegration relationship, P-value is 0.24044371314609309 ['VV' 'MGV'] no cointegration relationship, P-value is 0.6300941546763266 ['VTWV' 'PRFZ'] no cointegration relationship, P-value is 0.9322008923232263 ['VTWV' 'XSLV'] no cointegration relationship, P-value is 0.6244490894796061 ['VTHR' 'ONEQ'] no cointegration relationship, P-value is 0.08936267888480548 ['VT' 'DSI'] no cointegration relationship, P-value is 0.8511454299344112 ['VPU' 'IDU'] no cointegration relationship, P-value is 0.7426214145695796 ['VPL' 'DXJS'] no cointegration relationship, P-value is 0.48629473534275564 ['VPL' 'DBJP'] no cointegration relationship, P-value is 0.8670902487430607 ['VPL' 'GWX'] no cointegration relationship, P-value is 0.6302967833011792 ['VOOV' 'SPYV'] has cointegration relationship, P-value is 9.695605466336872e-10 ['VOOG' 'XLG'] no cointegration relationship, P-value is 0.8073146501074192 ['VOOG' 'VONG'] has cointegration relationship, P-value is 0.0012665516509519554 ['VONG' 'IVV'] no cointegration relationship, P-value is 0.7337175837390761 ['VNQI' 'WPS'] no cointegration relationship, P-value is 0.06513303707166243 ['VNQ' 'FRI'] no cointegration relationship, P-value is 0.9907976142785646 ['VNQ' 'IYR'] no cointegration relationship, P-value is 0.8590397465634766 ['VNQ' 'RWO'] no cointegration relationship, P-value is 0.6866106353021487 ['VLUE' 'RWW'] no cointegration relationship, P-value is 0.30609511895356994 ['VKQ' 'VGM'] no cointegration relationship, P-value is 0.06421610594916215 ['VKQ' 'IQI'] has cointegration relationship, P-value is 0.0012802769309938357 ['VIXY' 'VXZ'] no cointegration relationship, P-value is 0.092389288961914 ['VIXM' 'VXZ'] has cointegration relationship, P-value is 1.2318921403477127e-05 ['VIOV' 'IJS'] has cointegration relationship, P-value is 0.029174988822762274 ['VIOV' 'VIOO'] no cointegration relationship, P-value is 0.8007415226111734 ['VIOV' 'XSLV'] no cointegration relationship, P-value is 0.7763228932468278 ['VIOO' 'SCHA'] no cointegration relationship, P-value is 0.9640297047160777 ['VIIX' 'VXZ'] no cointegration relationship, P-value is 0.09498067553650885 ['VIIX' 'TECS'] no cointegration relationship, P-value is 0.09199186626714217 ['VIIX' 'QID'] no cointegration relationship, P-value is 0.4200163218824099 ['VIG' 'USMV'] no cointegration relationship, P-value is 0.7744124834699313 ['VHT' 'IBB'] has cointegration relationship, P-value is 0.040932953009623664 ['VHT' 'IYH'] no cointegration relationship, P-value is 0.25551533436625734 ['VHT' 'RXL'] no cointegration relationship, P-value is 0.22772583844768435 ['VGLT' 'SPTL'] has cointegration relationship, P-value is 0.006827482877927143 ['VGK' 'IEFA'] no cointegration relationship, P-value is 0.4773278433291047 ['VGIT' 'IEI'] no cointegration relationship, P-value is 0.24024988450683893 ['VEGI' 'MOO'] no cointegration relationship, P-value is 0.9983647848658734 ['UYM' 'SLX'] no cointegration relationship, P-value is 0.2749170780363045 ['UXI' 'PSCI'] no cointegration relationship, P-value is 0.27553914206772157 ['UWM' 'PTH'] no cointegration relationship, P-value is 0.9044831082818617 ['USO' 'RJI'] no cointegration relationship, P-value is 0.8466264259844253 ['USO' 'DBO'] no cointegration relationship, P-value is 0.0519704374964484 ['USO' 'BNO'] has cointegration relationship, P-value is 0.0024171572204648474 ['USO' 'USL'] no cointegration relationship, P-value is 0.64005711596247 ['USLV' 'SIVR'] no cointegration relationship, P-value is 0.1716155334402002 ['USLV' 'SLVP'] has cointegration relationship, P-value is 0.034313084334993436 ['USL' 'DBC'] no cointegration relationship, P-value is 0.6620261960860632 ['URE' 'ICF'] no cointegration relationship, P-value is 0.7064985465351674 ['URE' 'RQI'] has cointegration relationship, P-value is 0.038444358391402166 ['UPW' 'PUI'] no cointegration relationship, P-value is 0.0917447363306183 ['UPW' 'IDU'] no cointegration relationship, P-value is 0.07197314574322064 ['UPW' 'XLU'] no cointegration relationship, P-value is 0.09057341159782162 ['UPW' 'RYU'] no cointegration relationship, P-value is 0.5244729802260045 ['UPW' 'VPU'] no cointegration relationship, P-value is 0.20171515016260788 ['UPRO' 'ZIV'] no cointegration relationship, P-value is 0.23588157592260145 ['UNG' 'UNL'] Stable process! ['ULE' 'FXE'] Stable process! ['UGLD' 'UGL'] has cointegration relationship, P-value is 0.04478768851763236 ['UGL' 'GLDI'] no cointegration relationship, P-value is 0.4077453543184256 ['UGL' 'GLD'] no cointegration relationship, P-value is 0.21613850423522218 ['UGL' 'PHYS'] has cointegration relationship, P-value is 0.0009274432961681314 ['UGL' 'OUNZ'] no cointegration relationship, P-value is 0.19589043156100977 ['UGL' 'SGOL'] no cointegration relationship, P-value is 0.326879007576844 ['UGL' 'GLTR'] no cointegration relationship, P-value is 0.3289789460130825 ['UGA' 'USO'] has cointegration relationship, P-value is 0.013199030258277959 ['UGA' 'BNO'] has cointegration relationship, P-value is 0.040764271292680364 ['UGA' 'USL'] has cointegration relationship, P-value is 0.045017182028160664 ['UDN' 'FXE'] Stable process! ['UCO' 'EWC'] Stable process! ['UBR' 'EWZS'] no cointegration relationship, P-value is 0.056085853665805874
['UBR' 'BRF'] no cointegration relationship, P-value is 0.09859990957788245 ['TZA' 'SDS'] no cointegration relationship, P-value is 0.1626719444054397 ['TZA' 'MZZ'] no cointegration relationship, P-value is 0.09210063363735832 ['TZA' 'SRTY'] no cointegration relationship, P-value is 0.262769224103833 ['TZA' 'MIDZ'] no cointegration relationship, P-value is 0.26972516680043235 ['TYO' 'TMV'] no cointegration relationship, P-value is 0.5209150798696567 ['TYO' 'TBF'] no cointegration relationship, P-value is 0.30481064689866116 ['TYG' 'CEM'] no cointegration relationship, P-value is 0.18827292938226503 ['TYG' 'NTG'] no cointegration relationship, P-value is 0.07480624834591332 ['TYG' 'MLPA'] no cointegration relationship, P-value is 0.27155353687603023 ['TYG' 'YMLI'] has cointegration relationship, P-value is 0.03153913491420063 ['TYG' 'KYN'] no cointegration relationship, P-value is 0.41333473739465487 ['TWM' 'SEF'] no cointegration relationship, P-value is 0.26528751511904913 ['TWM' 'HDGE'] no cointegration relationship, P-value is 0.6536912659757583 ['TWM' 'SH'] no cointegration relationship, P-value is 0.07376637742980577 ['TWM' 'RWM'] no cointegration relationship, P-value is 0.27493557425860976 ['TWM' 'MZZ'] no cointegration relationship, P-value is 0.2687840335536522 ['TVIX' 'VXZ'] Stable process! ['TTT' 'DLBS'] no cointegration relationship, P-value is 0.9500391110757355 ['TTT' 'TYO'] no cointegration relationship, P-value is 0.17630762745450274 ['TTT' 'TMV'] no cointegration relationship, P-value is 0.9784662785032413 ['TTT' 'TBF'] no cointegration relationship, P-value is 0.9764379924202051 ['TTT' 'DTYS'] no cointegration relationship, P-value is 0.6133665786853121 ['TTT' 'TBT'] no cointegration relationship, P-value is 0.9968471114761994 ['TTP' 'FEN'] no cointegration relationship, P-value is 0.6193628467653706 ['TMV' 'DLBS'] no cointegration relationship, P-value is 0.9637332351892903 ['TLTE' 'ADRE'] has cointegration relationship, P-value is 0.007179885834642185 ['TLTD' 'VGK'] no cointegration relationship, P-value is 0.9834341645744676 ['TLT' 'BAB'] no cointegration relationship, P-value is 0.0826809159512022 ['TLT' 'IGLB'] no cointegration relationship, P-value is 0.6465122571264891 ['TLT' 'SPTL'] no cointegration relationship, P-value is 0.4760620941939183 ['TLT' 'BLV'] no cointegration relationship, P-value is 0.5893139321873387 ['TLH' 'IEF'] no cointegration relationship, P-value is 0.09417670602259309 ['TLH' 'BIV'] no cointegration relationship, P-value is 0.3930584689508045 ['TLH' 'GOVT'] no cointegration relationship, P-value is 0.8699318094889411 ['TECS' 'REW'] no cointegration relationship, P-value is 0.6308905263161113 ['TECS' 'QID'] no cointegration relationship, P-value is 0.83061056781105 ['TDTT' 'TDTF'] no cointegration relationship, P-value is 0.32750314760571764 ['TDTF' 'STIP'] no cointegration relationship, P-value is 0.44412413007147616 ['TDIV' 'IXN'] no cointegration relationship, P-value is 0.27308278211083503 ['TDIV' 'IGM'] no cointegration relationship, P-value is 0.4162482802588509 ['TBX' 'PST'] no cointegration relationship, P-value is 0.9942980285374633 ['TBT' 'TYO'] no cointegration relationship, P-value is 0.1335708502984534 ['TBT' 'TMV'] no cointegration relationship, P-value is 0.9985907208670427 ['TBF' 'TBX'] no cointegration relationship, P-value is 0.10057152966436661 ['TBF' 'TMV'] no cointegration relationship, P-value is 0.9957106202156264 ['TBF' 'TBT'] no cointegration relationship, P-value is 0.8410950883145538 ['TAN' 'ICLN'] no cointegration relationship, P-value is 0.11877482259185235 ['SVXY' 'ZIV'] no cointegration relationship, P-value is 0.6746909144548597 ['SRTY' 'MZZ'] no cointegration relationship, P-value is 0.09775548922393523 ['SRTY' 'TWM'] no cointegration relationship, P-value is 0.29401431959573593 ['SRS' 'REK'] no cointegration relationship, P-value is 0.7932420469222703 ['SQQQ' 'REW'] has cointegration relationship, P-value is 0.022758291955553116 ['SQQQ' 'TECS'] no cointegration relationship, P-value is 0.3431652160431249 ['SQQQ' 'QID'] no cointegration relationship, P-value is 0.26098161719585194 ['SQQQ' 'SPXS'] no cointegration relationship, P-value is 0.17142562789467702 ['SQQQ' 'SDS'] has cointegration relationship, P-value is 0.03002174837204521 ['SPXU' 'DXD'] has cointegration relationship, P-value is 0.03414786830189249 ['SPXU' 'SDS'] no cointegration relationship, P-value is 0.5706146317573669 ['SPXU' 'EDZ'] no cointegration relationship, P-value is 0.29968274845300136 ['SPXU' 'PSQ'] no cointegration relationship, P-value is 0.6974001356623485 ['SPXS' 'DOG'] no cointegration relationship, P-value is 0.4390931911197453 ['SPXS' 'DXD'] no cointegration relationship, P-value is 0.24140347241871607 ['SPXS' 'SPXU'] no cointegration relationship, P-value is 0.20099144246775835 ['SPTL' 'BAB'] no cointegration relationship, P-value is 0.1263590956357003 ['SPPP' 'PALL'] no cointegration relationship, P-value is 0.17132170113684198 ['SPLV' 'USMV'] no cointegration relationship, P-value is 0.09268802885694155 ['SPLV' 'ACWV'] no cointegration relationship, P-value is 0.4286100760782129 ['SPHQ' 'IYC'] no cointegration relationship, P-value is 0.5496696543759824 ['SPHD' 'SDOG'] no cointegration relationship, P-value is 0.774176719078242 ['SPHD' 'RYU'] no cointegration relationship, P-value is 0.7846646246814701 ['SOXX' 'SMH'] no cointegration relationship, P-value is 0.5206339535117122 ['SOXX' 'QTEC'] has cointegration relationship, P-value is 0.0017158767769241484 ['SOXS' 'SSG'] no cointegration relationship, P-value is 0.09459679070115157 ['SOXS' 'REW'] no cointegration relationship, P-value is 0.6860239738788003 ['SMN' 'MYY'] has cointegration relationship, P-value is 0.024270647467364754 ['SMN' 'SMDD'] no cointegration relationship, P-value is 0.05091520913209764 ['SMN' 'TWM'] no cointegration relationship, P-value is 0.3409823870755489 ['SMM' 'TTP'] no cointegration relationship, P-value is 0.8574735433709655 ['SMM' 'FEN'] no cointegration relationship, P-value is 0.33937444644858383 ['SMDD' 'HDGE'] no cointegration relationship, P-value is 0.8475565068610235 ['SLYV' 'IJS'] no cointegration relationship, P-value is 0.21042337433272262 ['SLYG' 'IJT'] has cointegration relationship, P-value is 0.0025611111188824976 ['SLYG' 'VIOO'] no cointegration relationship, P-value is 0.8125085218173833 ['SLY' 'IJS'] no cointegration relationship, P-value is 0.7888182532553957 ['SLY' 'VIOO'] has cointegration relationship, P-value is 1.1763483915748187e-12 ['SLY' 'SLYG'] no cointegration relationship, P-value is 0.9292565860814951 ['SLX' 'GUNR'] no cointegration relationship, P-value is 0.9343135024863529 ['SLV' 'SLVO'] Stable process! ['SLV' 'GLTR'] no cointegration relationship, P-value is 0.6510524319423299 ['SIVR' 'SLVO'] Stable process! ['SIVR' 'SLV'] has cointegration relationship, P-value is 2.8360176102908856e-05 ['SIVR' 'GLTR'] no cointegration relationship, P-value is 0.6403285390243267 ['SGOL' 'GLDI'] no cointegration relationship, P-value is 0.9975893223282758 ['SGOL' 'GLD'] no cointegration relationship, P-value is 0.16045939057575043 ['SGOL' 'PHYS'] no cointegration relationship, P-value is 0.07702201103206965 ['SGDJ' 'GDXJ'] no cointegration relationship, P-value is 0.6354853097411282 ['SEF' 'SKF'] no cointegration relationship, P-value is 0.4325074460344897 ['SDY' 'FVD'] no cointegration relationship, P-value is 0.5898479637444751 ['SDS' 'SH'] no cointegration relationship, P-value is 0.1918149774395494 ['SDS' 'PSQ'] no cointegration relationship, P-value is 0.5049165084904419 ['SDS' 'SEF'] no cointegration relationship, P-value is 0.07226698303247985 ['SDS' 'EFZ'] no cointegration relationship, P-value is 0.2676378397444373 ['SDOW' 'DXD'] no cointegration relationship, P-value is 0.6429107356103393 ['SDOW' 'SPXU'] has cointegration relationship, P-value is 0.013136038340993058 ['SDOG' 'DTN'] no cointegration relationship, P-value is 0.5601664301430511 ['SDD' 'TZA'] no cointegration relationship, P-value is 0.23909930396484635 ['SCZ' 'FJP'] no cointegration relationship, P-value is 0.2770033529340824 ['SCZ' 'EFAV'] no cointegration relationship, P-value is 0.9632895570689215 ['SCIN' 'SCIF'] no cointegration relationship, P-value is 0.27169896123109283
['SCIF' 'IFN'] no cointegration relationship, P-value is 0.9965002489547721 ['SCIF' 'INXX'] no cointegration relationship, P-value is 0.8098828382170481 ['SCIF' 'INDA'] no cointegration relationship, P-value is 0.9871689199602578 ['SCIF' 'IIF'] no cointegration relationship, P-value is 0.1954830789675175 ['SCIF' 'EPI'] no cointegration relationship, P-value is 0.8999956875058713 ['SCIF' 'INCO'] no cointegration relationship, P-value is 0.7760023425721426 ['SCHZ' 'TLH'] no cointegration relationship, P-value is 0.702695103522112 ['SCHV' 'DGRW'] no cointegration relationship, P-value is 0.7250145042321499 ['SCHH' 'FRI'] no cointegration relationship, P-value is 0.46312367024618584 ['SCHH' 'IYR'] no cointegration relationship, P-value is 0.8405885253060061 ['SCHH' 'ICF'] no cointegration relationship, P-value is 0.5644939614512196 ['SCHH' 'RWO'] no cointegration relationship, P-value is 0.5040242333418555 ['SCHH' 'VNQ'] no cointegration relationship, P-value is 0.5131405640751551 ['SCHD' 'HDV'] no cointegration relationship, P-value is 0.8245071371001313 ['SCHC' 'EWGS'] has cointegration relationship, P-value is 0.03652491315089644 ['SCHC' 'SCHF'] no cointegration relationship, P-value is 0.9446534968098482 ['SCHA' 'IJT'] no cointegration relationship, P-value is 0.8323389898187463 ['RZG' 'SLYG'] no cointegration relationship, P-value is 0.5733191494907659 ['RZG' 'VIOG'] no cointegration relationship, P-value is 0.6618335726192289 ['RYU' 'IDU'] no cointegration relationship, P-value is 0.5436511905123504 ['RYU' 'VPU'] no cointegration relationship, P-value is 0.5261663516560785 ['RYT' 'IGM'] no cointegration relationship, P-value is 0.24122700631230432 ['RYT' 'QTEC'] no cointegration relationship, P-value is 0.714887701779224 ['RYH' 'IYH'] no cointegration relationship, P-value is 0.15188171694813135 ['RXL' 'SPUU'] no cointegration relationship, P-value is 0.3337336015737314 ['RXL' 'PJP'] has cointegration relationship, P-value is 0.00956136978584499 ['RXL' 'IHE'] Stable process! ['RXL' 'HQL'] no cointegration relationship, P-value is 0.12074946475897219 ['RWR' 'FRI'] no cointegration relationship, P-value is 0.11727820341768602 ['RWR' 'IYR'] no cointegration relationship, P-value is 0.8254306406445151 ['RWR' 'ICF'] no cointegration relationship, P-value is 0.5926743846887235 ['RWR' 'RWO'] no cointegration relationship, P-value is 0.4957996020177706 ['RWR' 'VNQ'] no cointegration relationship, P-value is 0.4493277424920749 ['RWR' 'SCHH'] has cointegration relationship, P-value is 0.04995683816690512 ['RWO' 'IYR'] has cointegration relationship, P-value is 0.038574752251674504 ['RWM' 'HDGE'] no cointegration relationship, P-value is 0.8058589089341154 ['RWM' 'MYY'] no cointegration relationship, P-value is 0.22482909169065818 ['RWL' 'IVV'] no cointegration relationship, P-value is 0.27086926262907673 ['RWL' 'QDF'] no cointegration relationship, P-value is 0.8241212746936923 ['RSXJ' 'RSX'] no cointegration relationship, P-value is 0.8862777711775898 ['RSXJ' 'ERUS'] no cointegration relationship, P-value is 0.9933781717591116 ['RSP' 'SCHX'] no cointegration relationship, P-value is 0.40435891903243837 ['RSP' 'IWS'] no cointegration relationship, P-value is 0.948523582752798 ['RSP' 'SDY'] no cointegration relationship, P-value is 0.859017321561963 ['RPV' 'SDOG'] no cointegration relationship, P-value is 0.8267529207747704 ['RPV' 'FTA'] no cointegration relationship, P-value is 0.5174620134935669 ['RPV' 'JKI'] no cointegration relationship, P-value is 0.7869016040319257 ['RPG' 'DDM'] no cointegration relationship, P-value is 0.21599768124032365 ['RNP' 'RQI'] no cointegration relationship, P-value is 0.30498543011933293 ['RJN' 'UGA'] no cointegration relationship, P-value is 0.08901294422262823 ['RHS' 'VDC'] no cointegration relationship, P-value is 0.6486579480914179 ['REZ' 'FRI'] no cointegration relationship, P-value is 0.9682265016388649 ['REZ' 'IYR'] no cointegration relationship, P-value is 0.742588110440537 ['REZ' 'PSR'] no cointegration relationship, P-value is 0.8059564390665788 ['REZ' 'RWR'] no cointegration relationship, P-value is 0.9043958717615748 ['REZ' 'ICF'] no cointegration relationship, P-value is 0.39596884274996674 ['REZ' 'VNQ'] no cointegration relationship, P-value is 0.8742002012839333 ['REZ' 'SCHH'] no cointegration relationship, P-value is 0.8983391245138662 ['REW' 'SSG'] no cointegration relationship, P-value is 0.0564016083077261 ['REW' 'QID'] has cointegration relationship, P-value is 0.0336251147134979 ['REW' 'PSQ'] no cointegration relationship, P-value is 0.8342242627390731 ['RETL' 'PMR'] Stable process! ['QUAL' 'JKD'] no cointegration relationship, P-value is 0.7735340696330011 ['QTEC' 'XNTK'] no cointegration relationship, P-value is 0.6151567121769146 ['QTEC' 'IGV'] no cointegration relationship, P-value is 0.8230819414847292 ['QQQE' 'XNTK'] no cointegration relationship, P-value is 0.7645230053498813 ['QQEW' 'ONEQ'] no cointegration relationship, P-value is 0.5079683297036891 ['QQEW' 'SOXX'] has cointegration relationship, P-value is 0.02825472747776174 ['QQEW' 'QQXT'] no cointegration relationship, P-value is 0.3780807766132401 ['QLTA' 'TLH'] no cointegration relationship, P-value is 0.39424494980816555 ['QLTA' 'BLV'] no cointegration relationship, P-value is 0.14230302969383496 ['QID' 'PSQ'] no cointegration relationship, P-value is 0.4701118429077331 ['QID' 'SH'] no cointegration relationship, P-value is 0.054183840194809214 ['QABA' 'XSLV'] no cointegration relationship, P-value is 0.3604206632737293 ['PXQ' 'XTL'] no cointegration relationship, P-value is 0.6933639405460699 ticker PXMG peers ARKW Name: 295, dtype: object ['PXI' 'PEO'] no cointegration relationship, P-value is 0.4223341538329411 ['PXH' 'EWX'] no cointegration relationship, P-value is 0.4661405579300719 ['PXH' 'FNDE'] no cointegration relationship, P-value is 0.4058587301513726 ['PXE' 'IEO'] no cointegration relationship, P-value is 0.5328513292676046 ['PUI' 'IDU'] no cointegration relationship, P-value is 0.08058676722922353 ['PUI' 'XLU'] no cointegration relationship, P-value is 0.05087642595194264 ['PUI' 'RYU'] no cointegration relationship, P-value is 0.10253756686220072 ['PUI' 'VPU'] no cointegration relationship, P-value is 0.12421652195225791 ['PTH' 'FXH'] no cointegration relationship, P-value is 0.22606629117419735 ['PST' 'TBF'] no cointegration relationship, P-value is 0.29124963127381637 ['PST' 'TBT'] no cointegration relationship, P-value is 0.3474316550811308 ['PSCU' 'PUI'] no cointegration relationship, P-value is 0.9298699864310622 ['PSCF' 'XSLV'] no cointegration relationship, P-value is 0.3092155226785919 ['PRFZ' 'SLYG'] no cointegration relationship, P-value is 0.7720682591543342 ['PRFZ' 'IJS'] no cointegration relationship, P-value is 0.7640056517139068 ['PPA' 'IYJ'] no cointegration relationship, P-value is 0.8943060181819923 ['PNQI' 'FDN'] no cointegration relationship, P-value is 0.8579328649980185 ['PNQI' 'SKYY'] no cointegration relationship, P-value is 0.8089715884755393 ['PLW' 'TLT'] no cointegration relationship, P-value is 0.675452730804122 ['PJP' 'IHE'] Stable process! ['PIZ' 'EWGS'] no cointegration relationship, P-value is 0.9316660565221054 ['PICK' 'SLX'] no cointegration relationship, P-value is 0.7758592493127767 ['PICK' 'KOL'] no cointegration relationship, P-value is 0.13871284321267935 ['PICB' 'BWZ'] no cointegration relationship, P-value is 0.28964452279755815 ['PICB' 'IGOV'] no cointegration relationship, P-value is 0.5061288723042776 ['PHYS' 'DGL'] has cointegration relationship, P-value is 0.00152100035039963 ['PHYS' 'GLDI'] no cointegration relationship, P-value is 0.9594444081753275 ['PHYS' 'GLD'] has cointegration relationship, P-value is 0.025541654889574918 ['PGJ' 'CQQQ'] no cointegration relationship, P-value is 0.1442249014150664 ['PFM' 'VIG'] no cointegration relationship, P-value is 0.6459709239817838 ['PFM' 'SCHD'] no cointegration relationship, P-value is 0.9912715608428971 ['PFM' 'HDV'] no cointegration relationship, P-value is 0.7826284615481647 ['PEY' 'IWS'] no cointegration relationship, P-value is 0.8300441960152847 ['PEY' 'SPHD'] no cointegration relationship, P-value is 0.3665567534501945
['PEY' 'XMLV'] no cointegration relationship, P-value is 0.8731293703730725 ['PEO' 'IXC'] no cointegration relationship, P-value is 0.1423863893310522 ['PEO' 'XLE'] no cointegration relationship, P-value is 0.5527640709813855 ['PEK' 'ASHS'] no cointegration relationship, P-value is 0.19904671326128487 ['OUNZ' 'DGL'] no cointegration relationship, P-value is 0.8120898177844449 ['OUNZ' 'GLDI'] no cointegration relationship, P-value is 0.9971051843954477 ['OUNZ' 'GLD'] has cointegration relationship, P-value is 0.0 ['OUNZ' 'PHYS'] has cointegration relationship, P-value is 0.023009273332912014 ['OUNZ' 'SGOL'] has cointegration relationship, P-value is 0.0 ['ONEQ' 'QQQ'] no cointegration relationship, P-value is 0.1873875203389882 ['OILNF' 'USO'] has cointegration relationship, P-value is 0.00019736518830013408 ['OILNF' 'RJN'] no cointegration relationship, P-value is 0.7484836527443786 ['OILNF' 'UGA'] no cointegration relationship, P-value is 0.676902521829591 ['OEF' 'DIA'] no cointegration relationship, P-value is 0.07354854055577463 ['OEF' 'XLG'] no cointegration relationship, P-value is 0.09655470311790537 ['OEF' 'JKD'] no cointegration relationship, P-value is 0.8487770088917882 ['OEF' 'IWL'] no cointegration relationship, P-value is 0.22502704508346938 ['OEF' 'IVV'] has cointegration relationship, P-value is 0.019325912100445333 ['NTG' 'CEM'] no cointegration relationship, P-value is 0.8322061528481197 ['MZZ' 'SEF'] no cointegration relationship, P-value is 0.31086433188637164 ['MZZ' 'MYY'] no cointegration relationship, P-value is 0.14995856198990737 ['MZZ' 'SH'] no cointegration relationship, P-value is 0.22425147627378011 ['MZZ' 'RWM'] no cointegration relationship, P-value is 0.32465037154052756 ['MXE' 'EWW'] Stable process! ['MVV' 'IAT'] no cointegration relationship, P-value is 0.20100975172664443 ['MUC' 'MCA'] has cointegration relationship, P-value is 0.03462560227465998 ['MTUM' 'PWB'] no cointegration relationship, P-value is 0.6073486014863325 ['MLPX' 'EMLP'] no cointegration relationship, P-value is 0.6360759158111082 ['MLPI' 'TYG'] no cointegration relationship, P-value is 0.3372812836672162 ['MLPI' 'AMLP'] has cointegration relationship, P-value is 0.04078250051711167 ['MLPG' 'MLPA'] no cointegration relationship, P-value is 0.8890788758300487 ['MLPG' 'YMLI'] no cointegration relationship, P-value is 0.2530302118321467 ['MLPA' 'NTG'] no cointegration relationship, P-value is 0.8941201805381677 ['MLPA' 'YMLI'] no cointegration relationship, P-value is 0.4962263367291832 ['MLPA' 'MLPX'] has cointegration relationship, P-value is 0.014061764827188648 ['MIE' 'NML'] has cointegration relationship, P-value is 0.0017216361428055963 ['MIE' 'MLPX'] no cointegration relationship, P-value is 0.20918879906294446 ['MIDZ' 'SMN'] no cointegration relationship, P-value is 0.07282468396464638 ['MIDZ' 'HDGE'] no cointegration relationship, P-value is 0.863262367781037 ['MIDZ' 'MYY'] no cointegration relationship, P-value is 0.2950433167652157 ['MIDZ' 'MZZ'] no cointegration relationship, P-value is 0.2335355533865175 ['MIDZ' 'SMDD'] no cointegration relationship, P-value is 0.23335518379346898 ['MIDZ' 'TWM'] no cointegration relationship, P-value is 0.6271438003254908 ['MGV' 'VYM'] no cointegration relationship, P-value is 0.8583485825118458 ['MGV' 'SCHV'] no cointegration relationship, P-value is 0.8804341840412389 ['MGV' 'IVV'] no cointegration relationship, P-value is 0.32735243979231277 ['MGK' 'VONG'] no cointegration relationship, P-value is 0.501905138469467 ['MGC' 'QDEF'] no cointegration relationship, P-value is 0.23143802001543362 ['MDY' 'JKI'] no cointegration relationship, P-value is 0.8171728807051581 ['MDY' 'IVOV'] no cointegration relationship, P-value is 0.6324029562337745 ['MCHI' 'EWH'] no cointegration relationship, P-value is 0.2448439063522383 ['MCHI' 'EEMA'] no cointegration relationship, P-value is 0.43483230828064223 ['MCHI' 'AAXJ'] no cointegration relationship, P-value is 0.3088273524322117 ['MCHI' 'CHIX'] no cointegration relationship, P-value is 0.29614085813286384 ['LTPZ' 'EDV'] no cointegration relationship, P-value is 0.7042527399482723 ['LABU' 'BBC'] Stable process! ['LABU' 'SBIO'] Stable process! ['LABD' 'BIS'] no cointegration relationship, P-value is 0.641899070330581 ['KYN' 'KMF'] has cointegration relationship, P-value is 0.009720920904253931 ['KYN' 'NTG'] no cointegration relationship, P-value is 0.8425299580442593 ['KYN' 'AMLP'] no cointegration relationship, P-value is 0.24389231458064764 ['KYN' 'YMLI'] no cointegration relationship, P-value is 0.6065785025860877 ['KYN' 'MIE'] has cointegration relationship, P-value is 0.016683508054379292 ['KYN' 'AMJ'] no cointegration relationship, P-value is 0.1189552637667135 ['KXI' 'IYK'] no cointegration relationship, P-value is 0.3289752274410517 ['KRE' 'KBE'] no cointegration relationship, P-value is 0.8877544003985366 ['KRE' 'QABA'] no cointegration relationship, P-value is 0.7509131305475345 ['KMF' 'NDP'] no cointegration relationship, P-value is 0.9952482060689845 ['KMF' 'FEN'] no cointegration relationship, P-value is 0.5021825691768934 ['KBWY' 'ROOF'] no cointegration relationship, P-value is 0.9701830778238864 ['KBWB' 'RWW'] no cointegration relationship, P-value is 0.8442708572581876 ['KBWB' 'IAT'] no cointegration relationship, P-value is 0.3115911626581424 ['KBE' 'IAT'] no cointegration relationship, P-value is 0.06969023277702761 ['KBA' 'PEK'] no cointegration relationship, P-value is 0.8694162437136043 ['KBA' 'CNXT'] no cointegration relationship, P-value is 0.1930899088952609 ['KBA' 'ASHR'] no cointegration relationship, P-value is 0.82759050238562 ['JXI' 'FUTY'] no cointegration relationship, P-value is 0.6103554310650869 ['JXI' 'IDU'] no cointegration relationship, P-value is 0.6476978186406815 ['JXI' 'RYU'] no cointegration relationship, P-value is 0.6726226927809533 ['JPXN' 'JPN'] Stable process! ['JPNL' 'JEQ'] no cointegration relationship, P-value is 0.5536063064052376 ['JPNL' 'SCJ'] no cointegration relationship, P-value is 0.7677154551837639 ['JPNL' 'JPMV'] no cointegration relationship, P-value is 0.058549443352901076 ['JPNL' 'DXJ'] no cointegration relationship, P-value is 0.6722538505487415 ['JPNL' 'DBJP'] no cointegration relationship, P-value is 0.8657604739265168 ['JPNL' 'DXJS'] no cointegration relationship, P-value is 0.4126640484392198 ['JNUG' 'GDXJ'] no cointegration relationship, P-value is 0.37256133966106725 ['JKI' 'PEY'] no cointegration relationship, P-value is 0.8006084230127707 ['JKF' 'SPYV'] no cointegration relationship, P-value is 0.1980620839080225 ['JKE' 'MGK'] no cointegration relationship, P-value is 0.9462360562389461 ['JKE' 'IWY'] no cointegration relationship, P-value is 0.8579232381919984 ['JKD' 'DGRW'] no cointegration relationship, P-value is 0.9064731567391203 ['JJGTF' 'GRU'] no cointegration relationship, P-value is 0.6019713379544276 ['JJGTF' 'RJA'] no cointegration relationship, P-value is 0.4580873341234516 ['JJGTF' 'SOYB'] no cointegration relationship, P-value is 0.41001986000273893 ['JJGTF' 'WEAT'] no cointegration relationship, P-value is 0.8139473972234631 ['JJATF' 'RJA'] no cointegration relationship, P-value is 0.14108886858918496 ['IYZ' 'VOX'] Stable process! ['IYM' 'XLB'] no cointegration relationship, P-value is 0.9766667948520221 ['IYK' 'VDC'] no cointegration relationship, P-value is 0.8976663760462347 ['IYJ' 'IWP'] no cointegration relationship, P-value is 0.9310820542833599 ['IYG' 'IYF'] no cointegration relationship, P-value is 0.29465915241551643 ['IYG' 'VFH'] no cointegration relationship, P-value is 0.9263332141216113 ['IYF' 'FXO'] no cointegration relationship, P-value is 0.8096073811481732 ['IYE' 'XLE'] no cointegration relationship, P-value is 0.6424394560809304 ['IXUS' 'SCZ'] no cointegration relationship, P-value is 0.8079123542794819 ['IXP' 'IYZ'] Stable process! ['IXJ' 'FBT'] no cointegration relationship, P-value is 0.07847652340767519 ['IXJ' 'IYH'] no cointegration relationship, P-value is 0.2734697115740993 ['IWY' 'VONG'] no cointegration relationship, P-value is 0.593068864199409 ['IWY' 'XLG'] no cointegration relationship, P-value is 0.7083096542159162 ['IWY' 'VOOG'] no cointegration relationship, P-value is 0.09928069081395319
['IWV' 'IWF'] no cointegration relationship, P-value is 0.7768140745577867 ['IWP' 'ONEQ'] no cointegration relationship, P-value is 0.9687064712640654 ['IWO' 'VXF'] no cointegration relationship, P-value is 0.44673038020070543 ['IWO' 'SCHA'] no cointegration relationship, P-value is 0.8816356148684554 ['IWN' 'FNDA'] no cointegration relationship, P-value is 0.9221176471543779 ['IWN' 'XSLV'] no cointegration relationship, P-value is 0.5476677678155539 ['IWN' 'VIOO'] no cointegration relationship, P-value is 0.9584861031685297 ['IWN' 'IJS'] no cointegration relationship, P-value is 0.8416642101545442 ['IWM' 'VXF'] no cointegration relationship, P-value is 0.9903283722165424 ['IWM' 'VIOO'] no cointegration relationship, P-value is 0.8455256898525485 ['IWM' 'IJT'] no cointegration relationship, P-value is 0.820051356045347 ['IWL' 'DGRW'] no cointegration relationship, P-value is 0.5359420312928576 ['IWL' 'JKD'] no cointegration relationship, P-value is 0.9384108816981633 ['IWL' 'XLG'] no cointegration relationship, P-value is 0.11371452252548031 ['IWL' 'DIA'] no cointegration relationship, P-value is 0.4915319594350225 ['IWF' 'VOOG'] has cointegration relationship, P-value is 0.0007130492945973448 ['IWF' 'IWY'] no cointegration relationship, P-value is 0.4674694209034544 ['IWD' 'IWB'] no cointegration relationship, P-value is 0.8394053964860253 ['IWD' 'CSM'] no cointegration relationship, P-value is 0.5945604814706832 ['IVW' 'VOOG'] has cointegration relationship, P-value is 5.732487110769991e-06 ['IVW' 'IWY'] no cointegration relationship, P-value is 0.07966866167139774 ['IVW' 'OEF'] no cointegration relationship, P-value is 0.8086010905073562 ['IVV' 'USMV'] no cointegration relationship, P-value is 0.9709241315857903 ['IVOG' 'FAD'] no cointegration relationship, P-value is 0.9304917153335752 ['IVE' 'VTV'] no cointegration relationship, P-value is 0.39547109574777795 ['IUSG' 'ITOT'] no cointegration relationship, P-value is 0.9063600619678982 ['ITE' 'BSV'] no cointegration relationship, P-value is 0.14524695312758684 ['ITE' 'GOVT'] no cointegration relationship, P-value is 0.6939121853348468 ['ITE' 'VGIT'] no cointegration relationship, P-value is 0.9747876409664308 ['ITA' 'PPA'] no cointegration relationship, P-value is 1.0 ['ISRA' 'EIS'] no cointegration relationship, P-value is 0.474091792319658 ['ISHG' 'IBND'] no cointegration relationship, P-value is 0.23053574716624475 ['IQDF' 'DWM'] no cointegration relationship, P-value is 0.6533519928119004 ['INXX' 'INDA'] no cointegration relationship, P-value is 0.9753840278788932 ['INXX' 'IIF'] no cointegration relationship, P-value is 0.17891800457231533 ['INXX' 'EPI'] no cointegration relationship, P-value is 0.6923085104523508 ['INXX' 'INCO'] no cointegration relationship, P-value is 0.5671831265727169 ['INXX' 'INDY'] no cointegration relationship, P-value is 0.9832406645158266 ['INPTF' 'INXX'] no cointegration relationship, P-value is 0.6452583970479284 ['INPTF' 'INDA'] no cointegration relationship, P-value is 0.19419232407574916 ['INPTF' 'IIF'] no cointegration relationship, P-value is 0.6772040701802858 ['INPTF' 'SCIF'] no cointegration relationship, P-value is 0.6980469284755455 ['INPTF' 'EPI'] no cointegration relationship, P-value is 0.7791039000540037 ['INPTF' 'INCO'] no cointegration relationship, P-value is 0.7510789494445973 ['INPTF' 'INDY'] no cointegration relationship, P-value is 0.14455203675536993 ['INDA' 'IIF'] no cointegration relationship, P-value is 0.5894716697497542 ['INDA' 'INDY'] has cointegration relationship, P-value is 0.015064886288684607 ['INCO' 'INDA'] no cointegration relationship, P-value is 0.9720397304436408 ['INCO' 'IIF'] no cointegration relationship, P-value is 0.5504003889980873 ['INCO' 'EPI'] no cointegration relationship, P-value is 0.7122150064062117 ['INCO' 'INDY'] no cointegration relationship, P-value is 0.9719035033843753 ['IMLP' 'MLPY'] has cointegration relationship, P-value is 0.005318924437472543 ['IMLP' 'MLPA'] no cointegration relationship, P-value is 0.7926472514057135 ['IMLP' 'EMLP'] no cointegration relationship, P-value is 0.5867043733561729 ['IMLP' 'MLPG'] no cointegration relationship, P-value is 0.9332605630945999 ['IMLP' 'AMLP'] no cointegration relationship, P-value is 0.11759607245831838 ['IMLP' 'YMLI'] no cointegration relationship, P-value is 0.9676421896870153 ['IJT' 'VXF'] no cointegration relationship, P-value is 0.9384346743885802 ['IJS' 'XSLV'] no cointegration relationship, P-value is 0.7668869455962368 ['IJK' 'IJH'] no cointegration relationship, P-value is 0.7585010256154083 ['IIF' 'INDY'] no cointegration relationship, P-value is 0.9870972739856098 ['IHI' 'RYH'] no cointegration relationship, P-value is 0.5231560099845463 ['IHE' 'PPH'] Stable process! ['IHE' 'BBC'] Stable process! ['IHE' 'IXJ'] Stable process! ['IGM' 'ONEQ'] no cointegration relationship, P-value is 0.3934226517491881 ['IGM' 'QQQ'] no cointegration relationship, P-value is 0.30005586202395407 ['IGM' 'IXN'] no cointegration relationship, P-value is 0.9246210531640799 ['IGLB' 'CORP'] no cointegration relationship, P-value is 0.202145217868481 ['IGLB' 'QLTA'] no cointegration relationship, P-value is 0.6295860004091859 ['IGE' 'IXC'] no cointegration relationship, P-value is 0.6081865480438402 ['IGE' 'IYE'] no cointegration relationship, P-value is 0.6506985161202196 ['IGE' 'VDE'] no cointegration relationship, P-value is 0.6768376029748413 ['IGE' 'XLE'] no cointegration relationship, P-value is 0.24533397343876628 ['IGD' 'CHW'] no cointegration relationship, P-value is 0.28301617259541034 ['IFN' 'IIF'] no cointegration relationship, P-value is 0.7971461398454778 ['IFGL' 'WPS'] no cointegration relationship, P-value is 0.8992029313867326 ['IFGL' 'IFEU'] no cointegration relationship, P-value is 0.557166847462702 ['IEV' 'VGK'] no cointegration relationship, P-value is 0.6560423572593913 ['IEV' 'FEUZ'] no cointegration relationship, P-value is 0.8513821502694391 ['IEUS' 'FGM'] no cointegration relationship, P-value is 0.05691555019175401 ['IEUS' 'FKU'] no cointegration relationship, P-value is 0.9859658337928829 ['IEO' 'IYE'] no cointegration relationship, P-value is 0.40880884329871237 ['IEO' 'RYE'] no cointegration relationship, P-value is 0.9255118013386727 ['IEO' 'XLE'] no cointegration relationship, P-value is 0.578568859388954 ['IEO' 'PEO'] no cointegration relationship, P-value is 0.6613251493333071 ['IEMG' 'EEMV'] no cointegration relationship, P-value is 0.9866207506661195 ['IEMG' 'EWX'] no cointegration relationship, P-value is 0.27756889266777823 ['IEMG' 'IXUS'] no cointegration relationship, P-value is 0.12044263973866248 ['IEI' 'BSV'] no cointegration relationship, P-value is 0.46742780327293376 ['IEF' 'IEI'] no cointegration relationship, P-value is 0.23337401420845888 ['IEF' 'BIV'] no cointegration relationship, P-value is 0.6861812087539332 ['IEF' 'VGIT'] no cointegration relationship, P-value is 0.3206217023793817 ['IDX' 'EIDO'] has cointegration relationship, P-value is 0.04840840042390589 ['IDV' 'DIM'] no cointegration relationship, P-value is 0.44159303983037995 ['IDV' 'TLTD'] no cointegration relationship, P-value is 0.41730726580613653 ['IDV' 'IEV'] no cointegration relationship, P-value is 0.5319884057619887 ['IDV' 'EFAV'] no cointegration relationship, P-value is 0.5170816572394701 ['IDLV' 'DIM'] no cointegration relationship, P-value is 0.9707676585529614 ['IDLV' 'IDV'] no cointegration relationship, P-value is 0.9716680511051315 ['IDLV' 'EWA'] no cointegration relationship, P-value is 0.3154106827830619 ['ICF' 'IYR'] no cointegration relationship, P-value is 0.7318414962081907 ['ICF' 'RWO'] no cointegration relationship, P-value is 0.845955139495878 ['ICF' 'VNQ'] no cointegration relationship, P-value is 0.9182741420285071 ['IBND' 'UDN'] Stable process! ['IBND' 'FXE'] Stable process! ['IAU' 'GLDI'] no cointegration relationship, P-value is 0.9929775929989094 ['IAU' 'UGL'] no cointegration relationship, P-value is 0.21572660124071652 ['IAK' 'KIE'] no cointegration relationship, P-value is 0.1549721974469342 ['IAI' 'IYG'] no cointegration relationship, P-value is 0.07911124639914185 ['IAI' 'VFH'] no cointegration relationship, P-value is 0.48081901753982553
['HYG' 'JNK'] has cointegration relationship, P-value is 0.02141737488395105 ['HQH' 'HQL'] Stable process! ['HEWJ' 'EZJ'] no cointegration relationship, P-value is 0.8183530068846453 ['HEWJ' 'DXJ'] no cointegration relationship, P-value is 0.8981717100435113 ['HEWJ' 'DBJP'] no cointegration relationship, P-value is 0.6700206851223924 ['HEWJ' 'DXJS'] no cointegration relationship, P-value is 0.9771428579934506 ['HEFA' 'DBAW'] no cointegration relationship, P-value is 0.08633288889240232 ['HEDJ' 'EWG'] no cointegration relationship, P-value is 0.4728047092262502 ['HDLV' 'RDIV'] no cointegration relationship, P-value is 0.759783393113951 ['HDGE' 'MYY'] no cointegration relationship, P-value is 0.07106166570893534 ['HAP' 'GUNR'] has cointegration relationship, P-value is 0.017803932452783888 ['HAP' 'RLY'] no cointegration relationship, P-value is 0.1392999127553673 ['HAP' 'RYE'] no cointegration relationship, P-value is 0.4548871216944193 ['GXC' 'EWH'] no cointegration relationship, P-value is 0.44450163462093517 ['GXC' 'GMF'] no cointegration relationship, P-value is 0.1461173803069536 ['GXC' 'MCHI'] no cointegration relationship, P-value is 0.7742477188183887 ['GXC' 'CQQQ'] no cointegration relationship, P-value is 0.6741600493961717 ['GWX' 'SCZ'] no cointegration relationship, P-value is 0.6509800936794532 ['GUNR' 'COPX'] no cointegration relationship, P-value is 0.5698473072174253 ['GUNR' 'RLY'] no cointegration relationship, P-value is 0.09687180981021376 ['GSP' 'USO'] no cointegration relationship, P-value is 0.31778906247914374 ['GSP' 'DBO'] no cointegration relationship, P-value is 0.15872977479384803 ['GSP' 'UGA'] has cointegration relationship, P-value is 0.013428858615638011 ['GSP' 'USL'] no cointegration relationship, P-value is 0.18220297332146645 ['GOVT' 'IEI'] no cointegration relationship, P-value is 0.3385341227403246 ['GNR' 'GUNR'] no cointegration relationship, P-value is 0.9900328168065802 ['GMF' 'EEMV'] no cointegration relationship, P-value is 0.8776519704097452 ['GMF' 'AAXJ'] has cointegration relationship, P-value is 0.0037964743139583313 ['GLTR' 'DGL'] no cointegration relationship, P-value is 0.21941474545878603 ['GLTR' 'GLDI'] no cointegration relationship, P-value is 0.3150466842172516 ['GLTR' 'GLD'] no cointegration relationship, P-value is 0.17547152021204726 ['GLTR' 'PHYS'] no cointegration relationship, P-value is 0.10039639486094637 ['GLTR' 'OUNZ'] no cointegration relationship, P-value is 0.21066135727746776 ['GLTR' 'SGOL'] no cointegration relationship, P-value is 0.22742668859405285 ['GLO' 'GLQ'] no cointegration relationship, P-value is 0.5257946515642847 ['GLL' 'DGZ'] has cointegration relationship, P-value is 0.03375909796183399 ['GLL' 'DZZ'] has cointegration relationship, P-value is 1.2376367185618124e-06 ['GLL' 'DUST'] no cointegration relationship, P-value is 0.3424656074882255 ['GLD' 'GLDI'] no cointegration relationship, P-value is 0.9931554435914339 ['GER' 'GMZ'] has cointegration relationship, P-value is 0.000912870545707679 ['GDXS' 'DUST'] no cointegration relationship, P-value is 0.522041582670386 ['FYX' 'EES'] no cointegration relationship, P-value is 0.6049561950846214 ['FXU' 'PUI'] no cointegration relationship, P-value is 0.767668605313776 ['FXU' 'IDU'] no cointegration relationship, P-value is 0.8470337677430583 ['FXU' 'RYU'] no cointegration relationship, P-value is 0.9850358316099643 ['FXU' 'VPU'] no cointegration relationship, P-value is 0.8720571137163708 ['FXP' 'EUM'] no cointegration relationship, P-value is 0.07015373817366514 ['FXP' 'EDZ'] no cointegration relationship, P-value is 0.28106971214840565 ['FXN' 'PEO'] no cointegration relationship, P-value is 0.5216933986070593 ['FXN' 'RYE'] no cointegration relationship, P-value is 0.9265111515465443 ['FXN' 'IEO'] no cointegration relationship, P-value is 0.38798803024583867 ['FXL' 'IGM'] no cointegration relationship, P-value is 0.5523511102624447 ['FXL' 'QTEC'] no cointegration relationship, P-value is 0.9679366014422929 ['FXL' 'ARKK'] no cointegration relationship, P-value is 0.5419538800255798 ['FXI' 'EWH'] no cointegration relationship, P-value is 0.10977830766356483 ['FXI' 'GMF'] no cointegration relationship, P-value is 0.347261480902114 ['FXI' 'AIA'] no cointegration relationship, P-value is 0.5677441955523165 ['FXI' 'CHN'] no cointegration relationship, P-value is 0.17476028922218445 ['FXI' 'MCHI'] no cointegration relationship, P-value is 0.5350796043470814 ['FXH' 'RYH'] no cointegration relationship, P-value is 0.10457505721308064 ['FXH' 'IBB'] no cointegration relationship, P-value is 0.06207290469426205 ['FVD' 'ACWV'] no cointegration relationship, P-value is 0.5367870509566909 ['FVD' 'USMV'] no cointegration relationship, P-value is 0.8566573401043864 ['FVD' 'DHS'] no cointegration relationship, P-value is 0.8448671557829943 ['FUTY' 'VPU'] no cointegration relationship, P-value is 0.16913934536976738 ['FTCS' 'IVV'] no cointegration relationship, P-value is 0.22992317564003184 ['FTCS' 'DGRW'] no cointegration relationship, P-value is 0.4043548396873122 ['FTC' 'PWB'] no cointegration relationship, P-value is 0.6624131709645249 ['FSTA' 'VDC'] no cointegration relationship, P-value is 0.18585355876293397 ['FRI' 'IYR'] no cointegration relationship, P-value is 0.9602483568048028 ['FRI' 'ICF'] no cointegration relationship, P-value is 0.9369158297837648 ['FREL' 'RWR'] no cointegration relationship, P-value is 0.9221978416317005 ['FREL' 'ICF'] no cointegration relationship, P-value is 0.48985305693281406 ['FREL' 'VNQ'] no cointegration relationship, P-value is 0.7334084491887289 ['FREL' 'SCHH'] no cointegration relationship, P-value is 0.9234517281256025 ['FRAK' 'PEO'] no cointegration relationship, P-value is 0.2792941877999562 ['FRAK' 'IEO'] no cointegration relationship, P-value is 0.8187759943140531 ['FPX' 'JKH'] no cointegration relationship, P-value is 0.42072226787631106 ['FNI' 'PGJ'] no cointegration relationship, P-value is 0.47916940541009684 ['FNDE' 'DVYE'] no cointegration relationship, P-value is 0.8491137882933215 ['FNDC' 'VPL'] no cointegration relationship, P-value is 0.8196348448454165 ['FNDA' 'VIOV'] no cointegration relationship, P-value is 0.629666998426697 ['FNDA' 'SLY'] no cointegration relationship, P-value is 0.6341518724821419 ['FNDA' 'IJS'] no cointegration relationship, P-value is 0.608928817844218 ['FMO' 'NTG'] no cointegration relationship, P-value is 0.7957907987744233 ['FMO' 'AMLP'] no cointegration relationship, P-value is 0.3289929693331024 ['FMO' 'FEN'] no cointegration relationship, P-value is 0.31845025868649623 ['FLN' 'EWZS'] no cointegration relationship, P-value is 0.15713003690994576 ['FJP' 'DXJS'] no cointegration relationship, P-value is 0.25218346725144747 ['FJP' 'DBJP'] no cointegration relationship, P-value is 0.9661493927199271 ['FJP' 'DFJ'] no cointegration relationship, P-value is 0.43898448798819023 ['FHLC' 'IYH'] no cointegration relationship, P-value is 0.21761112427871032 ['FGM' 'EWG'] no cointegration relationship, P-value is 0.5878012814010575 ['FGM' 'EWGS'] no cointegration relationship, P-value is 0.08650566558569683 ['FGM' 'GF'] no cointegration relationship, P-value is 0.9917942974829823 ['FGM' 'EWN'] no cointegration relationship, P-value is 0.8759690529058812 ['FGM' 'DXGE'] no cointegration relationship, P-value is 0.69395218328223 ['FGD' 'DWM'] no cointegration relationship, P-value is 0.5709072620013722 ['FGD' 'WDIV'] no cointegration relationship, P-value is 0.6495958879452267 ['FFR' 'GRI'] no cointegration relationship, P-value is 0.31498259485594216 ['FEZ' 'EWK'] no cointegration relationship, P-value is 0.78862209932888 ['FEZ' 'EWN'] has cointegration relationship, P-value is 0.022442056159422713 ['FEZ' 'EWQ'] no cointegration relationship, P-value is 0.4527437120064732 ['FEZ' 'EZU'] no cointegration relationship, P-value is 0.9119747920893411 ['FEZ' 'EWG'] no cointegration relationship, P-value is 0.808531990712221 ['FEX' 'PRF'] no cointegration relationship, P-value is 0.2631938001323141 ['FEU' 'EWQ'] no cointegration relationship, P-value is 0.6542466751887084 ['FEP' 'EFA'] no cointegration relationship, P-value is 0.6990076897301799 ['FEN' 'CEM'] no cointegration relationship, P-value is 0.4300744354739007
['FEN' 'AMJ'] no cointegration relationship, P-value is 0.0843408046944722 ['FEM' 'DVYE'] no cointegration relationship, P-value is 0.9458888736906949 ['FEM' 'TLTE'] no cointegration relationship, P-value is 0.49800012698508783 ['FDT' 'ACWX'] no cointegration relationship, P-value is 0.9606438740896688 ['FDN' 'IGM'] no cointegration relationship, P-value is 0.8377220281065283 ['FDN' 'SKYY'] no cointegration relationship, P-value is 0.6181893763612689 ['FDM' 'XSLV'] no cointegration relationship, P-value is 0.5838324934625676 ['FCOM' 'VOX'] no cointegration relationship, P-value is 0.23366014443201466 ['FBZ' 'UBR'] no cointegration relationship, P-value is 0.9337687207638965 ['FBZ' 'EWZS'] no cointegration relationship, P-value is 0.4738656655117557 ['FBT' 'FXH'] no cointegration relationship, P-value is 0.07348330497048214 ['FBT' 'PJP'] no cointegration relationship, P-value is 0.07198635627216456 ['FBT' 'VHT'] no cointegration relationship, P-value is 0.05980388592191823 ['FBT' 'RYH'] no cointegration relationship, P-value is 0.06054973385612942 ['FBT' 'PBE'] no cointegration relationship, P-value is 0.3872042074602472 ['FBGX' 'FLGE'] no cointegration relationship, P-value is 0.0511377030857317 ['FAZ' 'SDOW'] no cointegration relationship, P-value is 0.1943595807060854 ['FAZ' 'SEF'] no cointegration relationship, P-value is 0.44287576700744 ['FAZ' 'VXX'] no cointegration relationship, P-value is 0.5268398215353131 ['FAZ' 'SRTY'] no cointegration relationship, P-value is 0.11969713254951209 ['FAZ' 'MIDZ'] no cointegration relationship, P-value is 0.20952350034163592 ['FAB' 'FNK'] no cointegration relationship, P-value is 0.29459310796294447 ['EZU' 'EWK'] no cointegration relationship, P-value is 0.7149065531240825 ['EZU' 'EWN'] has cointegration relationship, P-value is 0.04479057992755067 ['EZU' 'VGK'] no cointegration relationship, P-value is 0.5989081349737162 ['EZU' 'IEFA'] has cointegration relationship, P-value is 0.02658585652315648 ['EZJ' 'DXJS'] no cointegration relationship, P-value is 0.25373984606882627 ['EZJ' 'DBJP'] no cointegration relationship, P-value is 0.8543854419375021 ['EZJ' 'DFJ'] no cointegration relationship, P-value is 0.8296418808899233 ['EXI' 'EWGS'] no cointegration relationship, P-value is 0.1313977794508948 ['EXG' 'IGD'] no cointegration relationship, P-value is 0.2298070963564447 ['EWZS' 'BRF'] no cointegration relationship, P-value is 0.752642173071149 ['EWZ' 'ILF'] no cointegration relationship, P-value is 0.9510965167636213 ['EWY' 'KF'] no cointegration relationship, P-value is 0.1506978563387632 ['EWX' 'INDA'] no cointegration relationship, P-value is 0.14400524832763462 ['EWX' 'EEMV'] no cointegration relationship, P-value is 0.9575133015135148 ['EWQ' 'IEFA'] has cointegration relationship, P-value is 0.014571771699412015 ['EWQ' 'VGK'] has cointegration relationship, P-value is 0.0043126601819875095 ['EWQ' 'EWK'] no cointegration relationship, P-value is 0.7940542009052893 ['EWK' 'EIRL'] no cointegration relationship, P-value is 0.45948015052853086 ['EWK' 'EWN'] no cointegration relationship, P-value is 0.6026579003892678 ['EWK' 'EWGS'] no cointegration relationship, P-value is 0.13247897260643315 ['EWH' 'CHN'] has cointegration relationship, P-value is 0.01697972383222902 ['EWGS' 'EWG'] no cointegration relationship, P-value is 0.6512787987314284 ['EWGS' 'EDEN'] no cointegration relationship, P-value is 0.1865028496302461 ['EWG' 'EZU'] no cointegration relationship, P-value is 0.7693818377401531 ['EWG' 'EWN'] no cointegration relationship, P-value is 0.5959352011287177 ['EWC' 'RYE'] no cointegration relationship, P-value is 0.7550682750907518 ['EWA' 'SDIV'] no cointegration relationship, P-value is 0.5723637593723631 ['EUM' 'EFZ'] no cointegration relationship, P-value is 0.07313899355969788 ['ETW' 'ETV'] no cointegration relationship, P-value is 0.8038575697001924 ['ETO' 'EVT'] no cointegration relationship, P-value is 0.4317025461935058 ['ERY' 'DUG'] no cointegration relationship, P-value is 0.10804798274930655 ['ERUS' 'RSX'] no cointegration relationship, P-value is 0.9369402188332568 ['EQWL' 'RWW'] no cointegration relationship, P-value is 0.25529447397464344 ['EPV' 'EUM'] has cointegration relationship, P-value is 0.03133439858977859 ['EPV' 'EFU'] no cointegration relationship, P-value is 0.11726111656966642 ['EPV' 'EFZ'] has cointegration relationship, P-value is 0.015304987187692416 ['EPS' 'QDEF'] no cointegration relationship, P-value is 0.6352925890169043 ['EPI' 'INDA'] no cointegration relationship, P-value is 0.964752497730254 ['EPI' 'IIF'] no cointegration relationship, P-value is 0.3895186755382537 ['EPI' 'INDY'] no cointegration relationship, P-value is 0.9821209685327039 ['EOS' 'ETV'] no cointegration relationship, P-value is 0.6513145705300749 ['EOS' 'EXG'] no cointegration relationship, P-value is 0.471919253773629 ['ENY' 'EWC'] no cointegration relationship, P-value is 0.6813301689502336 ['ENFR' 'EMLP'] no cointegration relationship, P-value is 0.9018065000824443 ['ENFR' 'MLPX'] no cointegration relationship, P-value is 0.7863812321888756 ['EMLP' 'MLPI'] no cointegration relationship, P-value is 0.4834174370828145 ['EMLP' 'AMU'] no cointegration relationship, P-value is 0.49768954648418356 ['EMLP' 'ATMP'] no cointegration relationship, P-value is 0.6920260696571261 ['EFZ' 'EFU'] no cointegration relationship, P-value is 0.11281527757873194 ['EFU' 'EUM'] has cointegration relationship, P-value is 0.0033471136209607317 ['EFU' 'EEV'] no cointegration relationship, P-value is 0.05259123122136055 ['EFG' 'TLTD'] no cointegration relationship, P-value is 0.9786460114635703 ['EFAV' 'ACWV'] no cointegration relationship, P-value is 0.6833377930178407 ['EEV' 'YXI'] no cointegration relationship, P-value is 0.5724944879693987 ['EEV' 'FXP'] no cointegration relationship, P-value is 0.388996639712853 ['EEV' 'EUM'] no cointegration relationship, P-value is 0.5111305313759629 ['EES' 'SCHA'] no cointegration relationship, P-value is 0.9542996116922686 ['EES' 'VIOV'] no cointegration relationship, P-value is 0.825662655161416 ['EEMA' 'AIA'] has cointegration relationship, P-value is 0.02397412372893736 ['EEMA' 'AAXJ'] has cointegration relationship, P-value is 0.030806659513292128 ['EEMA' 'FXI'] no cointegration relationship, P-value is 0.8181434452420395 ['EEM' 'IEMG'] has cointegration relationship, P-value is 0.009405482896383207 ['EEB' 'RSX'] no cointegration relationship, P-value is 0.3080044916009971 ['EEB' 'ERUS'] no cointegration relationship, P-value is 0.6325179123143321 ['EEB' 'ADRE'] no cointegration relationship, P-value is 0.587615391372456 ['EDZ' 'EPV'] no cointegration relationship, P-value is 0.17243596835972846 ['EDZ' 'YANG'] no cointegration relationship, P-value is 0.19802806343066343 ['EDZ' 'EEV'] no cointegration relationship, P-value is 0.31614220726412007 ['EDV' 'TLT'] no cointegration relationship, P-value is 0.28880113587858003 ['EDV' 'VGLT'] no cointegration relationship, P-value is 0.24763496993541406 ['EDIV' 'DVYE'] no cointegration relationship, P-value is 0.45008953547805663 ['DXJS' 'DFJ'] no cointegration relationship, P-value is 0.700252141304459 ['DXJF' 'HEWJ'] no cointegration relationship, P-value is 0.30878682287100706 ['DXJF' 'DBJP'] no cointegration relationship, P-value is 0.32202717219615157 ['DXJ' 'DBEF'] no cointegration relationship, P-value is 0.885732863385901 ['DXJ' 'DBJP'] no cointegration relationship, P-value is 0.856091724997109 ['DXGE' 'HEDJ'] no cointegration relationship, P-value is 0.9787367875819046 ['DXD' 'DOG'] no cointegration relationship, P-value is 0.5381439914894908 ['DXD' 'SDS'] no cointegration relationship, P-value is 0.05694598846169811 ['DWX' 'LVL'] no cointegration relationship, P-value is 0.8419874232763827 ['DVY' 'FVD'] no cointegration relationship, P-value is 0.9978736179568409 ['DVHL' 'ROOF'] no cointegration relationship, P-value is 0.06106413482688268 ['DVHL' 'ENFR'] no cointegration relationship, P-value is 0.4534099225508809 ['DUST' 'DGZ'] no cointegration relationship, P-value is 0.7677041421516352 ['DUST' 'DGLD'] no cointegration relationship, P-value is 0.6586208129002394 ['DTYS' 'TBX'] no cointegration relationship, P-value is 0.998527361288147
['DTYS' 'DLBS'] has cointegration relationship, P-value is 0.04759897521807325 ['DTYS' 'TYO'] no cointegration relationship, P-value is 0.998677105289187 ['DTYS' 'PST'] no cointegration relationship, P-value is 0.9980500410793052 ['DTYS' 'TBT'] no cointegration relationship, P-value is 0.8611409957032674 ['DTH' 'VXUS'] no cointegration relationship, P-value is 0.19831654514447783 ['DTD' 'FVD'] no cointegration relationship, P-value is 0.9131962665222833 ['DSLV' 'ZSL'] no cointegration relationship, P-value is 0.10054754489279566 ['DSI' 'FTCS'] no cointegration relationship, P-value is 0.332030536677984 ['DSI' 'RWL'] no cointegration relationship, P-value is 0.7282375168359035 ['DSE' 'GER'] no cointegration relationship, P-value is 0.23801089542132187 ['DRV' 'SRS'] no cointegration relationship, P-value is 0.5597767963408051 ['DRN' 'URE'] no cointegration relationship, P-value is 0.9059754952042853 ['DRIP' 'DUG'] no cointegration relationship, P-value is 0.07658196517849722 ['DPK' 'EPV'] no cointegration relationship, P-value is 0.12215071752489065 ['DPK' 'EWV'] no cointegration relationship, P-value is 0.1766038030215642 ['DPK' 'VIXY'] no cointegration relationship, P-value is 0.6127271430241346 ['DPK' 'EFU'] no cointegration relationship, P-value is 0.13057017214380517 ['DPK' 'VIIX'] no cointegration relationship, P-value is 0.6081385103244893 ['DPK' 'VXX'] no cointegration relationship, P-value is 0.7420152201735932 ['DOG' 'SH'] no cointegration relationship, P-value is 0.16290116591703158 ['DNL' 'VXUS'] no cointegration relationship, P-value is 0.6393443538044055 ['DLS' 'SCZ'] no cointegration relationship, P-value is 0.9476624192371764 ['DLS' 'GWX'] no cointegration relationship, P-value is 0.569074376072555 ['DLN' 'OEF'] no cointegration relationship, P-value is 0.5688565131597225 ['DLN' 'IWL'] no cointegration relationship, P-value is 0.633499042022924 ['DLN' 'DHS'] no cointegration relationship, P-value is 0.8894060298349895 ['DLN' 'DIA'] no cointegration relationship, P-value is 0.27324923099871196 ['DJP' 'GCC'] no cointegration relationship, P-value is 0.27355908615539754 ['DJP' 'RJI'] no cointegration relationship, P-value is 0.4526531940178946 ['DJP' 'BCM'] no cointegration relationship, P-value is 0.05079207532684547 ['DIM' 'VGK'] no cointegration relationship, P-value is 0.9923712220800879 ['DIM' 'TLTD'] no cointegration relationship, P-value is 0.5247611412712182 ['DIM' 'DLS'] no cointegration relationship, P-value is 0.7783948612370986 ['DIA' 'JKD'] no cointegration relationship, P-value is 0.7383472036005632 ['DHS' 'SPLV'] no cointegration relationship, P-value is 0.8901093201131778 ['DGZ' 'DZZ'] has cointegration relationship, P-value is 0.00026028578853297087 ['DGS' 'EEMV'] no cointegration relationship, P-value is 0.9325643330907399 ['DGS' 'EWX'] no cointegration relationship, P-value is 0.24780146108827972 ['DGRW' 'DIA'] has cointegration relationship, P-value is 0.00826409668188039 ['DGRW' 'XLG'] has cointegration relationship, P-value is 0.005221352305202721 ['DGP' 'IAU'] no cointegration relationship, P-value is 0.21861271881550365 ['DGP' 'GLD'] no cointegration relationship, P-value is 0.2237911095081352 ['DGP' 'PHYS'] no cointegration relationship, P-value is 0.05428562804158173 ['DGP' 'OUNZ'] no cointegration relationship, P-value is 0.13593084664447708 ['DGP' 'SGOL'] no cointegration relationship, P-value is 0.16385758272644974 ['DGLD' 'DZZ'] has cointegration relationship, P-value is 0.020003760147233637 ['DGLD' 'GLL'] no cointegration relationship, P-value is 0.7458560282602573 ['DGLD' 'ZSL'] no cointegration relationship, P-value is 0.16696046823927413 ['DGL' 'GLDI'] no cointegration relationship, P-value is 0.9977612238878502 ['DGL' 'GLD'] no cointegration relationship, P-value is 0.8636488002218083 ['DGL' 'SGOL'] no cointegration relationship, P-value is 0.7523979628623976 ['DFJ' 'SCJ'] no cointegration relationship, P-value is 0.7033776135134256 ['DFJ' 'HEWJ'] no cointegration relationship, P-value is 0.997332139395114 ['DFE' 'EWGS'] no cointegration relationship, P-value is 0.13685080304659591 ['DFE' 'DLS'] no cointegration relationship, P-value is 0.17641607577789914 ['DFE' 'EWUS'] no cointegration relationship, P-value is 0.9497592289354888 ['DFE' 'IEUS'] no cointegration relationship, P-value is 0.9269384405044042 ['DFE' 'FEUZ'] no cointegration relationship, P-value is 0.10057956285253 ['DFE' 'IFEU'] no cointegration relationship, P-value is 0.9485545298902369 ['DBO' 'DBC'] no cointegration relationship, P-value is 0.9317612467679631 ['DBO' 'USL'] no cointegration relationship, P-value is 0.3810482979362452 ['DBJP' 'DXJS'] no cointegration relationship, P-value is 0.9651752520017601 ['DBJP' 'DBEF'] no cointegration relationship, P-value is 0.8622821979885208 ['DBJP' 'DFJ'] no cointegration relationship, P-value is 0.6620026660861869 ['DBGR' 'DXGE'] no cointegration relationship, P-value is 0.7104097539625382 ['DBEF' 'DBGR'] no cointegration relationship, P-value is 0.4278088118065591 ['DBEF' 'HEDJ'] no cointegration relationship, P-value is 0.22579601925720622 ['DBE' 'USO'] no cointegration relationship, P-value is 0.6022425716774673 ['DBE' 'DBO'] no cointegration relationship, P-value is 0.47177516900208794 ['DBE' 'OILNF'] no cointegration relationship, P-value is 0.5909224191034116 ['DBC' 'RJI'] no cointegration relationship, P-value is 0.5470760761838268 ['DBC' 'USO'] no cointegration relationship, P-value is 0.8938724505624198 ['CZA' 'FNDB'] no cointegration relationship, P-value is 0.6714140833534094 ['CWB' 'IGV'] no cointegration relationship, P-value is 0.8137456364053448 ['CUT' 'WOOD'] no cointegration relationship, P-value is 0.05431327229689828 ['CURE' 'RXL'] no cointegration relationship, P-value is 0.10935147604809486 ['CSM' 'FTCS'] no cointegration relationship, P-value is 0.9607503420871567 ['CSM' 'DIA'] no cointegration relationship, P-value is 0.3292820189699147 ['CQQQ' 'FNI'] no cointegration relationship, P-value is 0.12533043256369902 ['CORP' 'BLV'] no cointegration relationship, P-value is 0.15337222061391653 ['COPX' 'XME'] no cointegration relationship, P-value is 0.41841842070538815 ['COPX' 'SLX'] no cointegration relationship, P-value is 0.1823405208474962 ['COPX' 'KOL'] no cointegration relationship, P-value is 0.21585025143047948 ['CNXT' 'ASHS'] no cointegration relationship, P-value is 0.6422863613851106 ['CNXT' 'ASHR'] has cointegration relationship, P-value is 0.0021596330566787444 ['CHN' 'MCHI'] has cointegration relationship, P-value is 0.006820942654011927 ['CHIX' 'FXI'] no cointegration relationship, P-value is 0.05763376139377958 ['CHAU' 'KBA'] Stable process! ['CHAU' 'PEK'] Stable process! ['CHAU' 'ASHS'] Stable process! ['CHAU' 'ASHR'] Stable process! ['CEM' 'AMLP'] no cointegration relationship, P-value is 0.23721014270680624 ['CEM' 'AMJ'] no cointegration relationship, P-value is 0.2406147618139492 ['CEE' 'RSX'] no cointegration relationship, P-value is 0.45031830502668235 ['CEE' 'ERUS'] no cointegration relationship, P-value is 0.45051677784920796 ['CAF' 'PEK'] no cointegration relationship, P-value is 0.3210772125522928 ['BWZ' 'IBND'] has cointegration relationship, P-value is 0.02300846039460936 ['BWX' 'UDN'] Stable process! ['BWX' 'IGOV'] no cointegration relationship, P-value is 0.516503905988197 ['BRZU' 'UBR'] Stable process! ['BRZU' 'EWZS'] Stable process! ['BNO' 'RJI'] no cointegration relationship, P-value is 0.29212067881330783 ['BNO' 'GSP'] has cointegration relationship, P-value is 0.01181263704576404 ['BNO' 'DBO'] no cointegration relationship, P-value is 0.11133421174688712 ['BNO' 'DBE'] no cointegration relationship, P-value is 0.838657871253351 ['BNO' 'USL'] has cointegration relationship, P-value is 0.04149855439768352 ['BLV' 'BAB'] has cointegration relationship, P-value is 0.028528052933604716 ['BLV' 'BIV'] no cointegration relationship, P-value is 0.30011936248914606 ['BKF' 'EWX'] no cointegration relationship, P-value is 0.6284860046714693 ['BIV' 'SCHZ'] has cointegration relationship, P-value is 0.004498315079462056 ['BIV' 'IEI'] no cointegration relationship, P-value is 0.6635908389437666 ['BGR' 'PEO'] no cointegration relationship, P-value is 0.21096144247605064
['BDCS' 'BIZD'] no cointegration relationship, P-value is 0.48479548738975564 ['BDCL' 'BIZD'] no cointegration relationship, P-value is 0.8299939494096031 ['BBP' 'SBIO'] no cointegration relationship, P-value is 0.8967084703456945 ['BBC' 'BBP'] no cointegration relationship, P-value is 0.9519186639912998 ['BBC' 'SBIO'] no cointegration relationship, P-value is 0.2648486022557398 ['ATMP' 'AMLP'] no cointegration relationship, P-value is 0.7672259929597014 ['ATMP' 'YMLI'] has cointegration relationship, P-value is 0.003360962107369166 ['ATMP' 'AMJ'] no cointegration relationship, P-value is 0.8514533943436642 ['ASHS' 'KBA'] has cointegration relationship, P-value is 0.016244123048090153 ['ASHR' 'PEK'] has cointegration relationship, P-value is 3.3289311610298024e-07 ['ASHR' 'ASHS'] no cointegration relationship, P-value is 0.16032979161651778 ['ARKQ' 'ARKK'] no cointegration relationship, P-value is 0.9898703349251176 ['ARKQ' 'ARKW'] no cointegration relationship, P-value is 0.9269877363753347 ['ARKK' 'ARKW'] has cointegration relationship, P-value is 0.0029530687144655255 ['ARKG' 'ARKK'] no cointegration relationship, P-value is 0.6422597583651801 ['ARKG' 'BBC'] no cointegration relationship, P-value is 0.3815623136124646 ['AMZA' 'ZMLP'] no cointegration relationship, P-value is 0.9427121372357438 ['AMZA' 'AMLP'] no cointegration relationship, P-value is 0.6229207907675901 ['AMZA' 'YMLI'] no cointegration relationship, P-value is 0.8702374200678944 ['AMU' 'TYG'] no cointegration relationship, P-value is 0.3014679607989286 ['AMLP' 'MLPA'] no cointegration relationship, P-value is 0.43356445794499177 ['AMLP' 'YMLI'] no cointegration relationship, P-value is 0.881059625778813 ['AMJ' 'TYG'] no cointegration relationship, P-value is 0.2856698568043354 ['AAXJ' 'EEMV'] no cointegration relationship, P-value is 0.9618322317184002 ['ACWV' 'AAXJ'] no cointegration relationship, P-value is 0.5930073077125214 ['ADRE' 'BKF'] no cointegration relationship, P-value is 0.7352486571744654 ['AIA' 'AAXJ'] no cointegration relationship, P-value is 0.32259692818133245

These are pairs of funds which pass the cointegration test.

In [4]:
results1 = pd.Series(results1)
display(results1)
pd.concat([results1.apply(lambda x:x[0]),results1.apply(lambda x:x[1])],axis = 1).to_csv(filepath+'cointegration1.csv',index = False)
0       [YAO, CHN]
1      [YANG, YXI]
2       [XLV, IXJ]
3       [XLG, DIA]
4       [XHS, IHF]
5      [VXX, VIIX]
6     [VOOV, SPYV]
7     [VOOG, VONG]
8       [VKQ, IQI]
9      [VIXM, VXZ]
10     [VIOV, IJS]
11      [VHT, IBB]
12    [VGLT, SPTL]
13      [USO, BNO]
14    [USLV, SLVP]
15      [URE, RQI]
16     [UGLD, UGL]
17     [UGL, PHYS]
18      [UGA, USO]
19      [UGA, BNO]
20      [UGA, USL]
21     [TYG, YMLI]
22    [TLTE, ADRE]
23     [SQQQ, REW]
24     [SQQQ, SDS]
25     [SPXU, DXD]
26    [SOXX, QTEC]
27      [SMN, MYY]
28     [SLYG, IJT]
29     [SLY, VIOO]
          ...     
61      [GLL, DZZ]
62      [GER, GMZ]
63      [FEZ, EWN]
64      [EZU, EWN]
65     [EZU, IEFA]
66     [EWQ, IEFA]
67      [EWQ, VGK]
68      [EWH, CHN]
69      [EPV, EUM]
70      [EPV, EFZ]
71      [EFU, EUM]
72     [EEMA, AIA]
73    [EEMA, AAXJ]
74     [EEM, IEMG]
75    [DTYS, DLBS]
76      [DGZ, DZZ]
77     [DGRW, DIA]
78     [DGRW, XLG]
79     [DGLD, DZZ]
80    [CNXT, ASHR]
81     [CHN, MCHI]
82     [BWZ, IBND]
83      [BNO, GSP]
84      [BNO, USL]
85      [BLV, BAB]
86     [BIV, SCHZ]
87    [ATMP, YMLI]
88     [ASHS, KBA]
89     [ASHR, PEK]
90    [ARKK, ARKW]
Length: 91, dtype: object

Cointegrated Augmented Dickey-Fuller Test

The Cointegrated Augmented Dickey-Fuller Test (CADF test) involves firstly performing a linear regression between two price series to determine the portfolio’s optimal hedge ratio and then conducting a stationarity test on the portfolio’s price series.

Take XLV and IXJ as an example. Firstly, the price series of XLV and IXJ for the period 2015 to mid-2019 are plotted:

In [333]:
data = web.DataReader(['XLV','IXJ'], 'yahoo', start, end)['Adj Close']
data.plot()
Out[333]:
<matplotlib.axes._subplots.AxesSubplot at 0x1b3f0f8bef0>
Notebook Image

A scatter plot is plotted to see if there exists a linear realtionship.

In [6]:
plt.scatter(data['IXJ'],data['XLV'])
Out[6]:
<matplotlib.collections.PathCollection at 0x1b3e9795390>
Notebook Image

The residual of XLV-beta*IXJ does not look overly stationary and the the residual does not pass the unit root test.

In [7]:
## ordinary least squares regression
from sklearn.linear_model import LinearRegression
reg = LinearRegression().fit(data['IXJ'].values.reshape(-1,1), data['XLV'])
beta = reg.coef_
residual = data['XLV'] - beta * data['IXJ']
plt.plot(residual)
Out[7]:
[<matplotlib.lines.Line2D at 0x1b3ef0d5ba8>]
Notebook Image
In [8]:
sm.tsa.adfuller(residual)
Out[8]:
(-2.2616846377199025,
 0.1846232591866374,
 1,
 1157,
 {'1%': -3.436014535478888,
  '5%': -2.8640412872730208,
  '10%': -2.56810174401953},
 -124.69337756664208)

Then we use the above method to test all pairs.

In [10]:
results2=[]
for t in range(len(ticker)):
    try:
        price1 = web.DataReader(ticker.iloc[t,:][0], 'yahoo', start, end)['Adj Close'].dropna()
        price2 = web.DataReader(ticker.iloc[t,:][1], 'yahoo', start, end)['Adj Close'].dropna()
        reg = LinearRegression().fit(price1.values.reshape(-1,1), price2)
        beta = reg.coef_
        residual = price1 - beta * price2
        pvalue = sm.tsa.adfuller(residual)[1]
        if pvalue<0.05:
            print(ticker.iloc[t,:].values, "has cointegration relationship, P-value is",pvalue)
            results2.append(ticker.iloc[t,:].values)
    except ValueError:
        print(ticker.iloc[t,:])
        continue
ticker ZBIO peers BIS Name: 4, dtype: object ticker YAO peers GXC Name: 7, dtype: object ticker YAO peers CHN Name: 8, dtype: object ticker YAO peers MCHI Name: 9, dtype: object ticker YAO peers CQQQ Name: 10, dtype: object ticker YAO peers FXI Name: 11, dtype: object ticker YANG peers CHAD Name: 12, dtype: object ticker XNTK peers IXN Name: 16, dtype: object ticker VXX peers VIXY Name: 36, dtype: object ticker VXX peers VIIX Name: 37, dtype: object ticker VXX peers SDS Name: 38, dtype: object ticker VTWV peers PRFZ Name: 41, dtype: object ['VKQ' 'VGM'] has cointegration relationship, P-value is 0.022653343041042134 ['VKQ' 'IQI'] has cointegration relationship, P-value is 0.021375258940595453 ['VIIX' 'QID'] has cointegration relationship, P-value is 0.0014426200536863892 ticker VGIT peers IEI Name: 75, dtype: object ticker USO peers RJI Name: 80, dtype: object ticker UPW peers PUI Name: 89, dtype: object ticker UPW peers RYU Name: 92, dtype: object ticker UPW peers VPU Name: 93, dtype: object ['UNG' 'UNL'] has cointegration relationship, P-value is 0.04024193016227392 ['ULE' 'FXE'] has cointegration relationship, P-value is 0.042089596191484425 ticker UGL peers GLDI Name: 98, dtype: object ['UDN' 'FXE'] has cointegration relationship, P-value is 0.03780511635907742 ['UCO' 'EWC'] has cointegration relationship, P-value is 0.0301507887882641 ticker UBR peers BRF Name: 110, dtype: object ticker TYO peers TMV Name: 115, dtype: object ticker TYG peers NTG Name: 118, dtype: object ticker TYG peers MLPA Name: 119, dtype: object ticker TYG peers YMLI Name: 120, dtype: object ticker TYG peers KYN Name: 121, dtype: object ['TVIX' 'VXZ'] has cointegration relationship, P-value is 6.25161858159587e-08 ticker TTT peers TMV Name: 130, dtype: object ticker TBT peers TMV Name: 153, dtype: object ticker TBF peers TMV Name: 155, dtype: object ticker SLX peers GUNR Name: 197, dtype: object ticker SGOL peers GLDI Name: 203, dtype: object ticker SGDJ peers GDXJ Name: 206, dtype: object ticker SCIN peers SCIF Name: 219, dtype: object ticker SCIF peers INXX Name: 221, dtype: object ['REZ' 'RWR'] has cointegration relationship, P-value is 0.024527995862271484 ticker QQQE peers XNTK Name: 285, dtype: object ticker PXMG peers ARKW Name: 295, dtype: object ['PJP' 'IHE'] has cointegration relationship, P-value is 0.007835112140827863 ticker OUNZ peers GLDI Name: 335, dtype: object ticker OILNF peers USO Name: 340, dtype: object ticker OILNF peers RJN Name: 341, dtype: object ticker OILNF peers UGA Name: 342, dtype: object ['MUC' 'MCA'] has cointegration relationship, P-value is 0.005357242511605715 ['MIE' 'MLPX'] has cointegration relationship, P-value is 0.031060619563182346 ticker LABU peers BBC Name: 385, dtype: object ticker LABU peers SBIO Name: 386, dtype: object ticker LABD peers BIS Name: 387, dtype: object ['KYN' 'AMJ'] has cointegration relationship, P-value is 0.01338069756227242 ticker JPXN peers JPN Name: 409, dtype: object ticker JJGTF peers GRU Name: 422, dtype: object ticker JJGTF peers RJA Name: 423, dtype: object ticker JJGTF peers SOYB Name: 424, dtype: object ticker JJGTF peers WEAT Name: 425, dtype: object ticker JJATF peers RJA Name: 426, dtype: object ticker IYF peers FXO Name: 433, dtype: object ['IXP' 'IYZ'] has cointegration relationship, P-value is 0.008287290340990915 ticker ITE peers VGIT Name: 470, dtype: object ticker INXX peers INDA Name: 475, dtype: object ticker INXX peers IIF Name: 476, dtype: object ticker INXX peers EPI Name: 477, dtype: object ticker INXX peers INCO Name: 478, dtype: object ticker INXX peers INDY Name: 479, dtype: object ticker INPTF peers INXX Name: 480, dtype: object ['IHE' 'PPH'] has cointegration relationship, P-value is 0.007976426959211117 ['IHE' 'BBC'] has cointegration relationship, P-value is 0.006106208233450511 ['IHE' 'IXJ'] has cointegration relationship, P-value is 0.014820427607901957 ['IEUS' 'FGM'] has cointegration relationship, P-value is 0.02536664289797592 ticker IEF peers VGIT Name: 534, dtype: object ['IBND' 'FXE'] has cointegration relationship, P-value is 0.029165374653193573 ticker IAU peers GLDI Name: 548, dtype: object ticker HAP peers GUNR Name: 563, dtype: object ticker GXC peers GMF Name: 567, dtype: object ticker GUNR peers COPX Name: 571, dtype: object ticker GUNR peers RLY Name: 572, dtype: object ticker GSP peers USO Name: 573, dtype: object ticker GSP peers USL Name: 576, dtype: object ticker GNR peers GUNR Name: 578, dtype: object ticker GMF peers EEMV Name: 579, dtype: object ticker GLTR peers GLDI Name: 582, dtype: object ticker GLD peers GLDI Name: 591, dtype: object ['GER' 'GMZ'] has cointegration relationship, P-value is 0.02237936729278496 ticker GDXS peers DUST Name: 593, dtype: object ticker FYX peers EES Name: 594, dtype: object ticker FXI peers GMF Name: 608, dtype: object ticker FREL peers RWR Name: 624, dtype: object ticker FREL peers ICF Name: 625, dtype: object ticker FREL peers VNQ Name: 626, dtype: object ticker FREL peers SCHH Name: 627, dtype: object ticker FEM peers DVYE Name: 663, dtype: object ticker FEM peers TLTE Name: 664, dtype: object ['FBGX' 'FLGE'] has cointegration relationship, P-value is 0.020809270810758496 ticker FAZ peers VXX Name: 680, dtype: object ['EWH' 'CHN'] has cointegration relationship, P-value is 0.04259329248395145 ticker EQWL peers RWW Name: 716, dtype: object ticker ENY peers EWC Name: 726, dtype: object ticker EMLP peers ATMP Name: 731, dtype: object ticker EES peers SCHA Name: 740, dtype: object ['EEMA' 'AAXJ'] has cointegration relationship, P-value is 0.009450640374017273 ticker DXJF peers HEWJ Name: 756, dtype: object ticker DXJF peers DBJP Name: 757, dtype: object ticker DRIP peers DUG Name: 782, dtype: object ['DPK' 'EWV'] has cointegration relationship, P-value is 0.021032338603943667 ['DPK' 'EFU'] has cointegration relationship, P-value is 0.009823472322788095 ticker DPK peers VXX Name: 788, dtype: object ticker DJP peers GCC Name: 797, dtype: object ticker DJP peers BCM Name: 799, dtype: object ['DGZ' 'DZZ'] has cointegration relationship, P-value is 0.005741449945442098 ticker DGL peers GLDI Name: 818, dtype: object ticker DFJ peers HEWJ Name: 822, dtype: object ticker DBE peers OILNF Name: 839, dtype: object ticker DBC peers RJI Name: 840, dtype: object ticker CHAU peers KBA Name: 857, dtype: object ticker CHAU peers PEK Name: 858, dtype: object ticker CHAU peers ASHS Name: 859, dtype: object ticker CHAU peers ASHR Name: 860, dtype: object ['CEM' 'AMLP'] has cointegration relationship, P-value is 0.041275292925849694 ['BRZU' 'EWZS'] has cointegration relationship, P-value is 0.020932933149520223 ticker BNO peers GSP Name: 872, dtype: object ['BGR' 'PEO'] has cointegration relationship, P-value is 0.022163345063016746 ticker ATMP peers AMLP Name: 887, dtype: object ticker ATMP peers YMLI Name: 888, dtype: object ticker ATMP peers AMJ Name: 889, dtype: object ticker AMU peers TYG Name: 901, dtype: object ['AMLP' 'MLPA'] has cointegration relationship, P-value is 0.03339525333261745
In [33]:
results2 = pd.Series(results2)
display(results2)
pd.concat([results2.apply(lambda x:x[0]),results2.apply(lambda x:x[1])],axis = 1).to_csv(filepath+'cointegration2.csv',index = False)
0       [VKQ, VGM]
1       [VKQ, IQI]
2      [VIIX, QID]
3       [UNG, UNL]
4       [ULE, FXE]
5       [UDN, FXE]
6       [UCO, EWC]
7      [TVIX, VXZ]
8       [REZ, RWR]
9       [PJP, IHE]
10      [MUC, MCA]
11     [MIE, MLPX]
12      [KYN, AMJ]
13      [IXP, IYZ]
14      [IHE, PPH]
15      [IHE, BBC]
16      [IHE, IXJ]
17     [IEUS, FGM]
18     [IBND, FXE]
19      [GER, GMZ]
20    [FBGX, FLGE]
21      [EWH, CHN]
22    [EEMA, AAXJ]
23      [DPK, EWV]
24      [DPK, EFU]
25      [DGZ, DZZ]
26     [CEM, AMLP]
27    [BRZU, EWZS]
28      [BGR, PEO]
29    [AMLP, MLPA]
dtype: object

Following is the pairs of funds that both pass these two integration tests. We select these pairs to open and close pair trading.

In [61]:
results1
Out[61]:
0       [YAO, CHN]
1      [YANG, YXI]
2       [XLV, IXJ]
3       [XLG, DIA]
4       [XHS, IHF]
5      [VXX, VIIX]
6     [VOOV, SPYV]
7     [VOOG, VONG]
8       [VKQ, IQI]
9      [VIXM, VXZ]
10     [VIOV, IJS]
11      [VHT, IBB]
12    [VGLT, SPTL]
13      [USO, BNO]
14    [USLV, SLVP]
15      [URE, RQI]
16     [UGLD, UGL]
17     [UGL, PHYS]
18      [UGA, USO]
19      [UGA, BNO]
20      [UGA, USL]
21     [TYG, YMLI]
22    [TLTE, ADRE]
23     [SQQQ, REW]
24     [SQQQ, SDS]
25     [SPXU, DXD]
26    [SOXX, QTEC]
27      [SMN, MYY]
28     [SLYG, IJT]
29     [SLY, VIOO]
          ...     
61      [GLL, DZZ]
62      [GER, GMZ]
63      [FEZ, EWN]
64      [EZU, EWN]
65     [EZU, IEFA]
66     [EWQ, IEFA]
67      [EWQ, VGK]
68      [EWH, CHN]
69      [EPV, EUM]
70      [EPV, EFZ]
71      [EFU, EUM]
72     [EEMA, AIA]
73    [EEMA, AAXJ]
74     [EEM, IEMG]
75    [DTYS, DLBS]
76      [DGZ, DZZ]
77     [DGRW, DIA]
78     [DGRW, XLG]
79     [DGLD, DZZ]
80    [CNXT, ASHR]
81     [CHN, MCHI]
82     [BWZ, IBND]
83      [BNO, GSP]
84      [BNO, USL]
85      [BLV, BAB]
86     [BIV, SCHZ]
87    [ATMP, YMLI]
88     [ASHS, KBA]
89     [ASHR, PEK]
90    [ARKK, ARKW]
Length: 91, dtype: object
In [138]:
set([tuple(v) for v in results1.values])
result_set1 = set([tuple(v) for v in results1.values])
result_set2 = set([tuple(v) for v in results2.values])
all_results = pd.Series(list(result_set1.intersection(result_set2)))
all_results
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-138-da48279e6689> in <module> ----> 1 set([tuple(v) for v in results1.values]) 2 result_set1 = set([tuple(v) for v in results1.values]) 3 result_set2 = set([tuple(v) for v in results2.values]) 4 all_results = pd.Series(list(result_set1.intersection(result_set2))) 5 all_results NameError: name 'results1' is not defined

Pair Trading

Let \(P_t^A\) and \(P_t^B\) be the prices of two stocks A and B respectively. If it is assumed that {\(P_t^A\), \(P_t^B\)} is individually non-stationary, there exists the parameter \(\beta\) such that the following equation was a stationary process

\( P_t^A - \beta P_t^B = \mu + \epsilon_t\)

where \(\mu\) is a mean of the cointegration model. \(\epsilon_t\)is a stationary, mean-revering process and was referred to as a cointegration residual. The parameter \(\beta\)is known as a cointegration coefficient. The equation above represents a model of cointegrated pair for stocks A and B.

It's essential to understand how the conitegration residual together with the cointegration coefficient determines our trading direction. If \(\epsilon\) is positive, in a given confidence interval, this is a signal that stock A is relatively overpriced and stock B is relatively underpriced, and we are going to long B and short A; If \(\epsilon\) is negative, we are going to long A and short B.

Open Pair Trading

For each pair in selected pairs, we receive the current prices of the stocks, and then use the cointegration model to calculate the residual \(\epsilon\).

The variable 'touch' is signal. If the residual \(\epsilon\) cross over the positive threshold standard deviation(we set \(2.56*\sigma\) here), the signal would become +1; while if it cross down the negative threshold deviation( \(-2.56*\sigma\), the signal would become -1. For those pairs with +1 signal, we long stock B and short stock A. For those pairs with -1 signal, we long Stock A and short stock B.

Close Pair Trading

It works similar to the opening part. It uses the recorded original model and thresholds to determine whether or not we should close the position. If the residual \(\epsilon\) reaches our closing threshold, we liquidate stock A and stock B to close.

In [45]:
for t in range(len(results2)):
    price1 = web.DataReader(results2[t][0], 'yahoo', start, end)['Adj Close'].dropna()
    price2 = web.DataReader(results2[t][1], 'yahoo', start, end)['Adj Close'].dropna()
    reg = LinearRegression().fit(price1.values.reshape(-1,1), price2)
    beta = reg.coef_
    residual = price1 - beta * price2  
    error = residual - np.mean(residual)
    std = np.std(residual)
    # pair trading
    touch = 0
    cutoff = 2.56
    for i in range(len(error)):
        if touch == 0:
            if error[i] > cutoff*std:
                print(str(error.index[i])+'long %s and short %s'%(results2[t][1],results2[t][0]))
                touch = 1
            if error[i] < -cutoff*std:
                print(str(error.index[i])+'long %s and short %s'%(results2[t][0],results2[t][1]))
                touch = -1
        elif touch > 0:
            if error[i] < cutoff*std:
                print(str(error.index[i])+'close')
                touch = 0
        else:
            if error[i] > -cutoff*std:
                print (str(error.index[i])+'close')
                touch = 0
2019-07-15 00:00:00long VGM and short VKQ 2019-07-16 00:00:00close 2019-07-17 00:00:00long VGM and short VKQ 2019-07-18 00:00:00close 2015-11-13 00:00:00long IQI and short VKQ 2015-11-16 00:00:00close 2016-10-27 00:00:00long VKQ and short IQI 2016-10-28 00:00:00close 2018-09-17 00:00:00long VKQ and short IQI 2018-09-18 00:00:00close 2018-09-19 00:00:00long VKQ and short IQI 2018-09-20 00:00:00close 2019-07-26 00:00:00long VKQ and short IQI 2019-07-29 00:00:00close 2015-01-05 00:00:00long QID and short VIIX 2015-01-08 00:00:00close 2015-01-09 00:00:00long QID and short VIIX 2015-01-26 00:00:00close 2015-01-27 00:00:00long QID and short VIIX 2015-02-19 00:00:00close 2015-01-14 00:00:00long UNL and short UNG 2015-01-20 00:00:00close 2018-02-01 00:00:00long ULE and short FXE 2018-02-05 00:00:00close 2018-02-14 00:00:00long ULE and short FXE 2018-02-16 00:00:00close 2018-03-26 00:00:00long ULE and short FXE 2018-03-27 00:00:00close 2018-02-01 00:00:00long UDN and short FXE 2018-02-05 00:00:00close 2018-02-14 00:00:00long UDN and short FXE 2018-02-16 00:00:00close 2018-03-26 00:00:00long UDN and short FXE 2018-03-27 00:00:00close 2015-01-02 00:00:00long EWC and short UCO 2015-01-06 00:00:00close 2015-01-08 00:00:00long EWC and short UCO 2015-01-09 00:00:00close 2015-02-03 00:00:00long EWC and short UCO 2015-02-04 00:00:00close 2015-02-05 00:00:00long EWC and short UCO 2015-02-11 00:00:00close 2015-02-12 00:00:00long EWC and short UCO 2015-02-20 00:00:00close 2015-03-04 00:00:00long EWC and short UCO 2015-03-05 00:00:00close 2015-04-07 00:00:00long EWC and short UCO 2015-04-08 00:00:00close 2015-04-15 00:00:00long EWC and short UCO 2015-07-01 00:00:00close 2015-01-02 00:00:00long VXZ and short TVIX 2015-03-02 00:00:00close 2015-03-03 00:00:00long VXZ and short TVIX 2015-03-05 00:00:00close 2015-03-06 00:00:00long VXZ and short TVIX 2015-03-17 00:00:00close 2016-01-20 00:00:00long RWR and short REZ 2016-01-22 00:00:00close 2016-02-11 00:00:00long RWR and short REZ 2016-02-12 00:00:00close 2016-07-29 00:00:00long REZ and short RWR 2016-08-02 00:00:00close 2018-12-24 00:00:00long RWR and short REZ 2018-12-26 00:00:00close 2016-02-11 00:00:00long IHE and short PJP 2016-02-12 00:00:00close 2016-03-17 00:00:00long IHE and short PJP 2016-03-18 00:00:00close 2019-06-06 00:00:00long MUC and short MCA 2019-06-07 00:00:00close 2015-01-02 00:00:00long MLPX and short MIE 2015-01-28 00:00:00close 2015-02-04 00:00:00long MLPX and short MIE 2015-02-05 00:00:00close 2015-02-06 00:00:00long MLPX and short MIE 2015-02-10 00:00:00close 2015-02-24 00:00:00long MLPX and short MIE 2015-03-12 00:00:00close 2015-09-16 00:00:00long AMJ and short KYN 2015-09-30 00:00:00close 2016-11-14 00:00:00long IXP and short IYZ 2016-11-15 00:00:00close 2018-01-26 00:00:00long IYZ and short IXP 2018-01-29 00:00:00close 2018-02-01 00:00:00long IYZ and short IXP 2018-02-02 00:00:00close 2018-12-24 00:00:00long IXP and short IYZ 2018-12-26 00:00:00close 2016-02-11 00:00:00long IHE and short PPH 2016-02-12 00:00:00close 2016-03-17 00:00:00long IHE and short PPH 2016-03-18 00:00:00close 2016-11-03 00:00:00long IHE and short PPH 2016-11-04 00:00:00close 2016-11-03 00:00:00long IHE and short BBC 2016-11-04 00:00:00close 2015-07-13 00:00:00long IXJ and short IHE 2015-07-24 00:00:00close 2015-01-08 00:00:00long IEUS and short FGM 2015-02-09 00:00:00close 2015-02-11 00:00:00long IEUS and short FGM 2015-02-12 00:00:00close 2015-03-11 00:00:00long IEUS and short FGM 2015-03-18 00:00:00close 2015-03-19 00:00:00long IEUS and short FGM 2015-03-23 00:00:00close 2015-03-30 00:00:00long IEUS and short FGM 2015-03-31 00:00:00close 2015-04-02 00:00:00long IEUS and short FGM 2015-04-06 00:00:00close 2018-02-01 00:00:00long IBND and short FXE 2018-02-05 00:00:00close 2018-02-14 00:00:00long IBND and short FXE 2018-02-16 00:00:00close 2016-01-20 00:00:00long GMZ and short GER 2016-01-21 00:00:00close 2016-02-08 00:00:00long GMZ and short GER 2016-02-19 00:00:00close 2016-02-23 00:00:00long GMZ and short GER 2016-02-24 00:00:00close 2016-02-29 00:00:00long GMZ and short GER 2016-03-01 00:00:00close 2019-01-25 00:00:00long GER and short GMZ 2019-01-28 00:00:00close 2019-01-30 00:00:00long GER and short GMZ 2019-02-11 00:00:00close 2015-01-28 00:00:00long FBGX and short FLGE 2015-01-29 00:00:00close 2015-07-09 00:00:00long FBGX and short FLGE 2015-07-10 00:00:00close 2015-08-25 00:00:00long FBGX and short FLGE 2015-08-26 00:00:00close 2015-10-21 00:00:00long FLGE and short FBGX 2015-10-22 00:00:00close 2017-11-17 00:00:00long FBGX and short FLGE 2017-11-20 00:00:00close 2017-11-30 00:00:00long FBGX and short FLGE 2017-12-01 00:00:00close 2018-02-05 00:00:00long FLGE and short FBGX 2018-02-06 00:00:00close 2018-02-07 00:00:00long FLGE and short FBGX 2018-02-08 00:00:00close 2018-02-09 00:00:00long FLGE and short FBGX 2018-02-12 00:00:00close 2018-02-21 00:00:00long FLGE and short FBGX 2018-02-22 00:00:00close 2018-04-04 00:00:00long FBGX and short FLGE 2018-04-05 00:00:00close 2018-04-11 00:00:00long FLGE and short FBGX 2018-04-12 00:00:00close 2018-07-20 00:00:00long FLGE and short FBGX 2018-07-23 00:00:00close 2018-10-02 00:00:00long FLGE and short FBGX 2018-10-03 00:00:00close 2018-10-04 00:00:00long FLGE and short FBGX 2018-10-05 00:00:00close 2018-10-10 00:00:00long FBGX and short FLGE 2018-10-11 00:00:00close 2018-10-12 00:00:00long FLGE and short FBGX 2018-10-16 00:00:00close 2018-10-29 00:00:00long FLGE and short FBGX 2018-10-30 00:00:00close 2018-11-06 00:00:00long FLGE and short FBGX 2018-11-07 00:00:00close 2018-11-12 00:00:00long FLGE and short FBGX 2018-11-14 00:00:00close 2018-11-20 00:00:00long FLGE and short FBGX 2018-11-21 00:00:00close 2018-12-04 00:00:00long FLGE and short FBGX 2018-12-06 00:00:00close 2018-12-19 00:00:00long FLGE and short FBGX 2018-12-20 00:00:00close 2015-01-06 00:00:00long EWH and short CHN 2015-01-07 00:00:00close 2019-02-19 00:00:00long CHN and short EWH 2019-02-25 00:00:00close 2019-05-29 00:00:00long CHN and short EWH 2019-05-30 00:00:00close 2015-08-24 00:00:00long EEMA and short AAXJ 2015-08-25 00:00:00close 2016-06-28 00:00:00long AAXJ and short EEMA 2016-06-29 00:00:00close 2017-08-18 00:00:00long AAXJ and short EEMA 2017-08-21 00:00:00close 2019-05-01 00:00:00long EEMA and short AAXJ 2019-05-02 00:00:00close 2019-05-03 00:00:00long EEMA and short AAXJ 2019-05-06 00:00:00close 2019-06-18 00:00:00long EEMA and short AAXJ 2019-06-19 00:00:00close 2019-06-20 00:00:00long EEMA and short AAXJ 2019-06-26 00:00:00close 2019-06-27 00:00:00long EEMA and short AAXJ 2019-08-02 00:00:00close 2015-01-02 00:00:00long DPK and short EWV 2015-01-28 00:00:00close 2015-01-30 00:00:00long DPK and short EWV 2015-02-11 00:00:00close 2015-02-12 00:00:00long DPK and short EWV 2015-02-13 00:00:00close 2015-01-02 00:00:00long EFU and short DPK 2015-01-26 00:00:00close 2015-01-28 00:00:00long EFU and short DPK 2015-01-29 00:00:00close 2015-01-30 00:00:00long EFU and short DPK 2015-02-02 00:00:00close 2016-01-15 00:00:00long EFU and short DPK 2016-01-19 00:00:00close 2016-01-20 00:00:00long EFU and short DPK 2016-01-22 00:00:00close 2016-02-08 00:00:00long EFU and short DPK 2016-02-16 00:00:00close 2017-04-18 00:00:00long DGZ and short DZZ 2017-04-24 00:00:00close 2018-08-01 00:00:00long DZZ and short DGZ 2018-08-02 00:00:00close 2018-08-07 00:00:00long DZZ and short DGZ 2018-08-09 00:00:00close 2018-08-10 00:00:00long DZZ and short DGZ 2018-08-13 00:00:00close 2018-08-14 00:00:00long DZZ and short DGZ 2018-08-16 00:00:00close 2018-08-17 00:00:00long DZZ and short DGZ 2018-08-20 00:00:00close 2018-08-21 00:00:00long DZZ and short DGZ 2018-08-23 00:00:00close 2015-01-02 00:00:00long AMLP and short CEM 2015-01-05 00:00:00close 2015-02-27 00:00:00long AMLP and short CEM 2015-03-03 00:00:00close 2015-03-05 00:00:00long AMLP and short CEM 2015-03-09 00:00:00close 2016-01-20 00:00:00long CEM and short AMLP 2016-01-21 00:00:00close 2016-02-10 00:00:00long CEM and short AMLP 2016-02-12 00:00:00close 2015-01-02 00:00:00long EWZS and short BRZU 2015-01-05 00:00:00close 2015-01-07 00:00:00long EWZS and short BRZU 2015-01-30 00:00:00close 2015-02-03 00:00:00long EWZS and short BRZU 2015-02-04 00:00:00close 2015-02-05 00:00:00long EWZS and short BRZU 2015-02-06 00:00:00close 2015-02-24 00:00:00long EWZS and short BRZU 2015-02-25 00:00:00close 2015-04-23 00:00:00long EWZS and short BRZU 2015-04-30 00:00:00close 2015-05-05 00:00:00long EWZS and short BRZU 2015-05-13 00:00:00close 2015-05-14 00:00:00long EWZS and short BRZU 2015-05-18 00:00:00close
2015-01-14 00:00:00long PEO and short BGR 2015-01-15 00:00:00close 2015-01-22 00:00:00long PEO and short BGR 2015-02-03 00:00:00close 2015-02-04 00:00:00long PEO and short BGR 2015-02-09 00:00:00close 2015-02-11 00:00:00long PEO and short BGR 2015-02-13 00:00:00close 2015-02-23 00:00:00long PEO and short BGR 2015-02-24 00:00:00close 2015-02-26 00:00:00long PEO and short BGR 2015-03-18 00:00:00close 2015-03-19 00:00:00long PEO and short BGR 2015-03-20 00:00:00close 2015-03-23 00:00:00long PEO and short BGR 2015-03-30 00:00:00close 2015-01-02 00:00:00long MLPA and short AMLP 2015-01-14 00:00:00close 2015-01-16 00:00:00long MLPA and short AMLP 2015-02-11 00:00:00close 2015-02-20 00:00:00long MLPA and short AMLP 2015-02-23 00:00:00close 2015-02-25 00:00:00long MLPA and short AMLP 2015-02-26 00:00:00close 2015-02-27 00:00:00long MLPA and short AMLP 2015-03-02 00:00:00close 2015-05-01 00:00:00long MLPA and short AMLP 2015-05-04 00:00:00close 2016-02-08 00:00:00long AMLP and short MLPA 2016-02-09 00:00:00close 2016-02-10 00:00:00long AMLP and short MLPA 2016-02-12 00:00:00close

Take RWR and REZ as an example. The upper part of the following chart plots the stock prices of pair RWR vs REZ. The lower part plots how many times residuals deviate from its mean. There are 4 trading opportunities if we set the opening threshold to be 2.56.

In [334]:
data = web.DataReader(['EWH','CHN'], 'yahoo', start, end)['Adj Close']
plt.figure()
data.plot()

reg = LinearRegression().fit(data['EWH'].values.reshape(-1,1), data['CHN'])
beta = reg.coef_
residual = data['EWH'] - beta * data['CHN']
error = residual - np.mean(residual)
std = np.std(residual)

plt.figure()
plt.plot(error)
plt.hlines(cutoff*std,start,end)
plt.hlines(-cutoff*std,start,end)
Out[334]:
<matplotlib.collections.LineCollection at 0x1b3f0d18b70>
<Figure size 432x288 with 0 Axes>
Notebook Image
Notebook Image

VECM

\(\Delta P_t = \Pi P_{t-1} + \Gamma \Delta P_{t-1} + u_t\)

We want to decompose \(\Delta P_t\) as these three parts above.

In [147]:
from statsmodels.tsa.vector_ar.vecm import VECM, select_order
start = datetime.datetime(2015, 1, 1)
end = datetime.datetime.today()
data = web.DataReader(['MUC','MCA'], 'yahoo', start, end)['Adj Close']

We use first 100 data as "in-sample data" to predict 10 data as "out-of-sample data".

In [70]:
rolling_data = data[:100]
model_det = VECM(rolling_data, k_ar_diff=1, coint_rank=1, deterministic="ci")
det_vecm_res = model_det.fit()
pi = np.dot(det_vecm_res.alpha,det_vecm_res.beta.T)
predict = pd.DataFrame(data=det_vecm_res.predict(steps=10), index=data[100:110].index, columns=data.columns)

sigma_u = np.tile(np.sqrt(np.diag(det_vecm_res.sigma_u)), (10,1))
sigma_u = pd.DataFrame(data=sigma_u, index=data[100:110].index, columns=data.columns)
sigma_u
Out[70]:

Following is the cointegration part \(\Pi P_{t-1} \).

In [71]:
coint = np.zeros((10,2))
coint[0] = np.dot(pi, data.iloc[99])
coint[1:10] = np.dot(pi, predict[:-1].T).T
coint = pd.DataFrame(data=coint, index=data[100:110].index, columns=data.columns)
coint
Out[71]:

Next is AR(1) part \(\Gamma \Delta P_{t-1}\).

In [72]:
ar = np.zeros((10,2))
ar[0] = np.dot(det_vecm_res.gamma, data.diff().iloc[99])
ar[1:10] = np.dot(det_vecm_res.gamma, predict[:-1].T).T
ar = pd.DataFrame(data=ar, index=data[100:110].index, columns=data.columns)
ar
Out[72]:

We use \(u_t = \Delta P_t - \Pi P_{t-1} - \Gamma \Delta P_{t-1} \) to get \(u_t\).

Then decompose \(u_t = \alpha_t + \epsilon_t\).

In [73]:
pred_diff = predict.diff()
#  set the first pred_diff to 0 
pred_diff.iloc[0] = 0
u = pred_diff - coint - ar
display(u)
# decompose U = alpha + error
error = u - np.mean(u[1:])
error
Out[73]:
In [135]:
det_vecm_res.summary()
Out[135]:
In [449]:
det_vecm_res.plot_forecast(steps=10, n_last_obs=100)
Notebook Image

rolling window

Take 'EWH' and 'CHN' as an example.

In [245]:
from statsmodels.tsa.vector_ar.vecm import VECM, select_order
import warnings
warnings.filterwarnings("ignore")
from sklearn.linear_model import LinearRegression

start = datetime.datetime(2015, 1, 1)
end = datetime.datetime.today()
data = web.DataReader(['EWH','CHN'], 'yahoo', start, end)['Adj Close']
rw_num = 100
pred_num = 10

pred_err_result = pd.DataFrame(columns=data.columns)
coint_result = pd.DataFrame(columns=data.columns)
ar_result = pd.DataFrame(columns=data.columns)
pred_diff_result = pd.DataFrame(columns=data.columns)
sigma_u_result = pd.DataFrame(columns=data.columns)
error_result = pd.DataFrame(columns=data.columns)
beta = pd.Series(index = data[rw_num:].index)

for i in range(1,len(data)-rw_num-pred_num+2, pred_num):
    rolling_data = data[i-1 : i+rw_num-1]
    model_det = VECM(rolling_data, k_ar_diff=1, coint_rank=1, deterministic="ci")
    det_vecm_res = model_det.fit()
    pi = np.dot(det_vecm_res.alpha,det_vecm_res.beta.T)
    gamma = det_vecm_res.gamma
    
    sigma_u = np.tile(np.sqrt(np.diag(det_vecm_res.sigma_u)), (pred_num,1))
    sigma_u = pd.DataFrame(data=sigma_u, index=data[i+rw_num-1 : i+rw_num-1+pred_num].index, columns=data.columns)
    sigma_u_result = sigma_u_result.append(sigma_u)
    
    predict = pd.DataFrame(data=det_vecm_res.predict(steps=pred_num), index=data[i+rw_num-1 : i+rw_num-1+pred_num].index, columns=data.columns)
    prediction_error = data[i+rw_num-1 : i+rw_num+pred_num-1] - predict
    pred_err_result = pred_err_result.append(prediction_error)
    
    #decompose
    coint = np.zeros((pred_num,2))
    coint[0] = np.dot(pi, data.iloc[i+rw_num-2])
    coint[1:pred_num] = np.dot(pi, predict[:-1].T).T
    coint = pd.DataFrame(data=coint, index=data[i+rw_num-1 : i+rw_num-1+pred_num].index, columns=data.columns)
    coint_result = coint_result.append(coint)
    
    ar = np.zeros((pred_num,2))
    ar[0] = np.dot(det_vecm_res.gamma, data.diff().iloc[i+rw_num-2])
    ar[1:pred_num] = np.dot(det_vecm_res.gamma, predict[:-1].T).T
    ar = pd.DataFrame(data=ar, index=data[i+rw_num-1 : i+rw_num-1+pred_num].index, columns=data.columns)
    ar_result= ar_result.append(ar)
    
    pred_diff = predict.diff()
    # set the first pred_diff to 0 rather than use the last data point.
    pred_diff.iloc[0] = 0
    #pred_diff.iloc[0] = predict.iloc[0] - rolling_data.iloc[-1]
    pred_diff_result= pred_diff_result.append(pred_diff)
    
    u = pred_diff - coint - ar
    #u_result = u_result.append(u)
    # decompose U = alpha + error
    error = u - np.mean(u[1:])
    error_result = error_result.append(error)
    
    # the coefficient of the cointegration relationship
    reg = LinearRegression().fit(rolling_data.iloc[:,1].values.reshape(-1,1), rolling_data.iloc[:,0])
    beta[i-1:i-1+pred_num] = float(reg.coef_)
    
AorB = 0
plt.figure()
plt.plot(pred_diff_result.iloc[:,AorB],label='pred_diff')
plt.plot(error_result.iloc[:,AorB],label='error')
plt.plot(coint_result.iloc[:,AorB],label='coint')
plt.plot(ar_result.iloc[:,AorB],label='AR1')
plt.title(coint_result.columns[AorB])
plt.legend()

plt.figure()
plt.plot(sigma_u_result.iloc[:,AorB],label='sigma_u')
plt.plot(coint_result.iloc[:,AorB],label='coint')
plt.title(coint_result.columns[AorB])
plt.legend()

plt.figure()
plt.plot(coint_result.iloc[:,AorB],label='coint')
plt.legend()
plt.title(coint_result.columns[AorB])
plt.hlines([1,-1],start,end)

Out[245]:
<matplotlib.collections.LineCollection at 0x21695d102e8>
Notebook Image
Notebook Image
Notebook Image

The trading rule is that we enter a trade when coint is above 1 or below -1.

There are 6 pairs that passed two cointegration tests.

In [225]:
all_results = [('VKQ', 'IQI'),('GER', 'GMZ'), ('MUC', 'MCA'),('DGZ', 'DZZ'),('EEMA', 'AAXJ'),('EWH', 'CHN')]
all_results
Out[225]:
[('VKQ', 'IQI'),
 ('GER', 'GMZ'),
 ('MUC', 'MCA'),
 ('DGZ', 'DZZ'),
 ('EEMA', 'AAXJ'),
 ('EWH', 'CHN')]
In [250]:
from statsmodels.tsa.vector_ar.vecm import VECM, select_order
import warnings
warnings.filterwarnings("ignore")
from sklearn.linear_model import LinearRegression

start = datetime.datetime(2015, 1, 1)
end = datetime.datetime.today()
rw_num = 100
pred_num = 10
AorB = 0
threshold = 1

for j in range(len(all_results)):
    data = web.DataReader([all_results[j][0],all_results[j][1]], 'yahoo', start, end)['Adj Close']
    coint_result = pd.DataFrame(columns=data.columns)
    beta = pd.Series(index = data[rw_num:].index)

    for i in range(1,len(data)-rw_num-pred_num+2, pred_num):
        rolling_data = data[i-1 : i+rw_num-1]
        model_det = VECM(rolling_data, k_ar_diff=1, coint_rank=1, deterministic="ci")
        det_vecm_res = model_det.fit()
        pi = np.dot(det_vecm_res.alpha,det_vecm_res.beta.T)
        predict = pd.DataFrame(data=det_vecm_res.predict(steps=pred_num), index=data[i+rw_num-1 : i+rw_num-1+pred_num].index, columns=data.columns)
        #decompose
        coint = np.zeros((pred_num,2))
        coint[0] = np.dot(pi, data.iloc[i+rw_num-2])
        coint[1:pred_num] = np.dot(pi, predict[:-1].T).T
        coint = pd.DataFrame(data=coint, index=data[i+rw_num-1 : i+rw_num-1+pred_num].index, columns=data.columns)
        coint_result = coint_result.append(coint)

        # the coefficient of the cointegration relationship
        reg = LinearRegression().fit(rolling_data.iloc[:,1].values.reshape(-1,1), rolling_data.iloc[:,0])
        beta[i-1:i-1+pred_num] = float(reg.coef_)
    
    touch = 0
    PNL = pd.Series(index = coint_result.index)
    PNL.iloc[-1] =0
    enter = pd.DataFrame(columns=['enter','coint','long','price','short','price'])
    exit = pd.DataFrame(columns=['exit','coint','long','price','short','price'])
    trade_num = 0

    for k in range(len(coint_result)): 
        if touch == 0:
            PNL.iloc[k] = PNL.iloc[k-1]
            if coint_result.iloc[k,AorB] > threshold:
                enter.loc[trade_num] = [coint_result.index[k],coint_result.iloc[k,AorB],coint_result.columns[1],data.iloc[k+rw_num][1],coint_result.columns[0],data.iloc[k+rw_num][0]]
                touch = 1
            if coint_result.iloc[k,AorB] < -threshold:
                enter.loc[trade_num] = [coint_result.index[k],coint_result.iloc[k,AorB],coint_result.columns[0],data.iloc[k+rw_num][0],coint_result.columns[1],data.iloc[k+rw_num][1]]
                touch = -1
        else:
            deltaPA = data.iloc[k+rw_num][0] - data.iloc[k+rw_num-1][0]
            deltaPB = data.iloc[k+rw_num][1] - data.iloc[k+rw_num-1][1]
            PNL.iloc[k] = PNL.iloc[k-1] + deltaPA + beta[k]*deltaPB
            if touch > 0:
                if coint_result.iloc[k,AorB] <= threshold:
                    exit.loc[trade_num] = [coint_result.index[k],coint_result.iloc[k,AorB],coint_result.columns[1],data.iloc[k+rw_num][1],coint_result.columns[0],data.iloc[k+rw_num][0]]
                    touch = 0
                    trade_num += 1
            else:
                if coint_result.iloc[k,AorB] >= -threshold:
                    exit.loc[trade_num] = [coint_result.index[k],coint_result.iloc[k,AorB],coint_result.columns[0],data.iloc[k+rw_num][0],coint_result.columns[1],data.iloc[k+rw_num][1]]
                    touch = 0
                    trade_num += 1
    if touch != 0:
        exit.loc[trade_num] = [coint_result.index[k-1],coint_result.iloc[k-1,AorB],enter.iloc[-1][2],data.iloc[k+rw_num-1][enter.iloc[-1][2]],enter.iloc[-1][4],data.iloc[k+rw_num-1][enter.iloc[-1][4]]]

    trade_table = pd.concat([enter, exit], axis=1, join='outer')
    display(trade_table)
    plt.figure()
    plt.plot(PNL)
    plt.title(all_results[j])


Notebook Image
Notebook Image
Notebook Image
Notebook Image
Notebook Image
Notebook Image

Reference

[1] Kris Longmore, Exploring mean reversion and cointegration: part 2(Jan 02, 2016).https://robotwealth.com/exploring-mean-reversion-and-cointegration-part-2/

[2] Intraday Dynamic Pairs Trading using Correlation and Cointegration Approach. https://www.quantconnect.com/tutorials/strategy-library

[3] Zhe Huang, Franck Martin. Optimal pairs trading strategies in a cointegration framework. 2017. ￿halshs-01566803

The next work is to find out why this integration relationship exists.

In [ ]:
import jovian 
jovian.commit()
[jovian] Saving notebook..
In [ ]: