Calculate ways to select trading stock pairs in long/short
Quantifying portfolio-selection and backtest search spaces.
Combinatorics sucks; it seems simple on the surface, but forming a concrete intuition for it seems practically impossible at the moment. Maybe I just need an alpha, lol. On a more serious note, I need a way to form a strong mental understanding of it without mentally referring to known examples.
Lesson: https://github.com/dashn9/learningquant/blob/main/src/lessons/trading_pairs.rs
PROBLEM:
You have 8 distinct stocks: 5 technology stocks and 3 energy stocks.
- Unordered pair: How many ways can you select 2 stocks for a trading pair? Selecting Stock A and Stock B is the same as selecting Stock B and Stock A.
- Constrained selection: How many pairs contain exactly 1 technology stock and 1 energy stock?
- Compare with permutations: Using all 8 stocks, how many ways can you choose one stock to go long and a different stock to go short? Here, long A / short B differs from long B / short A. How does this count compare with part 1, and why?
Solution:
- In my own thought, this would be that you only care about two positions for the entire 8 stocks, so it creates a permutation of 8!/6!, but we are looking for a combination of two positions where order is irrelevant, therefore 8!/6!2!. In my head, I like to picture it as grouping the two positions in a manner that any number of the 8 sticks can flow into two slots in any number of unique ways; dividing it by 2! means they have to flow in non uniquely. You can conceptualize this using smaller numbers.
- 5!/4! * 3!/2!. My thought is you are looking for 1 position across 5 items(call group A) and 1 position across 3 items(call group B). For every item you pick in A, you must pick all in B, but not vice versa, because the problem says exactly 1 pair for any unique items and it must be constrained, meaning each pair must not hold duplicates irrespective of the position of items in the pair; therefore, a combination and not a permutation.
- This has a strong correlation to problem 1; unlike problem 1, which is a combination, we use permutation here because the stock positions are unique. Just get rid of the 2! and you get your answer. The long/short is not a smokescreen per se, but rather another way to look at it is in the pair, say {X, Y}; both are unique positions, and through the pairs, any of the stocks should fit in both positions, with the rest of the stocks making a unique pair; e.g., 1 of the stocks should fit with 7 others. 2! eliminates the extra non-unique pairs. The answer is 8!/6!
This wraps up my basic stats learning and writing for now, for “geometric, binomial, and Poisson distributions”, and “using the normal distributions i/ii”; I will read them without writing on.
The next ones will be my real-world experiences building and running these models with pure stats on live markets and real money in full detail.
Note: These are notes from my learning journey; please do not implement the strategy with real money unless you know what you are doing.