@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)
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.