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

Комментарии • 57

  • @intyelcapo
    @intyelcapo 2 года назад +1

    Thank you very much !! I like the way you explain ;)

  • @hasanhas00n1
    @hasanhas00n1 2 года назад +1

    great series just watched your video from 16th of may it seems like you have stepped up your bot. thanks for sharing

    • @Algovibes
      @Algovibes  2 года назад

      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.

  • @mrvincefox
    @mrvincefox 2 года назад +1

    You share some awesome info. Thanks

  • @cnaccio
    @cnaccio 2 года назад +1

    Love the content!

  • @da0ud
    @da0ud 25 дней назад +1

    Conclusion, you randomly picked between - 1 and 1. Good job.

    • @Algovibes
      @Algovibes  3 дня назад

      nope, wrong! Do the test: Just backtest a trading strat where you randomly pick to buy and sell - will perform way worse.

  • @randomdude79404
    @randomdude79404 2 года назад +6

    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 !

    • @Algovibes
      @Algovibes  2 года назад +2

      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.

    • @randomdude79404
      @randomdude79404 2 года назад +1

      @@Algovibes thanks for the reply appreciate it and yes I understand and agree with you

  • @baljindersingh398
    @baljindersingh398 Год назад

    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

  • @TylerDurden191
    @TylerDurden191 2 года назад +1

    Great contento! Why are you converting to np.log?

    • @Algovibes
      @Algovibes  2 года назад

      Just to make the returns additive.
      I explained it here:
      ruclips.net/video/fWHQwqT3lNY/видео.html

  • @fardinhamidi8037
    @fardinhamidi8037 2 года назад

    Is there any reason to adjust the model by introducing the RSI to adjust for overbought and oversold markets?

    • @Algovibes
      @Algovibes  2 года назад

      Could you elaborate the coherence of that with the content of this video.?Maybe I am just getting it, sorry :D

  • @ilovekhr1
    @ilovekhr1 Год назад +1

    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?

    • @Algovibes
      @Algovibes  Год назад

      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.

    • @ilovekhr1
      @ilovekhr1 Год назад

      @@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?

  • @yangwang9688
    @yangwang9688 2 года назад +1

    What is the trading rule after you get the direction of the instrument movement? Why are you multiplying the direction with the returns?

    • @Algovibes
      @Algovibes  2 года назад

      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.

    • @yangwang9688
      @yangwang9688 2 года назад +1

      @@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.

    • @Algovibes
      @Algovibes  2 года назад +1

      @@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.

  • @sarvesharora1660
    @sarvesharora1660 2 года назад +1

    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 ?

    • @Algovibes
      @Algovibes  2 года назад +1

      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

    • @sarvesharora1660
      @sarvesharora1660 2 года назад +1

      Thanks sir, really helpful

  • @Septumsempra8818
    @Septumsempra8818 2 года назад +2

    Random Forrest with a set of technical indicators to predict next day.
    s/o from South Africa

    • @Algovibes
      @Algovibes  2 года назад

      Nice suggestion! Thanks and greetings to 🇿🇦

  • @korshun38
    @korshun38 2 года назад +1

    Спасибо!

    • @Algovibes
      @Algovibes  2 года назад +1

      Thanks a lot for using the Super Thank feature. Appreciate it and happy to have some Rubel in stock :D Спасибо! :-)

  • @ihebbibani7122
    @ihebbibani7122 2 года назад +1

    How do you explain that an AI algorithm could not do better than a passive strategy ?

    • @Algovibes
      @Algovibes  2 года назад

      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

    • @ihebbibani7122
      @ihebbibani7122 2 года назад +1

      @@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...

    • @Algovibes
      @Algovibes  2 года назад +1

      @@ihebbibani7122 definitely a fair point!

  • @16oshe
    @16oshe Год назад +1

    compartir el código

    • @Algovibes
      @Algovibes  Год назад

      Yessir!
      Be invited to join here:
      ruclips.net/channel/UC87aeHqMrlR6ED0w2SVi5nwjoin

  • @LoYaL_RR
    @LoYaL_RR 2 года назад +2

    Bro could you please open a telegram group? I would love to talk about this stuff :D
    Außerdem, du sprichst deutsch, nh?

    • @Algovibes
      @Algovibes  2 года назад

      Telegram nutze ich leider nicht. Sorry!

    • @LoYaL_RR
      @LoYaL_RR 2 года назад +1

      @@Algovibes discord?

    • @Algovibes
      @Algovibes  2 года назад

      @@LoYaL_RR Leider nicht :(

    • @maxk3895
      @maxk3895 2 года назад

      @@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 :)

    • @maxk3895
      @maxk3895 2 года назад

      @@Algovibes und gute Videos 🙏🏼

  • @maximorenatonia8724
    @maximorenatonia8724 2 года назад +1

    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'

    • @Algovibes
      @Algovibes  2 года назад

      Thanks mate. It's probably just a small thing. How exactly did you define the model variable? Pretty sure there is the issue.

    • @maximorenatonia8724
      @maximorenatonia8724 2 года назад +1

      @@Algovibes fixed the problem many thanks for your answer much appreciate it !!

  • @davidxiangaspar9126
    @davidxiangaspar9126 2 года назад +1

    Hello pls read my message on your other video it's a great strategy

    • @Algovibes
      @Algovibes  2 года назад

      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 :-)

  • @k2icc
    @k2icc 2 года назад +1

    KeyError: 'Lag_1'

    • @Algovibes
      @Algovibes  2 года назад

      Can you elaborate?

    • @k2icc
      @k2icc 2 года назад +1

      @@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.

  • @juancarbonell9948
    @juancarbonell9948 2 года назад

    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.

    • @Algovibes
      @Algovibes  2 года назад

      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.

    • @BullNkosi
      @BullNkosi 2 года назад +1

      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.