Advanced pair trading in Python: beta loading, optimal entry, and stop-losses

  Рет қаралды 10,524

NEDL

NEDL

Күн бұрын

Пікірлер: 27
@NEDLeducation
@NEDLeducation 3 жыл бұрын
You can find the .ipynb for this video and some additional materials here: drive.google.com/drive/folders/1sP40IW0p0w5IETCgo464uhDFfdyR6rh7 Please consider supporting NEDL on Patreon: www.patreon.com/NEDLeducation
@shaaf9817
@shaaf9817 3 жыл бұрын
wow a real algo trading channel that isnt just about RSI and indicators
@kessler88
@kessler88 3 жыл бұрын
As always, impressive content and superior execution Savva :) Love it!
@cassioandrade6233
@cassioandrade6233 3 жыл бұрын
Parabéns Savva, obrigado por compatilhar!👏👏👏
@johnsmith-qc8ud
@johnsmith-qc8ud 3 жыл бұрын
Savva, thanks for all your efforts! Your channel makes some advanced econometrics and statistics concepts easier to understand. A couple of bugs in the above video: fee = 0.0001 isn't realistic enough. You used 0.001 in previous videos. And if you use that value here, the results won't be ok anymore. 20:10 you mistyped the "signal" variable identifer. That's why strictly typed languages which require to declare variables first still rule the world :)
@NEDLeducation
@NEDLeducation 3 жыл бұрын
Hi John, and thanks for the kind words! Glad you liked the video. As for your questions: 1) yes, this strategy is quite sensitive to trading costs, to do well with high fees you have to select very high optimal entry thresholds and monitor multiple pairs simultaneously for trading opportunities; 2) thanks for pointing this out, will correct the typo, but funnily this does not affect the logic of the code as in this very step signal has to be kept equal to the previous value of the signal :)
@ekolytih
@ekolytih 2 жыл бұрын
As always thanks so much on posting such high quality content w/ detailed walkthrough! Just a minor suggestion on your coding style that you shall consider decouple functions / utilities for easier troubleshooting and future re-factoring :)
@bryan-9742
@bryan-9742 2 жыл бұрын
question. I noticed you use prices in this methodology. Would using log returns be more relevant to maintaining the relationship? I just implemented this strategy in digital assets and my results were fairly poor for the pair I choose and I was wondering whether this could be the reason why.
@slavashalel2390
@slavashalel2390 3 жыл бұрын
вы супер, начну спонсировать со след зп !
@NEDLeducation
@NEDLeducation 3 жыл бұрын
Огромное спасибо :)
@fatdog000
@fatdog000 8 ай бұрын
is it possible to combine this with a Kalman filter? if so can you show how? ive seen similar approaches online when its applied to z score of the rolling hedged spread
@neuvocastezero1838
@neuvocastezero1838 Ай бұрын
Thanks for the video, I understood some of it. The way the strategy is explained, it sounds like we're setting a stop loss at 5%, but the potential profit when equilibrium is restored is only 2%, so it seems that this would be profitable only with an exceptionally high win rate. Is this assessment correct, or am I missing something?
@nicolabarbaro9477
@nicolabarbaro9477 Жыл бұрын
Great content Savva. Are you thinking about expanding the code as to take in to consideration more than 2 tickers? For example analyzing more tickers (10/20?) and choosing the ones with lowest KPSS?
@NEDLeducation
@NEDLeducation Жыл бұрын
Hi Nicola, and glad you are enjoying the channel! It is possible to do that by implementing a loop and recording KPSS statistics in a dataframe, I was considering doing that, but the tutorial was simply too bulky and long. Might come back to it at some point with a fresh mind :)
@tanberzaman349
@tanberzaman349 3 жыл бұрын
Love this, thank you so much, this is exactly what I was looking for :) Quick question, i was wondering if i could do a regression with multiple independent variables, for example how would I see how the yield curve moving as a whole, or growth and inflation as a whole vs. my dependent variables like Equities, Commodity and Currency asset classes and subcomponents and constiuents? Thank you so much. I'm a huge fan of your work.
@NEDLeducation
@NEDLeducation 3 жыл бұрын
Hi Tanber, and glad you liked the video! As for your question, you could get the data on your macroeconomic aggregates on the highest frequency possible and then match these with returns of your asset classes.
@FabioGaldony
@FabioGaldony 3 жыл бұрын
Какие брокеры дают работать через библиотеку Python?
@mallerktrading2616
@mallerktrading2616 3 жыл бұрын
Dear Savva, thanks you for your videos. I have watched ur last pair trading video and currently this one I still don't understand how the (t) sample goes in the loop u are calling the (t) of the same day using the same day closing price to calculate models and trading on the same day closing price used in the model. Correct me if am wrong dear. Because I still don't understand how u make decision of the next trading day if is overvalued or undervalued
@NEDLeducation
@NEDLeducation 3 жыл бұрын
Hi, and thanks for the question. Here, the model does look onto the next trading day to calculate the return, in the same loop, but to form a prediction, it does only use the prices that are available as of today.
@zumus2
@zumus2 3 жыл бұрын
Hi Nedl. Can you explain a bit more when it comes to real trading of your case, How many lot is going to long/short for each stocks? Many thanks!
@NEDLeducation
@NEDLeducation 3 жыл бұрын
Hi, and thanks for the question! It depends on portfolio value. The weights represent which proportion of it goes towards a particular position. For example, if $10,000 being traded, and you have a weight of 1.2 for the first stock and -0.8 for the second stock, you open a long position worth $12,000 for the first and a short position worth $8,000 for the second.
@maciekspinoff7246
@maciekspinoff7246 2 жыл бұрын
Why do you put function definitions inside a loop?
@NEDLeducation
@NEDLeducation 2 жыл бұрын
Hi Maciek, and thanks for the excellent question! This has to do with the use of scipy.optimize function, as it has to be coded inside the loop and the function has to use data that is both defined inside a loop and cannot be given as an argument of a defined function (since scipy.optimize requires all arguments to be variable). Hope this helps!
@maciekspinoff7246
@maciekspinoff7246 2 жыл бұрын
@@NEDLeducation Of course it works as expected, but it would be more elegant if both functions were defined separately and called in the loop with all required inputs passed as parameters.
@bryan-9742
@bryan-9742 2 жыл бұрын
NEDL I think there is an error in the code on beta loading when you're taking the return. see below: rets0 = np.array(raw_data[tickers[0]][t-window:t-1])/np.array(raw_data[tickers[0]][t-window+1:t]) - 1 If we agree that returns equal p1-p0/p0 = p1/p0-1 Then it seems that you're taking p0/p1 -1 instead of p1/p0 -1. let t = 8, window = 7: this code would yield the following: np.array(raw_data[ticker[0]][8-7: 8-1])/np.array(raw_data[ticker[0]][8-7+1:t]) - 1 = np.array(raw_data[ticker[0]][1: 7])/np.array(raw_data[ticker[0]][2:8]) - 1 here you can clearly see if you're plotting this out in jupyter labs you're actually calculating the returns as p0/p1 - 1. Did you mean to do this?
@bryan-9742
@bryan-9742 2 жыл бұрын
I'm now pretty sure you have to re-organze that one snippet in beta loading. I tested it on a couple time series and the returns are being taken backwards. I can send you my .py file if you'd like. You can even verify this by expanding your #calculate returns snippet just below and see that you take the returns (p1-p0/p0 ) but inversely above if that helps. #calculating returns gross = position0*(raw_data[pair1[0]][t+1]/raw_data[pair1[0]][t] - 1) + position1*(raw_data[pair1[1]][t+1]/raw_data[pair1[1]][t] - 1) net = gross - fee*(abs(position0 - old_position0) + abs(position1 - old_position1)) market = raw_data['market'][t+1]/raw_data['market'][t] - 1
@adi29verse
@adi29verse 3 жыл бұрын
Good
Каха и дочка
00:28
К-Media
Рет қаралды 3,3 МЛН
Beat Ronaldo, Win $1,000,000
22:45
MrBeast
Рет қаралды 155 МЛН
Advanced Pairs Trading: Intro to the Copula Approach
38:13
Hudson & Thames
Рет қаралды 15 М.
Must-Watch: Dr. Ernest Chan’s Ultimate Guide to Mean Reversion Trading!
48:44
QuantInsti Quantitative Learning
Рет қаралды 47 М.
"How to build Mean Reversion trading strategies" - Stefan Friedrichowski
1:29:54
Better System Trader
Рет қаралды 26 М.
Introduction to Pairs Trading
47:33
Quantopian
Рет қаралды 74 М.
Trading Psychology | Why Normal Doesn’t Make Money | Part 1
18:39
The Only Unbreakable Law
53:25
Molly Rocket
Рет қаралды 341 М.
Advanced Pairs Trading: Vine Copula Trading Strategy
27:04
Hudson & Thames
Рет қаралды 8 М.
Каха и дочка
00:28
К-Media
Рет қаралды 3,3 МЛН