Algorithmic trading in Python: Cointegration and pair trading

preview_player
Показать описание
How to implement the logic of cointegration and statistical arbitrage in Python? Today we are building from scratch our own trading bot based on cointegration and pair trading, utilising data parsed from Yahoo Finance and Python statistical packages, and looking at how we can simulate a simple real-world pair trading strategy in Python.

Don't forget to subscribe to NEDL and give this video a thumbs up for more videos in Python!

Рекомендации по теме
Комментарии
Автор

Truly the best platform around for distant learning in business, finance, economics and much much more.

Jtking
Автор

Holy shit!! The best channel I have stumbled across for algo trading.:) Cheers!

_stxf
Автор

as mentioned in the prev video, if you subtract the returns each day, you ASSUME that the notional size is the SAME. So each day you need to compensate for the notional changes on both stocks and put them identical (or nearly identical if you use a minimum threshold). Thank you for your amazing work!

riccardoronco
Автор

Wow i am so glad i found your channel. You have really good content and finally a serious algorithm trader

paulmuller
Автор

Much love from London bro you are amazing!

andrewtate
Автор

Good afternoon! Your channel gets more interesting with each new video! The topic of Python programming is very relevant and extremely useful in the world of finance. It will be cool if there are more similar videos!)))

deniswolf
Автор

Awesome! You have to demand fee for your perfect job and perfect english for instance in patreon 👍

denisbaranoff
Автор

Wahou, Incredible !
Thank you for sharing so much information !

pasduroc
Автор

Awesome video, very clear and intuitive to understand. looking forward to more python algorithmic tutorials!

prisiv
Автор

Hi @NEDL
Thanks for this very illustrative video and code...
I had a clarification to seek re this line of code, which I was hoping you would help resolve :

gross_return = signal*returns[stock2][t] - signal*returns[stock1][t]

This portfolio return calculation assumes we take equal weight and opposite positions on stock1 and stock2? However the initial stock prices and subsequent positions at the time of the signal may not be the same? Eg the first time signal is non-zero, the prices are respectively 140.22 for stock1 and 66.67 for stock2. Wouldn't the gross_return calculation for the portfolio then have to use a weighted equation, weighed by the positions?

algoudemy
Автор

Great video! Thank you. The variable "a" in minute 13:15 is defined as Average(S2-b*S1). Maybe I am wrong but I think it should be implemented with 2 averages, like: Average(S2)-B*Average(S1).

onda
Автор

8:08 - Why do you use simple returns here and not the log returns? Aren't log returns more appropriate for further compounding?

maciejscibor
Автор

We have the times that we'll enter a trade however when will we close our position?

RCNNNNCR
Автор

i don't get the calculation of the gross_return: "gross_return = signal*returns[stock2][t] - signal*returns[stock1][t] " Why do we subtract the return on stock 1 from the return on stock 2? If we short, this position should (in the best case) also generate a positive return. In addition, I still have the question of whether, if the "signal" does not change, we hold the positions until the signal reverses. Is the gross_return then calculated as the return over the period in which the signal was the same? thanks in advance

ikrusk
Автор

Amazing tutorial!!! Thank you very much!!!

Kelevra
Автор

First of all, thanks for your video. And I have a question, (my English is not very well), we retrieve data from 2019-12-31 to 2021-03-08, and we use this centense - 1, 0)" to calculate the daily return and then append a 0 to the last day. I think we should put the 0 as the return of the first day not the return of last day. I think the first return should be the return of 2020-01-02, because only when market close at 2020-01-02, can't we know the close price that day, and can't we calculate the return that day. So the first return should be the return of 2020-01-02, not the return of 2019-12-31. Since we don't know the close price at 2019-12-30, we should let the return on 2019-12-31 be 0.

yoofoo
Автор

Can you do video about johansen cointegration and VECM model to pair trading? I watched your videos they are great, but now everybody use johansen/VECM or KalmanFilter or ANN (LSTM) with some transformation of data.... Nobody use OLS....

oleksitkachenko
Автор

awesome video! Would have been more cooler if you added kalman filter

jadecapital
Автор

Thank you for posting this and your other detailed videos. Regarding the cointegration test used in this video, would it be more accurate to use 'Adj Close' rather than 'Close' prices? It seems that any dividends and splits not accounted for in 'Close' prices would affect the calculations. In a test run of your code using Adj Close, net returns are cut in half. Maybe Adj Close should be used for the cointegration test but Close should be used for simulated trades returns.

nimbusdodger
Автор

Hello, great video as always.
I have a request for a video of Kalman filter for cointegration in python.

avinashmishra