Pair Trading - Exploring The Low Risk Statistical Arbitrage Trading Concepts

UberMachine

Well-Known Member
@UberMachine , I have already explained these points in my earlier posts, maybe you can once read this thread from the begining. That is one reason why I want to keep this thread simple and clean so that people new to Pair trading find information and understand the basics strategy and not get overwhelmed with complex concepts which are not required for day trading the pairs. Once they are familiar with the basics they can then explore other complex concepts and methods to automate it.

Just to briefly answer your queries:
How to select pairs?

>> Select pairs which has co-integration significance value less than 0.05, lower the value better.
What is the look back window?
>> In the script I have shared I have used 200 days for co-integration & 20 days for zScore calculations. These values are fine for day trading.
How to set entry and exit prices?
>> I have suggested the 1st 30 min candle break out strategy to trade the pairs, if one can understand the core idea of pair trading they can come up with their own strategy.
What and threshold to use?
>> Usually a zScore value more than +/- 2 SD is good to initiate the trades. However this is more applicable for position trading as one need enough buffer, for day trading even a lower threshold should be fine.
How to backtest this strategy?
>> One can use zScore values in association with the stock closing prices for backtesting. However for day trading I do not see much benefit of doing this as one can easily perform direct walk-forward testing for few days to understand the characteristics of the pair. One can just select few good co-integrating pairs and trade on it till the co-integration falls apart.

But If one wants to position trade it they can use reinforcement machine learning models or deep learning models to identify pairs which show similar characteristics, but these are complex methods and I dont recommend it to beginners. In trading its always better to keep it as simple as possible, more complexities does not mean more profits.

Also as we discussed earlier, lets keep the automation/coding and tool specific discussion in a separate thread.
Thanks @ncube . I just wanted to reiterate the above said points for further full-fledged development including auto-selection of pairs and using the ratio method to explore further.
 

ncube

Well-Known Member
Thanks @ncube . I just wanted to reiterate the above said points for further full-fledged development including auto-selection of pairs and using the ratio method to explore further.
Ok, just to share my experience on automation if it can help you in the development, usually I have observed people try to run regressions to find the best parameter values on historical and test data which can generates the highest profits. However this is not a good approach, its just over-fitting. Stock price movements are always random and trying a linear model on it will not be effective. Best trading strategy is one which trades a concept or Idea and not influenced by parameter values. Parameters can be used as guides but our trading strategy should not be dependent of specific parameter values.

For example, one can run N number of iterations on historical data with different moving average values and find that 59 day moving average gives the best result compared to a 20 day moving average, however let me assure you that it will never work on future data. Hence the strategy should be designed such that the results should not vary much either you choose 20 days or 59 days moving average.

Hope everyone is able to understand what I am saying...I try to keep it simple but sometimes its difficult to explain my thoughts and I get complaints that my writing style is more of a thesis..rather than in plain english...:)
 
Last edited:

VJAY

Well-Known Member
Dear ncube,
Pairs I following(paper trade) after my first loss trade in real am seeing every trade failure as Y scrip is failing X scrip is winning but thing is first Y scrip triggers then fails then X scrip triggers...so profit not there ...are you experiencing it in your live trades?
 

UberMachine

Well-Known Member
Ok, just to share my experience on automation if it can help you in the development, usually I have observed people try to run regressions to find the best parameter values on historical and test data which can generates the highest profits. However this is not a good approach, its just over-fitting. Stock price movements are always random and trying a linear model on it will not be effective. Best trading strategy is one which trades a concept or Idea and not influenced by parameter values. Parameters can be used as guides but our trading strategy should not be dependent of specific parameter values.

For example, one can run N number of iterations on historical data with different moving average values and find that 59 day moving average gives the best result compared to a 20 day moving average, however let me assure you that it will never work on future data. Hence the strategy should be designed such that the results should not vary much either you choose 20 days or 59 days moving average.

Hope everyone is able to understand what I am saying...I try to keep it simple but sometimes its difficult to explain my thoughts and I get complaints that my writing style is more of a thesis..rather than in plain english...:)
@ncube
Good going mate.

Almost all stock market movements are random in the short run and I use relative measures for stock selection (that's why I prefer ratios to spread).
That said, if the parameters themselves exhibit some statistically significant pattern, say that for each moving average window gets your profit gets smaller or bigger, then we could have a safe assumption that there is a relationship between the window size and the results.

Extending the pair trading example, I assume that given a bigger window length there is a greater chance that the mean reverts back upto a point from where the series would start diverging (In simple terms, say my strategy works well upto 120 days rolling average after which the results are unpredictable). Knowing this range makes me more comfortable.

And (+1) for pointing out, that the strategy must be backed up by results, the results shouldn't be used to arrive at strategies.
We can tune our strategies based on results but making strategies based on results is a sure recipe for disaster and I think most stock tips providers do the same.

And (+1) for over fitting, look-ahead bias and linear regression

But optimizing too much in finance is worse than premature optimization in code :)
 

ncube

Well-Known Member
Dear ncube,
Pairs I following(paper trade) after my first loss trade in real am seeing every trade failure as Y scrip is failing X scrip is winning but thing is first Y scrip triggers then fails then X scrip triggers...so profit not there ...are you experiencing it in your live trades?
@VJAY, sure not all trades will be successful some will fail but over few trades the net results should be positive. You can try the following to improve your pair selection for each day:
1. If selecting multiple pairs, try to select pairs from different sectors. This will ensure all the pairs do not behave similar. Sometimes if there is volatility in the sector, all the pairs in the same sector will move similarly.
2. Some pairs by nature are volatile, if so try to avoid trading them.

I do not regularly day trade pairs, however in the last 2 months for the trades I have taken (about 50 odd) for testing the overall results have been good.
 

UberMachine

Well-Known Member
Dear ncube,
Pairs I following(paper trade) after my first loss trade in real am seeing every trade failure as Y scrip is failing X scrip is winning but thing is first Y scrip triggers then fails then X scrip triggers...so profit not there ...are you experiencing it in your live trades?
What pairs do you use?
And how you record your paper trades?
Can you upload the Excel File if available?
 

nurav

Well-Known Member
1533308064248.png

This is a spread of HDFCBANK and SBI in the ratio of 1:8. Varun sir's customised code which he trades daily as bread and butter. I beleive it is better to stick to the same pair daily. This is intraday short HDFCBANK and Long SBI as per this chart. Entry was at -229 levels and exit was at 3:15 at -277.
The bias to go short this pair comes from the prices being below the pink sloping line. 48 Points per spread. for 100 shares HDFCbank short and 800SBI plus around 4800.