Pair Trading - Exploring The Low Risk Statistical Arbitrage Trading Concepts

Syndibank-andhrabank / p-value: 0.000355 / z-score: 2.019)

HCLTech-TCS / p-value: 0.0191 / z-score: (-2.248)

Unionbank-PNB / p-value: 0.0201 / z-score: (-2.007)

andhrabank-bankbaroda/ p-value: 0.000881 / z-score: (-2.6)
HDFC-Ibulhsgfin / p-value: 0.0214 / z-score: 2.174

Hi @VJAY,
Please check HCLTech-TCS, I am getting p-value: 0.0378 and z-score: +2.248
Thanks.
 

VJAY

Well-Known Member
HDFC-Ibulhsgfin / p-value: 0.0214 / z-score: 2.174

Hi @VJAY,
Please check HCLTech-TCS, I am getting p-value: 0.0378 and z-score: +2.248
Thanks.
Thanks vevensa...yes Zscore wrongly put (-) ...but p-value after checking still its same !!!!
 

VJAY

Well-Known Member
You could use the following function
Python:
df = pd.read_excel(FILENAME, SHEETNAME) # Replace FILENAME and SHEETNAME
df[df['zscore'] < 0.05] # replace zscore with the actual column name in Excel
Dear UB,
its not what I want...i have my scrips in stockdata file which I use for pairtrading...now I check p-value of pairs which I want to check by put scrip names (pair)manually and run that cell to get p-value.....so I want to get pairs (multi combinations from my data file)which have p-value below 0.05 automaticly runing a cell ..so i dont need to check manualy every pair ....so i can check only thrown pairs by code
 

ncube

Well-Known Member
Dear UB,
its not what I want...i have my scrips in stockdata file which I use for pairtrading...now I check p-value of pairs which I want to check by put scrip names (pair)manually and run that cell to get p-value.....so I want to get pairs (multi combinations from my data file)which have p-value below 0.05 automaticly runing a cell ..so i dont need to check manualy every pair ....so i can check only thrown pairs by code
@VJAY, I know what you are asking for, its the same that @Vevensa_P had asked earlier, instead of all the 500 stock combinations you are asking for the few stocks that you are monitoring in the excel sheet. As I said earlier this would require some new coding effort and at the moment I am slightly busy with my work. Once I get some free time I will try to share some code.
 

VJAY

Well-Known Member
@VJAY, I know what you are asking for, its the same that @Vevensa_P had asked earlier, instead of all the 500 stock combinations you are asking for the few stocks that you are monitoring in the excel sheet. As I said earlier this would require some new coding effort and at the moment I am slightly busy with my work. Once I get some free time I will try to share some code.
Thanks brother.... NP take your time...its not any urgent thing....:)
 

VJAY

Well-Known Member
hindzinc-nmdc/ p-value: 0.00498 / z-score: (-2.551)
andhrabank-banknaroda/ p-value: 0.000979 / z-score: (-2.068)
 

ncube

Well-Known Member
@VJAY, I know what you are asking for, its the same that @Vevensa_P had asked earlier, instead of all the 500 stock combinations you are asking for the few stocks that you are monitoring in the excel sheet. As I said earlier this would require some new coding effort and at the moment I am slightly busy with my work. Once I get some free time I will try to share some code.
@VJAY @Vevensa_P, Add the following function "find_pair_coint()" in the function section and you can call it as follows, "find_pair_coint(returns,0.05)" if you want to find pairs with coint significance less than 0.01 then change the 2nd parameter to 0.01 instead of 0.05. Please ensure that you dont have many stocks in the excel sheet, else it will run all the combinations and output the pairs which will be in lakhs. Better limit it to max 25 pairs (50 stocks)

1536555431980.png


Code:
def find_pair_coint(data, significance=0.05):
    n = data.shape[1]
    keys = data.keys()
    for i in range(n):
        for j in range(i+1, n):
            S1 = data[keys[i]]
            S2 = data[keys[j]]
            result = coint(S1, S2)
            pvalue = result[1]
            if pvalue < significance:
                print((keys[i], keys[j]),round(pvalue,5))
Code:
find_pair_coint(returns,0.05)
Another update, I ran backtesting for the 30 min break out for all the pairs for last 5 years and the results are not that significant for intra-day (30min candle breakout and close the trade at eod). Its giving good result for positional trades only. For intraday it would require active monitoring and use discretionary price action methods to generate profits. Hence I would not encourage this strategy and trade this only if you can monitor the trade continuously.

On the other hand 15min breakout in the direction of prominent trend for both stocks and closing the trade at abt 0.03%-0.05% is giving better results, hence you can explore this method.

However I always believe the ultimate goal for every trader should be Positional trading as it is less stressful and objective should be to have a life outside trading and not spend the whole day in front of monitor.
 

VJAY

Well-Known Member
Dear ncube,
Thanks for the code..Yes I too think pair trading is better to trade positional