Hey Algovibes, Once again great work mate, thanks for taking a look at the code - I took on board the feedback you gave me and I'm glad to see some of it made it into this video. I've learned a lot from your channel, keep up the good work bro.
@Algovibes3 жыл бұрын
Hi mate, Thank you very much for your comment and thanks a lot again for your contribution :-) More content is about to come once I find some time.
@xwclsg3 жыл бұрын
Great videos, great comments below the videos, and please keep up the update on your channel.
@Algovibes3 жыл бұрын
Thanks a lot for your comment. It really helps me and I appreciate it :-)
@TheLantani2 жыл бұрын
Amazing video!! Happy new year 2022
@reckziegel3 жыл бұрын
Thank you for your videos, I'm learning a lot!
@Algovibes3 жыл бұрын
Great to hear! Thanks for watching and your feedback. Really appreciate it :-)
@mschuer1003 жыл бұрын
Hi again, just going through your code again for my own education and cleaned it up a little bit. I think you would want the corresponding date to the return and then put that into a dataframe. I did this when replicating this strategy and first created a dictionary of the date and profits lists ==> ex. results = dict(zip(date, profits)) and then df = pd.Dataframe.from_dict(results, orient = 'index') worked perfectly for me. Hope this helps. And please keep the videos coming, they are great
@Algovibes3 жыл бұрын
yeah you can do that as well. I just put that fastly together in the end :-D But as always thanks a lot for your suggestion. Very happy to have you onboard :-)
@mschuer1003 жыл бұрын
@@Algovibes happy to be on board. Your videos are fantastic.
@undermygarage3 жыл бұрын
Hope all is well with you Algovibes. You seem super chill! Greetings from US. Keep up the good work!
@Algovibes3 жыл бұрын
Everything is as good as can be expected under the circumstances. I hope you are well too! Greetings back to US. Awesome to have American people on board :-) Appreciate your kind words!
@mschuer1003 жыл бұрын
Awesome video! Thanks for sharing this. Great follow up to the Dow momentum strategy. Just as an aside, i would include BRK.B and BF.B just to round out your data set. If you are not aware, in Yahoo Finance, those stocks with a period (.) are replaced with a dash (-) so BRK.B becomes BRK-B. Here is how i took care of it :: symbols = [ ] for i in tickers: symbols.append(i.replace('.','-')) Keep the videos coming
@Algovibes3 жыл бұрын
Thank you very much for watching and thanks a lot for your kind words. And a third thank you for your incredible valuable suggestion! Best regards :)
@rraul3 жыл бұрын
Thanks from Brazil. I Will use this for local stocks market
@Algovibes3 жыл бұрын
Thanks for watching my friend and greetings to Brazil 🇧🇷 :-)
@ayonrabbani93573 жыл бұрын
Thank you! My new years plan is to learn and build off your videos! Thanks for the info and inspiration :)
@Algovibes3 жыл бұрын
Thanks a lot for your appreciative comment my friend. Wishing you a lot of success and be kindly invited to let me know if you have progressed :-)
@FtHBarrelroll7 ай бұрын
Danke habibi
@Algovibes7 ай бұрын
Gerne :-) LG
@juuttuub3 жыл бұрын
Superb! It would be nice to see 52 week high momentum strategy that is published by Hwang and George.
@Algovibes3 жыл бұрын
Thanks again :-) I already saw your comment in my notifications but it just didn't go through probably because of the alpha architect link. Nevertheless I checked that and I will see what I can do. Thank you for your contribution!
@batiste1158 Жыл бұрын
Thanks for the video! I just have one question. How would you implement a value weighted portfolio instead of an equal weighted portfolio like you used in the video? Thanks in advance!
@Algovibes Жыл бұрын
Very good question. Either you work with an individual defined weightsarray (I have covered something similar in my Portfolio Theory video - be invited to check them out!) OR you take a factor like the Market cap and weight it by that factor itself.
@rabih79692 жыл бұрын
Hello Algovibes, first of all a big thank you for the video! it is really great and you're really saving lives here ;) a question: i am doing a bivariate portfolio analysis, so i have two variables; Momentum and another variable. after forming the portfolios for each variable, i have to intersect the portfolios for each period from both variables and with that make new portfolios. for example, if i have 3 portfolios for momentum: loser,okay,winner and three portfolios for the other variable: a,b,c then i want to get 9 portfolios: intersect loser-a, intersect loser-b, intersect loser-c, intersect okay-a etc.. could you tell me if you have already made a video about such topic or if you could refer me to a link where i could find such function? i would really appreciate your help! huge thanks!
@Algovibes2 жыл бұрын
First of all thanks a lot but this is nothing I could help you with in the KZbin comment section 😂 But fingers are crossed for your academic project / thesis!
@Nidhiprajapati-h1e6 ай бұрын
hello Algovibes your video is very useful could you please make videos on time series momentum by taking 6 month formation period and 6 month holding period
@Algovibes5 ай бұрын
Thank you mate! Be sure to check out my other videos on Momentum, I did something very similar there.
@richardpitt79003 жыл бұрын
Great job
@Algovibes3 жыл бұрын
Thanks a lot Richard! :-)
@PMHijes3 жыл бұрын
Hi :) thanks a lot for a great video. Regarding the 2 failed downloads, it seems to be a problem with how yfinance deals with the tickers BRK.B and BF.B. It seems like yfinance understands BRK-B and BF-B, hence, you can manually change "." by "-":. Otherwise you get NaN in those two columns. for n,ticker in enumerate(tickers): if ticker == 'BRK.B' or 'BF.B': tickers[n] = ticker.replace(".", "-") Cheers, keep it up!
@Algovibes3 жыл бұрын
Great suggestion, thanks a lot mate! :-)
@nitin-goyal3 жыл бұрын
I have gone through many books, one doubt that i have is, S&P 500 constituents would have changed over time hence updating our stock universe. How can I get that factor in my back test? I think this is a really great factor considering we are choosing from that universe only! Thanks for the detailed video! :)
@Algovibes3 жыл бұрын
Hi man, thanks for your comment :-) You are right, this is the so called survivorship bias. To include that you will need to take a look at the changing constituents. There are some lists available for free, someone commented that below this or the other momentum video as far as I remember.
@chapmansbg3 жыл бұрын
Thanks with the well wishes, likewise I hope you have a great year. 38% over ten years is pretty crap, you would have been better off just holding and not trading. But if you could combine it with a getting out strategy (as you said) you would probably do okay. Have you any ideas about predicting the best time to get out?
@Algovibes3 жыл бұрын
Pretty late but I am satisfied with this year so far :-D Can you elaborate on "predicting the best time to get out" ?
@chapmansbg3 жыл бұрын
@@Algovibes I am referring to the sell price that should come after every buy, or the peak price before a correction. So if you look at today's BTC action (24 Sept 2021) we got to 45.2k before a big dump. That would have been the optimal sell price for someone that bought at 43.7k yesterday.
@jbg_pepe60972 жыл бұрын
Awesome Video! Just one remark. To be scientific correct, you'd have to take into consideration that the constituents of the index changes over time. Otherwise really awesome!
@Algovibes2 жыл бұрын
Thanks a lot mate :-) Yep, but unfortunately there are no good data sources for changing constituents.
@ArchitLal3213 жыл бұрын
Good vid thanks
@Algovibes3 жыл бұрын
Appreciate the feedback. Thank you very much for watching :-)
@mvbezinho3 жыл бұрын
Hello Algovibes! Happy New Year! Do you think it is worth using this strategy by listing the values of the stock betas in the same way used in the momentum strategy? Greetings from Brazil!
@Algovibes3 жыл бұрын
Greetings back to Brazil! Awesome to have you on board. Regarding your question it depends what you want to achieve? Best regards
@mvbezinho3 жыл бұрын
What I mean is to rank the stocks with the best betas (and alphas), according to the CAPM model, medium, over this same period. In this way, it would be possible to write the portfolio maintenance monthly and calculate the efficiency of this strategy according to the same benchmark criteria. I am not able to test this strategy to share my results because I still don't have enough knowledge in Python to write the simultaneous CAPM model for all shares listed on the stock exchange at the same time and store them in a list, or dataframe, for a dynamic analysis of your behavior. All the best for you AlgoVibes! You have earned a frequent subscriber!
@Algovibes3 жыл бұрын
@@mvbezinho Ah I understand. Yeah that would be interesting! Thanks a lot for your kind words my friend! There will be more content both on financial stuff, Data Science and general Python coding but I cannot provide as frequent as I wish to as I am working full time :-(
@ihebbibani71223 жыл бұрын
First of all , Thanks for the video. So the core idea in this video is to buy the winning returns each year on december and short the loosing returns also each year on december with the first eleven month given.This is what we call momentum right ?
@Algovibes3 жыл бұрын
Thank you very much for watching :-) You nearly got it right. We are buying each month (not only December) the winners and shorting the losers. The return period which is telling us whether it is a winner or loser are the last 12 months skipping the most recent month.
@elevateyourselfnow20233 жыл бұрын
Thanks for the tutorial. One thing to consider is that your approach contains survivorship bias, I think you just took a static S&P constituents list, right? Since SP500 index is a momentum index itself, the weak stocks will have dropped out over time and are not contained in your list. I think that Quantopian used to have a good database to account for this but they are not available anymore, maybe worthwile looking for another source....if you heard of any
@Algovibes3 жыл бұрын
Thanks a lot for watching! :-) Your observation is totally right: I am getting a static list as per the date wikipedia was setting up the tickers. Awesome that you mention the resulting survivorship bias! I think that is a very important point for long term backtesting but nevertheless in shorter time horizons I doubt it is making a huge difference (just a claim). But highly probably disappointing I don't have a better data source, but I am always looking for new ones and when I have a better one I will surely share that here. Best regards and thanks again.
@rafaels9233 жыл бұрын
Happy New Year! Wouldn't it be more correct to evaluate by the sum of the returns? For this example, momentum performs 203% and SP 135% -- frame[0].sum() and frame['SP500'].sum()
@Algovibes3 жыл бұрын
Hi Rafael, by subtracting I wanted to compare the monthly returns of the momentum strategy with the monthly returns of the S&P 500. If you want to cumulate those returns you would have to cumulate them the same way I did in the steps before. Best regards :)
@xxruffyxx13183 жыл бұрын
Thanks for this video. Keep the good work up. For my Bachelor thesis i have to compute the Fama French factors (SMB, HML) to make a Regression. Do you have any hints for me how i can do it ? Thanks in advance :)
@xxruffyxx13183 жыл бұрын
My idee was to take data that contains returns ,market cap and Book/maket cap ratio for every stock. From that point on i would make restricitons to get the 6 Portfolios. For Example, Portfolio 1 has the Stocks above 50% Median and with Book/mraket ratio above 0.7 quantile and so on. So i would get 6 Portolios which i can use to compute the SMB and HML factors. You think the way i want to do it is okay, or can you give me an advice to make it in a better way ? Thanks alot
@Algovibes3 жыл бұрын
I think I got you covered :-P Here is my video on implementing a Fama French Regression in Python: kzbin.info/www/bejne/pn3ckqd9grmksLs If you need to calculate the factors for another market as far as I remember someone in the comments asked me how I would do it and I gave a reply and references. You can also check out the video on getting the stock beta, maybe helpful for you as well. Thanks a lot for your kind comment btw :-)
@xxruffyxx13183 жыл бұрын
@@Algovibes thanks for you videos. i managed to calculate the factors. i have one morge question to perform a regression. I calculated SMB and HML and the average return of all stocks. Moreover i have data for the risk free rate. My quesion is how can i perform the regression now ? i for x-variable i use SMB, HML, and the average return of all stocks minus rf. But what should i use as y-variable ? What is the difference between the y-varibale and Rm-rf? I would be really happy if you can help me. Thanks in advance
@Algovibes3 жыл бұрын
@@xxruffyxx1318 Maybe I am getting you wrong but I am doing exactly that in my linked video above. I am explaining the regression and which are the dependent and independent variables. Can you please check it out again? Let me know if you have any more questions!
@Nidhiprajapati-h1e9 ай бұрын
Hello, Algovibes I want to calculate the return for 3-month holding period where do I need to change this formula.
@Algovibes9 ай бұрын
Did it in one of the newer momentum vids as far as I remember
@markk42033 жыл бұрын
I'm not understanding [24], which says past_11 = (mtl_ret + 1).rolling... it makes sense to me that it would be (mtl_ret -1) to go back one month (thereby skipping the most recent) and calculating the cumulative 11-month return until that point. Clearly this isn't necessary, though, because just after this in the video, in [35], you do end_measurement = formation - MonthEnd(1) , which addresses my original point. I guess I'm all confused about what [24] does?
@Algovibes3 жыл бұрын
With end_measurement I am just finding the date for which I need the cumulative return over the last 11 months. To get the cumulative return I am indexing for this date.
@ghaithalmasri30392 жыл бұрын
Hello, Algovibes, is there a way for us to get the code you wrote in this video?
@jmoz3 жыл бұрын
Great vid. Can you please explain the structure of the data frame at the start? I can see it is indexed by date, but also the columns are kind of indexed or grouped with the symbol and value above them? Sorry I don’t know the terminology. Basically I want to replicate this structure on my own data but I don’t know how. Thanks.
@Algovibes3 жыл бұрын
Thanks a lot for watching and your comment. Appreciate it :-) The initial dataframe is a multi index dataframe containing the ticker/stocks as the first index and Open, Low, High, Close, Adj Close and Volume as the second index. So for every stock you are getting a subframe. If you are calling the columns by: df.columns you will see that as well. Does this make sense to you or do you need more clarification? I am happy to help out so just let me know.
@jmoz3 жыл бұрын
@@Algovibes sorry I can’t see how that works. I can see the date is the index. And it looks like a pivot table but grouped. If you can imagine creating a df from csvs so that each row has a date, symbol, o, h, l, c-how would you setup that df so it looks like what you’re working on?
@Algovibes3 жыл бұрын
@@jmoz I don't recommend to structure it my way with your file. But here is the code to do so anyway: df ist your read in csv file. Transform your Date column by: df.Date = pd.to_datetime(df.Date) Then to create a MultiIndex: df.set_index('Date').set_index('Ticker',append=True).unstack() But as said I would rather group the data by Ticker and Date and amend the formulas.
@miahooj71723 жыл бұрын
Hi, loved your video! :D How would you write your code if you had to modify the winner ret for 3 months instead of only 1 month?
@Algovibes3 жыл бұрын
Hello :-) Thanks a lot for your comment. You just need to get the subsequent 3 months by cumulating the returns over those months. Is that helpful or do you need a code? Best regards
@miahooj71723 жыл бұрын
@@Algovibes Hi again, and thanks! :D I have tried including a code that does exactly that! I tried defining a dataframe that takes the accumulated returns for my holding period, and then i use that data frame for the loc-function when determining winner and loserreturn. But I would love to see how you would have done it, as I am not sure if I have missed something. Keep up with the great videos! :D
@Algovibes3 жыл бұрын
Hi again, yes your solution sounds pretty reasonable. I would probably define a function which is providing me the cumulative returns for the desired months (in your case three). That would be my syntax: def threemonths(mtl_ret,formation): returns = [] for i in range(3): returns.append(mtl_ret.loc[formation + MonthEnd(i)] + 1) returns = pd.Series(returns).cumprod() return returns.iloc[-1]
@mrryanwells2 жыл бұрын
any ideas why i would get "No axis named 2010-12-31 00:00:00 for object type DataFrame" after "ret_12 = past_11.loc(end_measurement)" im using visual studio to run a jupyter
@Algovibes2 жыл бұрын
Hey Ryan, this error is independent from the IDE you are using. Are you sure you are indexing correctly? BTW I released a newer video on Momentum, be kindly invited to check that out: kzbin.info/www/bejne/gmPRmYGsfqaseKs
@mrryanwells2 жыл бұрын
@@Algovibes I missed the brackets (not parenthenses) around [end_measurement]!!
@boohoo7083 жыл бұрын
hallo, could you pls tell me, how i have to change line 46, to get only 10 stocks instead of 54…thx for your great work bro…
@Algovibes3 жыл бұрын
Can you please give me the timestamp where I am doing that? I am happy to help you!
@akshitkumar41033 жыл бұрын
Hey brother! Can you suggest the changes in the code if we want to change the holding period from one month to 3 months? I am not able to figure that out on my own.
@Algovibes3 жыл бұрын
Hi mate, thanks for watching and your comment :-) I have covered different holding periods in this one here: kzbin.info/www/bejne/j3rWfIaHnZarprs Anyhow if you are using returns you would need to cumulate them over the holding period.
@akshitkumar41033 жыл бұрын
@@Algovibes Thankyou so much brother. Loving your content!
@srengodbersen14813 жыл бұрын
I was wondering why I cant lookup a holding period of 3 months where you look it up for 1 month? Why does it has to be accumilated returns? :D
@Algovibes3 жыл бұрын
Thanks a lot for your question! You are not the first one to ask this one. Maybe I should have explained it more precisely. We are looking up the monthly return for the asset. If we want to check a holding period more than one month the monthly returns have to be cumulated again to get the return over 3 months. Otherwise if you are just looking up +x you are just getting the return x months later and not the cumulative return until then. Does this make sense to you? Best regards :-)
@RickardVarli3 жыл бұрын
Hey AlgoVIbes. Somehow I fail to download yf.download(tickers,start='2009-12-31',end='2020-12-31'). It just freezes at 9% or something like that. Do you have any tips?
@Algovibes3 жыл бұрын
Thanks for watching :-) Try to download it some time later. Sometimes you are just exceeding the requests. Or restart your kernel. That often solves bugs. Let me know if this solves your problem!
@RickardVarli3 жыл бұрын
@@Algovibes Yes, thanks a lot. How would one program a different holding period like 3 or 6 months instead of 1 month?
@Algovibes3 жыл бұрын
By cumulating the returns in the mtl_ret data frame over the desired holding period from the buying date on. Somewhere in the comments on this or the other momentum video I published a code on how I would do that. Anyhow, I will publish another video on momentum in the upcoming days/weeks where I am probably also going through different holding periods. Best regards
@dimapol88803 жыл бұрын
Hello thx for video! The best way using 3 month period but not 12. And do you know how make backtest from 2008 if list of snp 500 stocks changed every month?
@Algovibes3 жыл бұрын
Hey :) Thanks for sharing your thoughts! Appreciate it. I didn't find a good (free) database for changing constituents yet. I was using the CRSP database while studying which is unfortunately not freely available. When I have solid data I will upload one but didn't invest time into that yet.
@dimapol88803 жыл бұрын
@@Algovibes do you know where I can find good database (paid)?
@Algovibes3 жыл бұрын
@@dimapol8880 Not a paid one but a free one ;-) raw.githubusercontent.com/fja05680/sp500/master/S%26P%20500%20Historical%20Components%20%26%20Changes(04-25-2021).csv Maybe I am doing a video on changing components with this data. Would be interesting for me as well :-P
@caulijutsu15753 жыл бұрын
Algo-god
@Algovibes3 жыл бұрын
:D far far away from that but I appreciate your comment. Thanks a lot for watching.
@srengodbersen14813 жыл бұрын
How could the code be modified to handle several months of holding periods instead of just the one you used? Would that be difficult?
@srengodbersen14813 жыл бұрын
And how would you adjust your code to changes in the different stock apperances on the S&P500 over the years?
@Algovibes3 жыл бұрын
Hi mate, regarding your questions: It's not a big deal to consider several months. Instead of only screening for the actual months one could define the end month and cumulate the monthly returns until that date. As many people have asked about that I will include that in an upcoming momentum video as well. Regarding the second question, can you specify why that should be a problem? I mean if a stock is dropping out you just won't consider it. In relation to the huge number of stocks and the turnover (we are checking for winners and losers every single month) that should be not that relevant. Do you understand my point? In case I got your question wrong please feel free to correct me. Best regards
@srengodbersen14813 жыл бұрын
@@Algovibes Thanks. Regarding the second question. If you consider a smaller index like the top 20 stocks (this is the case in Denmark), then I guess the code should take into consideration that the index changes every year. So instead of backtesting the same 20 stock for the last 20 years, the code should take into account that the top 20 stocks changes as well
@Algovibes3 жыл бұрын
@@srengodbersen1481 Got it. To avoid that just scrape the stock data for every year instead of doing it one time as I am doing that. Would this solve your problem?
@srengodbersen14813 жыл бұрын
@@Algovibes Yeah thanks! I might return to you if I have any python-data-related questions in the future :D
@prajakta15343 жыл бұрын
Hello Algovibes! I am getting KeyError: Timestamp('2010-11-30 00:00:00') on running ret_12=Past_11.loc[end_measurement] Can you please help me with this?
@Algovibes3 жыл бұрын
Hi and thanks for watching :-) Error is just telling you that there is no date 2010-11-30 in the past_11 data frame. Please check your past_11 return frame again and make sure you pulled the right time horizon. In case this didn't solve your issue please explain which timeframe you were trying to pull. I have just coded it again and didn't experience the problem. Hope this is helping you out!
@prajakta15343 жыл бұрын
Thank You! It worked . Learned a lot ...
@sujalshukla2993 жыл бұрын
Bro, can you help me for creating a program for intraday trading live chart plz bro
@Algovibes3 жыл бұрын
Hi :) Thank you very much for watching. How exactly can I help you? Best regards
@akshitkumar41033 жыл бұрын
Hello Alogvibes! After executing - ret_12 = past_11.loc(end_measurement) I get an error: ValueError: No axis named 2012-05-31 00:00:00 for object type Any help on this would be appreciated!
@Algovibes3 жыл бұрын
Hey mate :-) Please check again if you used squared brackets, so: past_11.loc[end_measurement] Let me know if this solved your problem.
@akshitkumar41033 жыл бұрын
@@Algovibes Thanks a lot mate! The issue was solved. Great work!
@monh9643 жыл бұрын
does this strategy work for short time frames ?
@Algovibes3 жыл бұрын
Good question. My guess is rather: No. But I haven't tested that yet.
@sujalshukla2993 жыл бұрын
Bro can u make a video on autorelod program
@Algovibes3 жыл бұрын
Hi mate, may you specify? Never heard of. Best regards
@sujalshukla2993 жыл бұрын
@@Algovibes bro, I want you to make a program for live chart for stock without api key
@sujalshukla2993 жыл бұрын
Thank for support
@Algovibes3 жыл бұрын
@@sujalshukla299 sure mate! Cool idea :) Noted that on my list for future videos.
@abhinav27459 ай бұрын
Can I get the source code?
@Algovibes9 ай бұрын
Hi mate, sure. Just check out the membership options on my channel. Looking forward to welcome you there!
@DarrylHebbes3 жыл бұрын
more strategien please
@Algovibes3 жыл бұрын
will come :-)
@boohoo7083 жыл бұрын
what nobody need, are numbers with 17 digits after the point
@Algovibes3 жыл бұрын
Can you explain?
@betoperalta7012 жыл бұрын
Tip: stop swallowing so Hard so closed to the mic. It is disturbing
@Algovibes2 жыл бұрын
Thx for the feedback. Can you check the newer vids? I think I got it under control 😛