You saved my time. Was looking for this for my project ! Thank you Matt.
@MattMacarty9 ай бұрын
Glad it helped.
@nj-bz8pv2 жыл бұрын
Thanks man! I’m a long time trader but beginner “quant” and python user. This is very helpful
@MattMacarty2 жыл бұрын
Glad it helped.
@botancitil922 жыл бұрын
Thank you very much for sharing your Python codes.
@MattMacarty2 жыл бұрын
You are welcome. Glad it helped
@Krath19883 жыл бұрын
Outstanding! Thank you for the tutorial, very clean code.
@MattMacarty3 жыл бұрын
Thank you. Glad it helped
@Gabvt13 жыл бұрын
Amazing content !!
@MattMacarty3 жыл бұрын
Thanks. Glad it helped
@mkaberli2 жыл бұрын
Your approach to algorithmic trading is novel. I've never seen an approach like this. I 've become aware of a problem with most indicators used by traders to generate Buy and Sell signals. One such indicator is the RSI. So, what I did was to add a column to your gld dataframe. I then ran a correlation between the gld['ratio] column and the gld['RSI'] column. I got the following correlation: 0.9120, which indicates that the ratio is highly correlated with the RSI. That, my friend, is the problem with most (all?) indicators that are based on price. In short, they all seem to be highly correlated. Using more than one indicator is oversampling, or superfluous. One doesn't really appear to be much better than another as far as I can tell. I'm curious, however, if there are any strategies that work better than others, relatively consistently. I'd also like to know if there are indicators that aren't correlated with price movement. I'm interested in any feedback, but if someone feels the need to attack me, please, keep it to yourself.
@MattMacarty2 жыл бұрын
Haha, yes I am just showing an example of a mean reversion approach using traditional statistics rather than technical indicator; I'm not making any claim that this is a winning system - it's far too simplistic, although at some point in history it may have worked just like that for a while. In general I think if anyone knows what works they aren't going to share it, since these edges tend to get traded away when they are known. This means lots of trial and error. And probably a combination signals. On the other hand highly correlated isn't the same as collinearity. The question might be when the two systems diverge which one does better?
@ahmadz1132 жыл бұрын
It would be great if you make another video about how to look at this strategy from linear regression point of view
@MattMacarty2 жыл бұрын
Ok, let me see what I can do.
@HisyamHilmiOmar-jx7mx7 ай бұрын
Hi, great tutorial! Just one quick question, for the value of the moving average, what does 21 stand for, is it the length of the moving average or the actual value of the moving average? Can you elaborate further on how you derived the value of 21 for the moving average?
@MattMacarty7 ай бұрын
21 is the number of periods in the moving average. This is the number of trading days in a month.
@SEVENCRYPTOCHANNEL3 жыл бұрын
Hallo I have 3 question here 1. Why do we use np.exp at the back? 2. why do we need to shift the position to 1 ahead?
@MattMacarty3 жыл бұрын
Hi. I am calculating an instantaneous rate of return with np.exp. You shift the data to avoid look-ahead bias.
@ahmadz1132 жыл бұрын
@@MattMacarty may you please elaborate more about what do you mean by instantaneous rate of return , why haven't u taken the return as Close (n) -close (n-1)
@muratkonuklar39102 жыл бұрын
Could you please suggest a solution for ( since not working pdr.get_data_yahoo) while I am executing the code for GLD?
@MattMacarty2 жыл бұрын
Can you tell me what the error message you are getting is?
@severinfelber54663 жыл бұрын
Thank you Sir
@MattMacarty3 жыл бұрын
Glad it helped
@twtw7853 жыл бұрын
Can you please show us how to write the for loop to backtest a portfolio stock, for example 10 stocks. I can understand the code for backtesting one instrument, but can't figure how to to write the code for testing 10 stocks in one go. Thanks a lot.
@MattMacarty3 жыл бұрын
Let e see what I can do. There are some pretty good back testing libraries out there.
@twtw7853 жыл бұрын
@@MattMacarty please show us. It's a joy to see you do it. You made it look so interesting and easy for us to understand. You are one of, if not the best Python tutorial guy on KZbin on this type of backtesting Pythob demo.
@ahmadz1132 жыл бұрын
a small correction while u were interpreting the graph : percentile 50% is the median not the mean
@MattMacarty2 жыл бұрын
Thanks.
@eliotharreau76272 жыл бұрын
Thank you very much man for this upload ! It's perfect. Can you make the same video with exit point, neutral point and calculate fees ? Thnx :-)
@MattMacarty2 жыл бұрын
Thanks. I would probably take advantage of one of the backtesting packages out there for some of this. Try bt which is about the easiest to use and has pretty good documentation.
@eliotharreau76272 жыл бұрын
Ok I will try bt, but its not so easy. Thnx
@Frdy123452 жыл бұрын
Superb tutorial, thanks! One question, how can we incorporate the cost of each transaction in the case of the strategy version? Would that mean its final return is likely to be smaller than that of buy and hold? Thanks
@MattMacarty2 жыл бұрын
Thanks. You could incorporate transaction costs by just subtracting the cost at every change in direction. Most transaction costs are pretty small at this pint but they will impact return.
@Frdy123452 жыл бұрын
@@MattMacarty thanks!
@jesslyn50813 жыл бұрын
May I know why you use close price instead of adjusted close price?
@MattMacarty3 жыл бұрын
Adjusted close is there for splits. So use it if the security has split recently. Close and adjusted close eventually converge.
@abdulghani91862 жыл бұрын
Can i use this on cryptocurrency?
@MattMacarty2 жыл бұрын
You should probably test anything you want to try on historical data.
@jaguar33953 жыл бұрын
Hello Matt, I hope you are good some questions: this strategy does not consider commissions right and that's why it outperforms buy and hold? what is the difference between a strategy of moving averages signals and this ratio? and if we wanted to add some commissions how would we do it? Thank you so much!
@MattMacarty3 жыл бұрын
Right, it doesn't consider commissions for either the strategy or the buy and hold. If you want to consider commssion you would probably having a starting capital amount and a commision amount, then you can add a column to your dataframe to track your ending value and compare it to the same for buy and hold.