Use Artificial Intelligence (AI) to Predict the Stock Market with Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ก.ค. 2024
  • #Programming #Python
    How I used AI & XGBoost to predict the stock market
    Disclaimer: The material in this video is purely for educational purposes and should not be taken as professional investment advice. Invest at your own discretion.
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
    ⭐Please Subscribe !⭐
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
    🐦🔥🐤 Support The Channel🐤🔥🐦
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
    ⭐Get the code and data sets or just support the channel by becoming a supporter on Patreon:
    ► / computerscience
    ⭐Website:
    ►everythingcomputerscience.com/
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
    📚Helpful Python Programming Books📚
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
    ► Hands-On Machine Learning with Scikit-Learn and TensorFlow:
    amzn.to/2AD1axD
    ► Learning Python:
    amzn.to/3dQGrEB
    ►Head First Python:
    amzn.to/3fUxDiO
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
    📚Helpful Financial Books📚
    ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
    🌟Stock Market Investing Books:
    ✔️The Bogleheads' Guide to Investing
    amzn.to/3s0icxA
    ✔️The Intelligent Investor
    amzn.to/34Mj7t1
    ✔️A Random Walk Down Wall Street
    amzn.to/3Bv0ghW
    🌟Money Mindset Books
    ✔️Rich Dad Poor Dad:
    amzn.to/3rZW6eE
    ✔️Get Good With Money: Ten Simple Steps To Becoming Financially Whole:
    amzn.to/3I1UXc1
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 67

  • @leandrogoethals6599
    @leandrogoethals6599 8 หลายเดือนก่อน +21

    How the flow of a forwardtest such prediction is:
    Step 1: Download the csv till current date
    Step 2: Delete the last 20% of the timestamps of the csv so if it's like data of 2000 till 2023 then cut till 2019 and save this as training_SP500.csv
    Step 3: Do the opposite of step 2 wich u cut the first 80% off and save it as future_Sp500.csv
    Step 4: train only on the data of training_SP500.csv
    Step 5: u test the the prediction for the missing 20% of the current data
    Step 6: on same chart plot the original data of the current s&p500 data
    And Voila a chart wich u can clearly see is those prediction where in the right direction!!
    Nice vid, good education

    • @itssardine5351
      @itssardine5351 2 หลายเดือนก่อน

      So you’re just using 20% of available data to train? Seems like a whole lot of input is lost…

    • @leandrogoethals6599
      @leandrogoethals6599 2 หลายเดือนก่อน

      @@itssardine5351 Well 20% of what u find adaquite ofcourse

    • @MyTopAnime
      @MyTopAnime หลายเดือนก่อน

      @@itssardine5351 If you know anything about AI, you generally use 20% as testing data and the rest as training data. Also sometimes too much data can cause overfitting. This means it can predict existing data with ease, but when it comes to new data, it will struggle to perform well.

    • @SPONGE2008
      @SPONGE2008 23 วันที่ผ่านมา

      ima be so fr i dont know how to get the csv file its like 2am im so tired lol anyone can help? would be appreciated

    • @leandrogoethals6599
      @leandrogoethals6599 23 วันที่ผ่านมา

      @@SPONGE2008 what u mean get "the" csv file u mean the one the video creator made(wath is his name again).
      I use my own csv wich is constructed by quering an api from a dataprovider, of course i don't wanna pay for data so i do this multiple times for diffrent time ranges and paste them togetther again

  • @modichanel16
    @modichanel16 ปีที่แล้ว +1

    great tutorials 👍👍👍👍👍

  • @benzhou9751
    @benzhou9751 9 หลายเดือนก่อน +5

    How do I get it to predict more

  • @dansimon4056
    @dansimon4056 ปีที่แล้ว

    Hey, nice, can you do a tutorial for optimal execution on python using almgren kriss?

  • @joao_paiva
    @joao_paiva 10 หลายเดือนก่อน +2

    This type of algo is usefull just to predict the next time event. You have 70% accuracy but you are predicting just the next day price based in the last day price multiple times

    • @rjsingh4255
      @rjsingh4255 10 หลายเดือนก่อน +1

      that is right mr future billionaire

    • @joao_paiva
      @joao_paiva 10 หลายเดือนก่อน +1

      ​@@rjsingh4255 lmao, just to share information bro 😂

  • @tuanvulet.9776
    @tuanvulet.9776 ปีที่แล้ว

    thanks bro

  • @Mr._Cousin
    @Mr._Cousin ปีที่แล้ว +10

    should it be more reasonable to use the price the day before to predict the price next day in train and testing?

    • @sleepy9305
      @sleepy9305 11 หลายเดือนก่อน +1

      Smart idea but one days data might not be enough to make a good prediction

    • @joao_paiva
      @joao_paiva 10 หลายเดือนก่อน +1

      it's what he did, the N day open price is equal to the N-1 day close price

  • @yourbestlifebrandi
    @yourbestlifebrandi ปีที่แล้ว +4

    Where or how did you produce the input file for historical data? Where can it be obtained?

    • @MeghanaHM
      @MeghanaHM 8 หลายเดือนก่อน

      Same question

    • @user-nn4tf9eb6u
      @user-nn4tf9eb6u 7 หลายเดือนก่อน

      import pandas_datareader.data as web
      # Required steps to setup Yahoo Finance
      import yfinance as yfin
      yfin.pdr_override()
      aapl = web.get_data_yahoo('AAPL',
      start='2019-01-01',
      end='2020-01-01')@@MeghanaHM

    • @crackedatcurry
      @crackedatcurry 4 หลายเดือนก่อน +1

      kaggle

  • @Aether_46
    @Aether_46 ปีที่แล้ว +1

    Hope you had tutorial for deployment of this and for real time price to predit.

    • @taneti_sanjay
      @taneti_sanjay 4 หลายเดือนก่อน

      Predicting real-time market prices presents significant challenges due to the need for up-to-date data. While it's theoretically possible to predict future prices, accessing real-time data is often limited by market closing times and costly data acquisition. APIs typically provide data once the market closes, hindering the ability to make real-time predictions. Moreover, obtaining live data usually incurs substantial expenses. Therefore, predicting prices for future points requires historical data for training models, making real-time prediction impractical in many cases.
      In addition to data accessibility challenges, there are inherent complexities in modeling financial markets that further complicate real-time predictions. Financial markets are influenced by a multitude of factors, including economic indicators, geopolitical events, investor sentiment, and market psychology. These factors can lead to sudden fluctuations and volatility, making it difficult to accurately forecast prices in real time.
      Furthermore, market dynamics are constantly evolving, with new information continuously being incorporated into prices. This makes it challenging for predictive models to adapt quickly enough to capture and react to these changes in real time.
      Moreover, the presence of noise and randomness in financial data adds another layer of complexity. Despite best efforts to develop sophisticated predictive models, there is always a degree of uncertainty inherent in predicting future prices accurately.

  • @vyacheslavfiodorov5738
    @vyacheslavfiodorov5738 ปีที่แล้ว +3

    Are you sure that it is not learning from the high and low prices of the current day that has not yet closed? How to make sure?

    • @kenhan168
      @kenhan168 2 หลายเดือนก่อน

      For the volume, you can only get it after the market close. So putting current day of volume while the market is open has no much use, as the volume is changing throughout the day.

  • @rverm1000
    @rverm1000 ปีที่แล้ว

    typo? train_data= data.iloc[:int(.99 * len(data)), :]
    test_data= data.iloc[int(.99 * len(data)):,:]

  • @JCCreatorStudio
    @JCCreatorStudio 4 หลายเดือนก่อน

    im new to ML, the final plot only show some orange line near the end, what does it mean and where are the rest?

    • @GamingWithAJ175679
      @GamingWithAJ175679 3 หลายเดือนก่อน

      the dataset had the entire data including the one at the end. However, he split the dataset into 2 parts. 1 big and 1 small (the one at the end). He fed the bigger chunk of data into the ml model and kept the smaller chunk aside. Once the thing was trained, he asked the model to predict the next prices which he then compared to the smaller chunk of data he did not allow the model to see.

  • @kaushikmetha3429
    @kaushikmetha3429 ปีที่แล้ว +2

    This works only for one stock. Is there any way to design a neural network model that can be used to predict stock price of more than one stock?

    • @Stopinvadingmyhardware
      @Stopinvadingmyhardware ปีที่แล้ว

      No, there isn’t.

    • @AI_Vania
      @AI_Vania ปีที่แล้ว

      Yes, you can predict multidimensional stock returns with a nn by having one or more output nodes for each return series that you want to predict.

    • @GamingwithPortals
      @GamingwithPortals ปีที่แล้ว

      Just use threads and run the same program for many different stocks

    • @Stopinvadingmyhardware
      @Stopinvadingmyhardware ปีที่แล้ว

      @@AI_Vania No, there isn’t. You can’t predict, you’re only building a measurement based system that estimates risk and when to purchase and sell based on estimated risk.

    • @AI_Vania
      @AI_Vania ปีที่แล้ว

      @@Stopinvadingmyhardware What do you mean "you can't predict"? One can build a model to predict future prices or (maybe better) future price distributions. The NN doesn't necessarily make risk estimations or buy/sell decisions, those things may involve logic that is outside of the NN.

  • @hamzazakaria2582
    @hamzazakaria2582 11 หลายเดือนก่อน +1

    i keep getting an error at the "model.score" it says model is not defined

    • @luishernandezmatos2264
      @luishernandezmatos2264 10 หลายเดือนก่อน

      you have to define the model ===> model = XGBRegressor()
      model.fit(train_data[features],train_data[TARGET])
      y_pred = model.predict(test_data[features])
      #Accuracy
      model.score(test_data[features], test_data[TARGET])

  • @vladvol855
    @vladvol855 ปีที่แล้ว

    Very interesting! But, how could it be used in algotrading?

    • @jasonreviews
      @jasonreviews ปีที่แล้ว +2

      you can't it's 30-60% accurate. You can't predict black swan events or news.

  • @IkaroSampaioDj
    @IkaroSampaioDj 6 หลายเดือนก่อน +9

    Stopped this video when he included 99% of the data in the train_data. Makes no sense

    • @sebastiangomez6593
      @sebastiangomez6593 5 หลายเดือนก่อน

      Why , explain me
      I'm new in python

    • @mpregsonic5874
      @mpregsonic5874 4 หลายเดือนก่อน +5

      Yeah it does. He is doing EXTRApolation where the future is being predicted. Predicting more than 1 times step into the future in this case compounds the margin of error greatly. This means you’ll want to train on all of the data up until the time period you are trying to predict. This is standard in time series. Even if you want to train on 70 percent to predict the remaining 30 percent you do it in what’s called a rolling forecast way which essentially retrains the model on all the data up to the point you’re trying to predict for every point within that original 30 percent.
      In machine learning where time series is not involved, an INTERpolation problem, training the model on 70 percent and testing on the remaining 30 is a lot more common and makes sense.

  • @2ncielkrommalzeme210
    @2ncielkrommalzeme210 4 หลายเดือนก่อน

    way of Telling the program is brief . how can we get the csv files for example like yours SPY.csv

    • @gaurirajput9856
      @gaurirajput9856 3 หลายเดือนก่อน

      you can download it from google or you can get it from google search

  • @Talangenz
    @Talangenz 11 หลายเดือนก่อน

    How do I, predict more, like not only the test set for example 3 years forward

    • @joao_paiva
      @joao_paiva 10 หลายเดือนก่อน

      this type of code is usefull just to predict the next time event

    • @ditoiuc
      @ditoiuc 10 หลายเดือนก่อน +1

      in the last 3 years we had : covid, war on ukraine. no python script could take that into account

    • @reynolrodriguez4982
      @reynolrodriguez4982 9 หลายเดือนก่อน

      easy money 😂

  • @pohu6296
    @pohu6296 10 หลายเดือนก่อน +1

    Use Your prediction and check the return %, the results is very very poor. The prediction is basically noise with baseline of open price. You can just plot open price vs close price, the are similar to your prediction.

    • @AB_498
      @AB_498 6 หลายเดือนก่อน

      that's true but i wonder why it still got an accuracy of 70% on test data

    • @kenhan168
      @kenhan168 2 หลายเดือนก่อน

      @@AB_498 , because it feed in the current open price and the volume, which is not available in actual trading. You can only get Volume after the market close.

  • @codeline9387
    @codeline9387 6 หลายเดือนก่อน +2

    actually thats almost useless prediction coz we know volume when only when close is known

  • @useradav
    @useradav ปีที่แล้ว

    I followed you step by step, but my historical chart is a downtrend for some reason.

    • @businesstodayve
      @businesstodayve 11 หลายเดือนก่อน

      check the indexes of your dataset

  • @shilpabaranwal5913
    @shilpabaranwal5913 3 หลายเดือนก่อน +1

    Nice Video but not useful for real time prediction, volume information will not be available beforehand

  • @user-pp6xt4mq8c
    @user-pp6xt4mq8c ปีที่แล้ว

    where to get dataset for this

  • @user-mv6pv6vm8g
    @user-mv6pv6vm8g 9 หลายเดือนก่อน +2

    Overfitting bruh

  • @robertobonani8571
    @robertobonani8571 ปีที่แล้ว +6

    Can see you are a programmer but not a data scientist

  • @guillermogomez9731
    @guillermogomez9731 5 หลายเดือนก่อน

    Pregunta que le hago a todos, para que te sirve esto xD. Para nada, no te da ninguna info

  • @vv9730
    @vv9730 9 หลายเดือนก่อน

    etni jhak marane ke bad prediction acuuracy only 70 %....11:30..!!!

  • @tristeub997
    @tristeub997 29 วันที่ผ่านมา

    It is totally useless wtf ??

  • @serg8483
    @serg8483 5 หลายเดือนก่อน

    I'm surprised why this video is getting so many views and likes.
    You made a huge mistake in your logic.
    This is not the accuracy of your model. This is a coefficient of determination that does not play any useful role in building a trading strategy.
    The coefficient of determination shows how strongly you can describe the target variable using your features.
    If you take data from the previous day, and without a model. Your coefficient of determination will be 0.99
    In short, it’s not accurate and it’s useless what you did