Predicting Stock Prices with Python using Machine Learning - Linear Regression

Поделиться
HTML-код
  • Опубликовано: 1 июн 2024
  • In this video we are covering the simplest form of Machine Learning to predict stock prices (or rather returns) in Python using a Linear Regression.
    Get the Notebook/Source code by becoming a Tier-2 Channel member:
    / algovibes
    As said in the video you should not take this as a valid trading strategy. It is just an idea how a linear Regression can 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 :-)
    Mentioned videos:
    Logit regression:
    • Logistic Regression in...
    Multiple linear regression:
    • Multiple Linear Regres...
    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 #Regression
    Disclaimer: This video is not an investment advice and is for informational and educational purposes only.
    0:00 - 01:04 Introduction
    01:04 - 04:53 Data prep
    04:53 - 06:15 Model building, fitting & prediction
    06:15 - 08:24 Strategy, Performance and Visualization
    08:24 - 14:40 Overfitting and avoiding with train test split
    14:40 - 16:42 Number of trades
    16:42 - 18:59 Playing around with different assets, lags (skippable)

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

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

    Fantastic how easy this was to follow and get some practical display of how to use these tools.

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

      Very happy to read man. Be kindly invited to check out my other stuff!

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

    great video, have been going back through some of your old videos. question, how do you get the next day's prediction based on the train_test_split?

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

    Thanks Man! Cool video as always! Could you possibly do a video on Reinforcement Learning in the future? I'd love to see your perspective and application on the that particular subject. Again thanks for your work! Amazing!

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

      Interesting topic indeed, agreed! On my list but not quite sure when I will cover it.

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

    Very good video. Thank you for sharing!

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

      Welcome! Thanks a lot for watching :-)

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

    Thanks! Very informative!

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

      Thanks for watching! :-)

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

      @@Algovibes could you do something similar with SVM? Thanks!

  • @cealgo-ctrader9393
    @cealgo-ctrader9393 2 года назад +7

    Another great video.
    one comment (or request), I totally agree that price predication using ML is a very risky idea, however, direction predication is might be a good approach with ML, please try to go further deep in ML classification for price direction prediction, I hope you will explain in simple way how to predict future (or next day) price direction. Thanks a lot.

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

      Thanks a lot for your feedback. Appreciate it!

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

    Thanks for the nice video!

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

      Thanks for watching mate

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

    Hey nice video !
    Maybe I'm wrong, but in 13:35 shouldn't we subtract -1 to account for the initial investment ?

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

    Thanks mate!

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

      Thanks for watching my friend!

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

    More Machine Learning vidoes :D :D :D It was great!

  • @josephpalakunnel5707
    @josephpalakunnel5707 2 года назад +4

    Thx man i was searching everywhere for this I'm started learing python a month ago

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

      Awesome! Thanks for watching :-)

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

    Thank you!

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

      Thank YOU for watching :-)

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

    Is there an option to add a plot title with this command in your code: np.exp(df[["returns", "strategy_LR"]].cumsum()).plot(). I don't see matplotlib being imported explicitly where the title method is available. Thanks.😀

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

      Yea sure, you can also just plot this with matplotlib and make your customizations then.

  • @nasimabu-dagga3143
    @nasimabu-dagga3143 Год назад +1

    Hi Algovibes. I found this video useful for learning about linear regression and data frames. I am trying to recreate your code but am encountering an error on the model fitting. Key error: "None of [Index(['lag_1', 'lag_2', 'lag_3', 'lag_4', 'lag_5'], dtype='object')] are in the [columns]" I have copied your code 1:1 and can't figure out what is going wrong. Do you have any ideas? Thank you!

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

      Hard to say where exactly the error is occurring but you definitely slightly deviated somewhere from my approach. Just go through it line by line again and it will be fine.

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

    how Can I do to get the recommendation from strategy? like the signals to buy and sell?

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

      If the direction is -1 you should sell and if the direction is 1 you should buy. Is that answering your question?
      Edit: I am referring to the column direction_LR

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

    thanks you!

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

      Welcome buddy, thanks for watching :-)

  • @pranavkhatri9564
    @pranavkhatri9564 9 месяцев назад

    what do we do in feature extraction?

  • @cold_aim
    @cold_aim 2 года назад +4

    can you please make a video on detecting breakouts like a stock price breaking their high low chain?

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

      Cool idea! It is not on my list right now but I noted that. Thanks for the suggestion.

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

      @@Algovibes sure i was going to add this feature to my bot anyhow so i thought it would be great to see someone else's approach :) and yea thanks for your reply and adding it on your your to-do list and if it will be based on indian stock market it will be great....

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

      I think if we add more supply demand combine your breakouts strategy for more performance

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

      @@nguyenduyta7136 yep that will be a great help in trading that's why I was thinking of making such algorithm that can direct that

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

    thanks , please provide code

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

    I wish i understood WTF you are doing with this coding stuff but i enjoy watching it... just watching thses makes me feel smarter EVEN THO idk wtf this code really does or what each part mean but hey.... its a view hahaha

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

      lol :D
      You are invited to check out my Python Introduction playlist :-) Also Python for Finance playlist could help you out.

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

    please make video on machine learning on option chain

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

      Not planned but noted. Thanks for your suggestion!

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

    Can u make a full course

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

      Maybe one day if I find some time!
      But I will continue this series on some other ML Algorithms (mostly classifications probably).

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

    how can we use this to predict future prices?

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

      By letting the model run for the most recent prices. But as I said this is just a play around and will definitely not result in profitable results!

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

      @@Algovibes of course i understand its just for educational purposes, thank you for this! So by letting it run for recent prices, we can add an end date variable for a time in the future when reading in the data?

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

      @@Algovibes how would you recommend doing a forecast for 30 days? thank you!

    • @Insh2020
      @Insh2020 5 месяцев назад

      Can you update your codes to predict price for next day as an example​@@Algovibes

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

    oh yessss tks u any thing beside bitcoin

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

      thx for watching bud :-)

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

    I see you fixed the variables to fit your beliefs about returns 😂. Once I am done with python than we can discuss this.

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

    I see the content on this channel is heating up