I am not a programmer by any means. I have no idea why I watch these videos but they are so insightful on strategies to solve problems. It's like coding is a series of thousands of small problems that you need to solve to achieve your designed outcome. Fascinating.
this is exactly what it is. The main ideia with solving complex problems (in programming context, because that's what I know) is divide and conquer. It's literally everywhere.
First of all thanks a lot for watching my videos :-) Appreciate it. If you need any help finding something helping you get a better understanding just let me know!
Love your channel, well done on finding the historical index members without paying. A little secret, whilst momentum can be a great strategy, generally tracking error is higher due to momentum crashes during regime change in the markets. Keep up the great work.
This saves me so much time. I was literally creating another boolean matrix from the last videos tickers and making a 1, (in index) 0(not in index) Matrix and mapping the timeseries as the index and then merging with the price series into one big df. From their I was gonna melt, pivot, and groupby but this is much more efficient.
Happy New Year man! I am following you since a long time and I want to tell you that your videos have inspired me to start something like this of my own. Of course it will take time but thank you for posting such insightful videos from time to time.
Hey!!! Thats a wonderful addon to the previous cascade momentum video. many queries are solved by this video pertaining to the previous one. Thanks again for your time and effort. Also, I would also request you to please do add one more tutorial video to it where in you can share further addon like CAPM, Ann returns, CAGR, Sharpe, Sortino, alpha, Beta, and certain functions which can show portfolio elements on that specific date with prices of stocks selected on creation day and exit day. what i mean to say that once the portfolio is created and on the day of rebalancing it must be able to clearly show the symbol, new entry, exit and final portfolio. Regards Narender
Hi, just want to start by saying, great video - these videos are a great tool for learning. I too did the same strat with the SP500 and i don't understand fully how survivorship bias affects the case - as we are dropping all the columns with any NaNs when you did the first part of the video. So any current day performers, if we use a date to pull the tickers using yf where they were not present in the sp500, they will have NaNs present in their column. As we drop these columns, the list of stocks decreases slightly. But how does it affect the strategy and backtesting then?
Excellent work Algovibes, keep it up! Can you please make a video on how to take this strategy, and short the nsmallest performing tickers, instead of longing the nlargest in the 3 time frames? I have tried this myself, but everything I do, I end up with a 3.5x (with 1% slippage) if I would LONG the nsmallest performing tickers! This leads me to believe my code is not correct, but I have reviewed many times. Please take a look at this scenario, because ideally we can combine longing in a bull market, and shorting in a bear market to maximize profit. Thank you!
I believe that the initial work by Jegadeesh + Titman follows your proposal: buy the winners and short the losers. That makes the strategy self-funding, which is great. Careful with your portfolio sizing though, as you may lose your margin in case of sudden reversals. It would be very interesting to see if such reversals actually occur in a backtest.
That's a wrong statement. E.g. there is also negative Momentum (stocks falling tend to fall further). In the video is shown how you diminish the survivorship bias.
@@Algovibes If a position is taken in a negative momentum stock and it get removed, then the strategy return is under estimated. When backtesting it's not such a drawback as in live environment the performance will be better than backtest. But in case of mean reversion a long position is taken when price is in downtrend. If the stock gets removed the backtest will overstate the performance than when it is implemented. A situation which is clearly avoidable. Anyway I loved your programming of the strategy.
Great video,I m new to your channel,May I know if any video talking about naming variable? Sometimes I confused myself for the variable that I created by myself 😅
@@Algovibes I mean how to name a variable in coding. For example, I need to create an integer variable to count how many stocks fulfil my self defined screening criteria,should I name the variable like intFulfilCriteriaA/FulfilCriteriaA/fulfill_criteria_a/int_CriteriaA etc…naming a variable and function and object during coding sometimes might be a difficult task for me🥲hope it is clear😃
It would be awsome to get it done on the SP500, where there are different sectors and it may get a 2022 positive year, for example, investing in energy or war related stocks.
thanks for these videos ... I am learning a lot and testing the strategy for S&P. I don't understand why the survival-free bias is getting a worse result than the regular momentum strategy. my logic says that if we have more stocks to choose from and the strategy picks the best-performing stocks across 12m->6m->3m then the performance should be better and that is not the case can you explain ... even in intuition wise why?
Welcome man! Intuition wise: Imagine you are considering a strategy which is including Tesla, a stock with a 10 year performance of about 10,000%. Now a survivorship bias free dataset only considers Tesla from a certain day on when it was actually in the Nasdaq. If it would include it from the beginning on, it would drive the portfolio performance by a significant amount. That would be the case if it wasn't survivorship bias free.
@@Algovibes hi, this is precisely my point. In the first momentum strategy, you removed TSLA stock cause it had some NA values so you couldn't use it and gain its performance. In this strategy, you gained its performance so intuition wise the current strategy that includes stocks like TSLA should achieve higher performance. but this is not the case
I wish I had your programming skills as I have great knowledge regarding MOMENTUM in financial markets. Back in time I was managing a fund based on this factor but I realized that to overcome some backdrops you need better filters that essentially allows you to distinguish between Alpha and Beta. May be you know ways to get the programming done.
That's awesome! Appreciate your comment. Yes, that's very interesting as well, agreed. Be invited to check out my other stuff then, should be interesting for you :-)
@@endeavorsu7174 I had to pay for it , subscribed for a month then cancel, it is worth it to examine results across different market regimes, and for other algos.
Loving all your content thanks for sharing your knowledge (I leave my question here because it is your most recent video but I am watching everything from the beginning). I am a software engineer and at the moment I only work with JavaScript, typescript, dart, css, html and sql making applications for a fintech, however all this subject of algorithmic trading seems fascinating to me. Do you know of any material such as a digital book that you can share or mention that is dedicated to explaining the mathematics behind the indicators?
thanks my mate. Talked about this here: ruclips.net/video/Wem7PIhT95U/видео.html and I think I made some book recommendations in my live stream as far as I rememember: ruclips.net/video/TJK-Ct9WnCw/видео.html
@@Algovibes in ruclips.net/video/OHYExP6RVFU/видео.html, we are already missing some stocks without investigations. it happens to me on other markets that date, ticker_name, delisted stocks creates survivorship bias anyhow unfortunately
Very nice video! Learned a lot, but the title is still missleading. The Nasdaq Index is rebalanced on a quarterly basis in March, June, September and December meaning that tickers that appear to be in the index in your historical component data only made it into the index (probably in september or June), because of their strong performance. By omitting this fact you include a look ahead bias and your backtest is not survivorship bias free.
First of all thanks a lot Johannes. Happy that you learned something. Secondly the title is perfectly fine. The wrong thing is your understanding of rebalancing - happy to explain: Rebalancing an index means that you are adjusting the weights of the constituent securities. That is actually happening quarterly for the Nasdaq and has no impact on the constituents. Reconstitution means that you are changing the constituent securities in an index. That is happening end of December each year for the Nasdaq. Further reading: analystprep.com/cfa-level-1-exam/equity/rebalancing-reconstitution-index/ www.globenewswire.com/news-release/2022/12/10/2571355/0/en/Annual-Changes-to-the-Nasdaq-100-Index.html
@@Algovibes cfa level 1 prep that was embarrasing :D thanks again for educating me. But starting in the beginning of the year makes no sense for me if reconstitution happens end of year.
@@LowQuant That is not the case (actually explained that in the video) I am only going back until the beginning for the data pull to have the lookback covered for 2016. If you build a portfolio at beginning of 2017 (which is the first formation date), you need the prices going back until beginning of 2016 to evaluate the performance of these stocks (max lookback is 12m).
Hi. I have problem with the line of code that resample the date in month. I get this error: TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'
@@Algovibes Ich studiere Quantitativ Finanz. Leider habe ich keine Vorgrunde von Programierung. Ihre Videos haben mir dabei viel gehölfen. Vielen Dank!
Please do you have any contact so i contact you to code my strategy for me...?i really dont know anything about coding and been looking for someone to code for me....
@@Algovibes how can i get you email to send you the strategy...had wanted to learn the code but i got to know that i cant be jack of all trades thats why i want you to help me code it...will be happy to send you screenshots if you dont mind
I am not a programmer by any means. I have no idea why I watch these videos but they are so insightful on strategies to solve problems. It's like coding is a series of thousands of small problems that you need to solve to achieve your designed outcome. Fascinating.
I am a programmer. Python is easy enough to learn, do it and you'll enjoy these videos even more
this is exactly what it is.
The main ideia with solving complex problems (in programming context, because that's what I know) is divide and conquer. It's literally everywhere.
First of all thanks a lot for watching my videos :-) Appreciate it. If you need any help finding something helping you get a better understanding just let me know!
@@Algovibes got inspired so i signed up dataquest on their data scientist path. Clocked in 6 hours today and loving it
@@yellowboat8773 like a BOSS 👨🏽💼
I love your vids mate. Explanation, introduction, coding, result of the algo - great stuff really.
Thanks a lot. Appreciate your comment!
Excellent stuff. Loving the vectorised approach. Thank you for sharing!
Thanks a lot for watching my man
Love your channel, well done on finding the historical index members without paying. A little secret, whilst momentum can be a great strategy, generally tracking error is higher due to momentum crashes during regime change in the markets. Keep up the great work.
Thank you very much for your kind words my mate
The strategies are getting more advanced in the new year. Thanks again for sharing.
Welcome mate! Trying my best to keep a balance between more beginner friendly content but also some advanced topics. Thanks for your feedback.
These videos are the best on youtube, no doubt.
Thanks a lot my mate
This saves me so much time. I was literally creating another boolean matrix from the last videos tickers and making a 1, (in index) 0(not in index) Matrix and mapping the timeseries as the index and then merging with the price series into one big df. From their I was gonna melt, pivot, and groupby but this is much more efficient.
Also a good way to solve that!
Happy New Year man! I am following you since a long time and I want to tell you that your videos have inspired me to start something like this of my own. Of course it will take time but thank you for posting such insightful videos from time to time.
That's awesome to read. Thanks a lot my friend!
I echo Atul’s sentiment. In the same position. Thankyou AlgoVibes
Hey!!! Thats a wonderful addon to the previous cascade momentum video. many queries are solved by this video pertaining to the previous one. Thanks again for your time and effort. Also, I would also request you to please do add one more tutorial video to it where in you can share further addon like CAPM, Ann returns, CAGR, Sharpe, Sortino, alpha, Beta, and certain functions which can show portfolio elements on that specific date with prices of stocks selected on creation day and exit day. what i mean to say that once the portfolio is created and on the day of rebalancing it must be able to clearly show the symbol, new entry, exit and final portfolio. Regards Narender
Thanks a lot Narender. Appreciate your comment!
Thank you Bro, have a great and healthy new year!
Thank you so much , same for you!
Great video as always!
Thanks buddy, appreciate your comment
Happy new year boss
Happy new year my mate!
Hi, just want to start by saying, great video - these videos are a great tool for learning. I too did the same strat with the SP500 and i don't understand fully how survivorship bias affects the case - as we are dropping all the columns with any NaNs when you did the first part of the video.
So any current day performers, if we use a date to pull the tickers using yf where they were not present in the sp500, they will have NaNs present in their column. As we drop these columns, the list of stocks decreases slightly. But how does it affect the strategy and backtesting then?
Excellent work Algovibes, keep it up! Can you please make a video on how to take this strategy, and short the nsmallest performing tickers, instead of longing the nlargest in the 3 time frames? I have tried this myself, but everything I do, I end up with a 3.5x (with 1% slippage) if I would LONG the nsmallest performing tickers! This leads me to believe my code is not correct, but I have reviewed many times. Please take a look at this scenario, because ideally we can combine longing in a bull market, and shorting in a bear market to maximize profit. Thank you!
Thanks buddy! Very cool idea. I have noted that. Thanks a lot for the suggestion.
I believe that the initial work by Jegadeesh + Titman follows your proposal: buy the winners and short the losers. That makes the strategy self-funding, which is great. Careful with your portfolio sizing though, as you may lose your margin in case of sudden reversals. It would be very interesting to see if such reversals actually occur in a backtest.
Happy new year!!
Happy New Year buddy
What I would love to know now: what is the outcome of this strategy in the S&P500?
Yes, and beaides that, if there is no positive momentum on the 3 periods of analysis, we stay in chash.
Awesome idea. Thanks a lot for the suggestion!
By design momentum or market cap strategies include only survivors. The survivorship bias is avoidable for mean reversion strategies
That's a wrong statement. E.g. there is also negative Momentum (stocks falling tend to fall further). In the video is shown how you diminish the survivorship bias.
@@Algovibes If a position is taken in a negative momentum stock and it get removed, then the strategy return is under estimated. When backtesting it's not such a drawback as in live environment the performance will be better than backtest.
But in case of mean reversion a long position is taken when price is in downtrend. If the stock gets removed the backtest will overstate the performance than when it is implemented. A situation which is clearly avoidable.
Anyway I loved your programming of the strategy.
Like before watching!
Man of honor 🏅
Great video,I m new to your channel,May I know if any video talking about naming variable? Sometimes I confused myself for the variable that I created by myself 😅
Sorry, can you elaborate on that? Didn't quite get the question. Thanks!
@@Algovibes I mean how to name a variable in coding. For example, I need to create an integer variable to count how many stocks fulfil my self defined screening criteria,should I name the variable like intFulfilCriteriaA/FulfilCriteriaA/fulfill_criteria_a/int_CriteriaA etc…naming a variable and function and object during coding sometimes might be a difficult task for me🥲hope it is clear😃
So far what has been your favorite strategy or the one you currently use?
It would be awsome to get it done on the SP500, where there are different sectors and it may get a 2022 positive year, for example, investing in energy or war related stocks.
Very cool idea. Noted that! Thanks a lot for the suggestion.
@@Algovibes I did it (version with survivor bias) and results were great.
thanks for these videos ... I am learning a lot and testing the strategy for S&P.
I don't understand why the survival-free bias is getting a worse result than the regular momentum strategy.
my logic says that if we have more stocks to choose from and the strategy picks the best-performing stocks across 12m->6m->3m then the performance should be better and that is not the case
can you explain ... even in intuition wise why?
Welcome man!
Intuition wise: Imagine you are considering a strategy which is including Tesla, a stock with a 10 year performance of about 10,000%. Now a survivorship bias free dataset only considers Tesla from a certain day on when it was actually in the Nasdaq. If it would include it from the beginning on, it would drive the portfolio performance by a significant amount. That would be the case if it wasn't survivorship bias free.
@@Algovibes hi, this is precisely my point.
In the first momentum strategy, you removed TSLA stock cause it had some NA values so you couldn't use it and gain its performance. In this strategy, you gained its performance so intuition wise the current strategy that includes stocks like TSLA should achieve higher performance. but this is not the case
I wish I had your programming skills as I have great knowledge regarding MOMENTUM in financial markets. Back in time I was managing a fund based on this factor but I realized that to overcome some backdrops you need better filters that essentially allows you to distinguish between Alpha and Beta. May be you know ways to get the programming done.
That's awesome! Appreciate your comment.
Yes, that's very interesting as well, agreed.
Be invited to check out my other stuff then, should be interesting for you :-)
For those that try the code, the link shared for the Nasdaq 100 historical data no longer works, appears the company made it private.
Good to know!
@@Algovibes Hi, is there any other way to get the same data? Otherwise it's difficult to follow this brilliant video.
Hi, is there any other way to get the same data? Otherwise it's difficult to follow this brilliant video.
@@endeavorsu7174 I had to pay for it , subscribed for a month then cancel, it is worth it to examine results across different market regimes, and for other algos.
Loving all your content thanks for sharing your knowledge (I leave my question here because it is your most recent video but I am watching everything from the beginning). I am a software engineer and at the moment I only work with JavaScript, typescript, dart, css, html and sql making applications for a fintech, however all this subject of algorithmic trading seems fascinating to me. Do you know of any material such as a digital book that you can share or mention that is dedicated to explaining the mathematics behind the indicators?
thanks my mate. Talked about this here:
ruclips.net/video/Wem7PIhT95U/видео.html
and I think I made some book recommendations in my live stream as far as I rememember:
ruclips.net/video/TJK-Ct9WnCw/видео.html
@@Algovibes checking out both vids right now. Thanks!
Do you have any other source for this nasdaq historical component data? The link isn't working.
interesting. thank you for showing us!
but with this approach there is still survivorship bias on delisted stocks?
Welcome mate! No, why do you think so?
@@Algovibes in ruclips.net/video/OHYExP6RVFU/видео.html, we are already missing some stocks without investigations.
it happens to me on other markets that date, ticker_name, delisted stocks creates survivorship bias anyhow unfortunately
hi bru why not same my getting with pandas on tradingview values? Example IM gettinr rsi value 50 on pandas, but tradingview showing rsi 51.10
I am getting the error "AttributeError: 'str' object has no attribute 'top_30'"
Just stick to the code in the video and you won't have that problem.
Very nice video! Learned a lot, but the title is still missleading.
The Nasdaq Index is rebalanced on a quarterly basis in March, June, September and December meaning that tickers that appear to be in the index in your historical component data only made it into the index (probably in september or June), because of their strong performance. By omitting this fact you include a look ahead bias and your backtest is not survivorship bias free.
it's therefore equally wrong to assume stocks were in the index at the beginning of 2016 if the tickers are in the comp of 12-31-2016
First of all thanks a lot Johannes. Happy that you learned something.
Secondly the title is perfectly fine. The wrong thing is your understanding of rebalancing - happy to explain:
Rebalancing an index means that you are adjusting the weights of the constituent securities.
That is actually happening quarterly for the Nasdaq and has no impact on the constituents.
Reconstitution means that you are changing the constituent securities in an index.
That is happening end of December each year for the Nasdaq.
Further reading:
analystprep.com/cfa-level-1-exam/equity/rebalancing-reconstitution-index/
www.globenewswire.com/news-release/2022/12/10/2571355/0/en/Annual-Changes-to-the-Nasdaq-100-Index.html
@@Algovibes cfa level 1 prep that was embarrasing :D thanks again for educating me. But starting in the beginning of the year makes no sense for me if reconstitution happens end of year.
@@LowQuant
That is not the case (actually explained that in the video)
I am only going back until the beginning for the data pull to have the lookback covered for 2016. If you build a portfolio at beginning of 2017 (which is the first formation date), you need the prices going back until beginning of 2016 to evaluate the performance of these stocks (max lookback is 12m).
Hi. I have problem with the line of code that resample the date in month. I get this error:
TypeError: Only valid with DatetimeIndex, TimedeltaIndex or PeriodIndex, but got an instance of 'Index'
Hi :-) Did you transform the index as I did in the video?
@@Algovibes thanks, i solve the problem
Welchen IDE benutzen Sie?
Jupyter Notebook ☺️
@@Algovibes danke!
@@Algovibes Ich studiere Quantitativ Finanz. Leider habe ich keine Vorgrunde von Programierung. Ihre Videos haben mir dabei viel gehölfen. Vielen Dank!
Bro, I hope you got my mail. Looking forward for your insights.
Got it, thanks a lot! Will actually be covered in one of my future videos.
Please do you have any contact so i contact you to code my strategy for me...?i really dont know anything about coding and been looking for someone to code for me....
Sure, you can drop me a mail and if the strategy is interesting enough I will make a video on it! :-)
@@Algovibes how can i get you email to send you the strategy...had wanted to learn the code but i got to know that i cant be jack of all trades thats why i want you to help me code it...will be happy to send you screenshots if you dont mind