Predicting Stock/Crypto Returns with Python using Machine Learning - Logistic Regression
HTML-код
- Опубликовано: 8 июн 2024
- In this video we are covering a Logistic Regression to predict stock prices (or rather returns) in Python. We are also taking a look at cryptos (Bitcoin) at the end.
Get the Notebook/Source code by becoming a Tier-2 Channel member:
/ algovibes
Previous vid on Linear Regression:
• Predicting Stock Price...
As said in the video you should not take this as a valid trading strategy. It is just an idea how a Logistic Regression could be used and how overfitting can be avoided or at least diminished using a train test split.
I am purposely NOT showing a time horizon where this is working or looking nicely to make you aware of that.
I am planning on covering other algorithms and extending the strategy. If you find that interesting please leave the video a like and subscribe :-)
The video series is inspired by the Hands-On Algorithmic Trading with Python course by Deepak Kanungo. Anyhow, the code and some approaches strongly deviate from his.
#Python #MachineLearning #Classification
Disclaimer: This video is not an investment advice and is for informational and educational purposes only.
0:00 - 0:52 Introduction
0:52 - 01:48 Quick recap
01:48 - 05:08 Data prep / Amendments to get lagged directions
04:46 - 07:17 Model building, fitting & prediction
07:17 - 09:25 Strategy, Performance and Visualization
09:25 - 13:25 Train test split
13:25 - 15:53 Confusion Matrix and Classification Report
15:53 - 16:38 Considering different amount of lags
16:38 - 18:08 Considering Bitcoin
Thank you very much !! I like the way you explain ;)
Thank you :-)
great series just watched your video from 16th of may it seems like you have stepped up your bot. thanks for sharing
Thanks for your feedback! Well no it actually is just a playing around with a logit regression. I wouldn't use it on a bot.
You share some awesome info. Thanks
Thank you mate
Love the content!
Thanks a lot man!
Conclusion, you randomly picked between - 1 and 1. Good job.
nope, wrong! Do the test: Just backtest a trading strat where you randomly pick to buy and sell - will perform way worse.
Dear AlgoVibes when can we expect a video on BackTrader ? I know I have been asking for a while now but its because its really important. If you do decide to do a strategy on it please include machine learning , stop loss and take profit and multi timeframe analysis in the strategy !
Thank you and thanks for another great video here !
Hi buddy, first of all thanks for your comment!
Unfortunately I can't give you a time when I am doing it.
I played around with Backtrader and tested some strategies with it but I didn't dig deep enough yet.
Video will come, but it is not on my top priorities.
Anyhow don't get me wrong: I am always happy for suggestions! I just cannot cover everything and I am focussing on things I find interesting and I enjoy coding. Figuring out a library is basically reading, reading and again reading docs which is let's say necessary but not my favorite time investment.
@@Algovibes thanks for the reply appreciate it and yes I understand and agree with you
Can you make clear that this strategy is good for bitcoin or any other strategy in machine learning which will be good go for bitcoin. Please help it just for my project
Great contento! Why are you converting to np.log?
Just to make the returns additive.
I explained it here:
ruclips.net/video/fWHQwqT3lNY/видео.html
Is there any reason to adjust the model by introducing the RSI to adjust for overbought and oversold markets?
Could you elaborate the coherence of that with the content of this video.?Maybe I am just getting it, sorry :D
do you think different machine learning algos might fit different assets better in terms of predicting its price? For example log regression for BTC and machine learning 2 for S&P?
Hi Zenn,
Hard to say without doing the necessary researches/Backtest but it is highly probable that certain models fit certain asset classes better than others.
@@Algovibes Cool, I might try it out myself someday haha! Have you done a video where you integrate ML with a trading bot before? If you did, could you drop me a link to it since I might have missed it?
What is the trading rule after you get the direction of the instrument movement? Why are you multiplying the direction with the returns?
I have explained why I am doing that in detail here:
ruclips.net/video/vWVZxiaaTCs/видео.html
But in a nutshell: I am going Long the asset if I get a predicted 1, so if I am buying/holding the asset I am just getting the return and I am going short on the asset if I get a predicted -1, so I am getting the negative return for that day.
@@Algovibes Thanks for the reply! Yet it seems to me that there will be only entry but with no exit. Please correct me if I was wrong.
@@yangwang9688 You are in some sense right as we don't really exit here but we are consistently considering to buy or sell the asset dependent on the prediction. We are just "backtesting" the strategy how it would perform if we are doing that.
Hi sir
I am getting runtime error : coroutine was never awaited
When api live streaming data in jupyter notebook while it working fine in vscode environment
Can you suggest something ?
Sure. When working with Jupyter don't use async functions. When working with an IDE or raw python use async functions. I have shown both ways in this video here:
ruclips.net/video/nQkaJ207xYI/видео.html
Thanks sir, really helpful
Random Forrest with a set of technical indicators to predict next day.
s/o from South Africa
Nice suggestion! Thanks and greetings to 🇿🇦
Спасибо!
Thanks a lot for using the Super Thank feature. Appreciate it and happy to have some Rubel in stock :D Спасибо! :-)
How do you explain that an AI algorithm could not do better than a passive strategy ?
Besides I would be cautious calling that an AI algorithm this I a good question but hard to answer.
Some possible answers to give you an idea:
1.Stock prices follow a random walk -> Unpredictable
2. We didn't pick the right features
3. There are way more features
@@Algovibes it's a machine learning algorithm. Machine Learning is a subset of AI . So why not calling this an AI algorithm ?
It's an AI algorithm without following the best rules to get a performant AI ...
This is what I think...
@@ihebbibani7122 definitely a fair point!
compartir el código
Yessir!
Be invited to join here:
ruclips.net/channel/UC87aeHqMrlR6ED0w2SVi5nwjoin
Bro could you please open a telegram group? I would love to talk about this stuff :D
Außerdem, du sprichst deutsch, nh?
Telegram nutze ich leider nicht. Sorry!
@@Algovibes discord?
@@LoYaL_RR Leider nicht :(
@@Algovibes möchtest du vielleicht ein discord server aufmachen oder sowas? Ich denke das würde vielen hier gefallen und würde dich auch mit deinem Kanal weiterbringen :)
@@Algovibes und gute Videos 🙏🏼
Hey love your work, very interesting !!
Could you please help me on this :)
Many thanks in advance !!
Here is the code and the error message.
This is how I defined direction, I do not understand why it does not take this variable into account.
df['direction'] = [1 if i>0 else -1 for i in df.returns]
model.fit(train[dirnames], train['direction'])
TypeError Traceback (most recent call last) in ----> 1 model**.fit(train[dirnames],** train**['direction'])** TypeError: fit() missing 1 required positional argument: 'y'
Thanks mate. It's probably just a small thing. How exactly did you define the model variable? Pretty sure there is the issue.
@@Algovibes fixed the problem many thanks for your answer much appreciate it !!
Hello pls read my message on your other video it's a great strategy
Hey buddy, thanks a lot for your follow up. I don't receive notifications for comments on comments but I found your comment. Will take a look :-)
KeyError: 'Lag_1'
Can you elaborate?
@@Algovibes Just from running the code until the point where we want to plot the df to show the Lags, it shows that error. I tried other instruments too. Will check again with the market open to see.
Im sorry but logistic regression is not a classification algorithm. This is a common mistake in the new wave of data scientist who did not study statistics. Sorry for being too harsh but it pisses me off that this maching learning, deep learning... era is just a fancier way of calling statistical techniques that already exist for decades.
No worries - I am used to that. I agree with you even though Logistic Regression can be used to solve classification problems.
Anyhow I amended a part in the video description where I am calling it a classification algorithm. Regarding the "new wave"... I don't really see the point where that is a problem. 'Data Science' is a multi-facetted field which combines a lot of disciplines. Not only statistics - even though it is a crucial part what I already stated in a lot of videos.
LR is not a classification algorithm but it can easily be used for binary classification where the magnitude of the output is the probability of a classification.