Introduction to Algorithmic Trading with Python: Create a Mean Reverting Trading Algorithm

  Рет қаралды 19,494

Matt Macarty

Matt Macarty

Күн бұрын

Пікірлер: 42
@mrityunjaypathak8792
@mrityunjaypathak8792 9 ай бұрын
You saved my time. Was looking for this for my project ! Thank you Matt.
@MattMacarty
@MattMacarty 9 ай бұрын
Glad it helped.
@nj-bz8pv
@nj-bz8pv 2 жыл бұрын
Thanks man! I’m a long time trader but beginner “quant” and python user. This is very helpful
@MattMacarty
@MattMacarty 2 жыл бұрын
Glad it helped.
@botancitil92
@botancitil92 2 жыл бұрын
Thank you very much for sharing your Python codes.
@MattMacarty
@MattMacarty 2 жыл бұрын
You are welcome. Glad it helped
@Krath1988
@Krath1988 3 жыл бұрын
Outstanding! Thank you for the tutorial, very clean code.
@MattMacarty
@MattMacarty 3 жыл бұрын
Thank you. Glad it helped
@Gabvt1
@Gabvt1 3 жыл бұрын
Amazing content !!
@MattMacarty
@MattMacarty 3 жыл бұрын
Thanks. Glad it helped
@mkaberli
@mkaberli 2 жыл бұрын
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.
@MattMacarty
@MattMacarty 2 жыл бұрын
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?
@ahmadz113
@ahmadz113 2 жыл бұрын
It would be great if you make another video about how to look at this strategy from linear regression point of view
@MattMacarty
@MattMacarty 2 жыл бұрын
Ok, let me see what I can do.
@HisyamHilmiOmar-jx7mx
@HisyamHilmiOmar-jx7mx 7 ай бұрын
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?
@MattMacarty
@MattMacarty 7 ай бұрын
21 is the number of periods in the moving average. This is the number of trading days in a month.
@SEVENCRYPTOCHANNEL
@SEVENCRYPTOCHANNEL 3 жыл бұрын
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?
@MattMacarty
@MattMacarty 3 жыл бұрын
Hi. I am calculating an instantaneous rate of return with np.exp. You shift the data to avoid look-ahead bias.
@ahmadz113
@ahmadz113 2 жыл бұрын
@@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)
@muratkonuklar3910
@muratkonuklar3910 2 жыл бұрын
Could you please suggest a solution for ( since not working pdr.get_data_yahoo) while I am executing the code for GLD?
@MattMacarty
@MattMacarty 2 жыл бұрын
Can you tell me what the error message you are getting is?
@severinfelber5466
@severinfelber5466 3 жыл бұрын
Thank you Sir
@MattMacarty
@MattMacarty 3 жыл бұрын
Glad it helped
@twtw785
@twtw785 3 жыл бұрын
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.
@MattMacarty
@MattMacarty 3 жыл бұрын
Let e see what I can do. There are some pretty good back testing libraries out there.
@twtw785
@twtw785 3 жыл бұрын
@@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.
@ahmadz113
@ahmadz113 2 жыл бұрын
a small correction while u were interpreting the graph : percentile 50% is the median not the mean
@MattMacarty
@MattMacarty 2 жыл бұрын
Thanks.
@eliotharreau7627
@eliotharreau7627 2 жыл бұрын
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 :-)
@MattMacarty
@MattMacarty 2 жыл бұрын
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.
@eliotharreau7627
@eliotharreau7627 2 жыл бұрын
Ok I will try bt, but its not so easy. Thnx
@Frdy12345
@Frdy12345 2 жыл бұрын
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
@MattMacarty
@MattMacarty 2 жыл бұрын
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.
@Frdy12345
@Frdy12345 2 жыл бұрын
@@MattMacarty thanks!
@jesslyn5081
@jesslyn5081 3 жыл бұрын
May I know why you use close price instead of adjusted close price?
@MattMacarty
@MattMacarty 3 жыл бұрын
Adjusted close is there for splits. So use it if the security has split recently. Close and adjusted close eventually converge.
@abdulghani9186
@abdulghani9186 2 жыл бұрын
Can i use this on cryptocurrency?
@MattMacarty
@MattMacarty 2 жыл бұрын
You should probably test anything you want to try on historical data.
@jaguar3395
@jaguar3395 3 жыл бұрын
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!
@MattMacarty
@MattMacarty 3 жыл бұрын
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.
@beqodia
@beqodia 2 жыл бұрын
Thank you Sir
@MattMacarty
@MattMacarty 2 жыл бұрын
Glad it helped
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
Auto-detect Support and Resistance in Python
17:06
Chad Thackray
Рет қаралды 24 М.
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Rob Mulla
Рет қаралды 279 М.
Mean Reversion Trading Strategy Clearly Explained!
8:14
NetPicks Smart Trading Made Simple
Рет қаралды 44 М.
Quant Strategy: Pairs Trading Algorithm (Mean Reversion)
15:00
Spencer Pao
Рет қаралды 68 М.
Algorithmic trading in Python: Support and resistance
17:07
Polynomial Regression in Python
20:18
NeuralNine
Рет қаралды 49 М.
Monte Carlo Simulation of a Stock Portfolio with Python
18:23
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН