Recurrent Neural Networks | LSTM Price Movement Predictions For Trading Algorithms

Поделиться
HTML-код
  • Опубликовано: 10 авг 2022
  • This video presents a simple way to introduce RNN (recurrent neural networks) and LSTM (long short term memory networks) for price movement predictions in trading Forex, Stock Market and Crypto. The algorithm is written in python language and can be downloaded so you can experiment on by changing the algorithm parameters. Deep Learning has been advertised as the ultimate prediction algorithm, in here we put it to the test in trading and price movement predictions. Technical indicators are added as well such as the relative strength indicator RSI and moving averages MA to extend the input data for the trading model.
    🍓 Follow structured courses with more details and practice exercises check my "About" page for Discount Coupons on my Udemy courses covering:
    - Python basics Kickstarter,
    - Object Oriented Programming
    - Data Analysis with NumPy and Pandas including financial analysis exercises,
    ... more courses are on the way drop me a message if you have a particular interesting topic!
    Good luck!
    #forexanalysis #neuralnetworks #deeplearning #tradingbots #tradingbot #forex #stockmarket #stocktrading #stocktradingstrategies #algotrading #python
    💲 Discount Coupon for My Udemy course on Algorithmic Trading:
    bit.ly/CouponAlgorithmicTrading
    The python code link:
    drive.google.com/file/d/15xlg...

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

  • @903vulture
    @903vulture Год назад +11

    Great job dude!! I'm learning a lot watching your videos. You have an excellent way of teaching, using plain, clear and concise English. Thank you!!!

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

      Thank you so much for your support, I started this channel as a learning space, but drifted more towards trading 🙂

    • @xyz9571
      @xyz9571 8 месяцев назад

      Watch the Lazy Programmer's videos if you want to learn why everything in this video is crap and doesn't work.

  • @a.winath4024
    @a.winath4024 Год назад +2

    I can not wait until the next video.Thank you so much!

  • @JohnQuezadaHuayamave
    @JohnQuezadaHuayamave Год назад +2

    Excelente explicación, me gusto mucho como fuiste detallando cada parte, estoy revisando todo tus videos y los veo varias veces para estar seguro que todo comprendí y no perdiera algo.

  • @antonioaqueiroz
    @antonioaqueiroz 10 месяцев назад +1

    Excellent work. As I got motivated with your video, I also watched your python training in Udemi. Congrats!!

    • @CodeTradingCafe
      @CodeTradingCafe  10 месяцев назад

      Thanks a lot for your support I hope the courses were useful ! Good luck in your coding journey!

  • @foobarAlgorithm
    @foobarAlgorithm Год назад +5

    Amazing work! Although I have a few questions, sorry for the noob question, as I’m still learning CNN, just a normal pandas and numpy user. When using these models to predict, are there any cases of accidental data snooping? What are the best practices to avoid it? Also when the neural network predicts one of the next days closing price and moves to the next one, does it use the predicted closing price from previous day or the actual data’s adjusted close for computation? I’m sorry if it’s a stupid question, I’m just curious to understand this better. Thankyou!

    • @CodeTradingCafe
      @CodeTradingCafe  Год назад +6

      Hi thank you for your support, actually your questions are not as noob as you think, the model uses the last real close value to predict the next one and this is very tricky I am making a video about it for the next week because people shouldn't be tricked by a nicely looking curve... More to come hopefully it will answer your questions.

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

    Thanks for sharing, its really educational and so helpful as this improves analytical view concerning the market

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

      Thank you for your support 😊, it really helps.

  • @jadonsumit786
    @jadonsumit786 4 месяца назад

    Thank you, very much brother. I have been searching for 3 days for how to make strategies for NN classification. I have got a lot of ideas from your video. seriously thank you very much brother.

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

    This is absolutely eye opening.

  • @outlinefrom2023
    @outlinefrom2023 8 месяцев назад +1

    Great job, I learned a lot, but I have a question , what should I do/ what the code should I use if I want to forecast next 4-5-10 days. as per as I understood from this useful video that you built a model to predict the next closing price and compare it with the real data you already have, but my question is, what if I want to forecast for n days??

    • @CodeTradingCafe
      @CodeTradingCafe  8 месяцев назад

      Thank you for you support! answering your question you will have to modify the training part so the target values considering 5 days and then train your model on this, followed by predictions which are assumed to predict for 5 days. That's one simple way of doing it.

  • @abdsh422
    @abdsh422 7 месяцев назад +1

    first thank you a lot for such a great video. if I am not wrong the results you shared at the end of the video are the scaled one. what do you think will be the best approach to rescale them and will scaling the data increase the predation gaps?

    • @CodeTradingCafe
      @CodeTradingCafe  7 месяцев назад

      Hi scaling will not change much in this case, the problem is more serious than this, so errors from scaling are invisible here. But just to be more precise scaling is playing to the predictions favor here because of data leakage when splitting into train and test chunks.

  • @user-pr3pp8fb8m
    @user-pr3pp8fb8m 9 месяцев назад +1

    Hi, Nice work!! Could you also elaborate on how to use non-numeric features in a similar price prediction model?

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

      Hi, thank you, for the non numeric features I have to show it in a video, but one example could be if EMA trend is up or down (categorical feature), or also sentiment analysis of a webpage for example.

    • @davidenzler1691
      @davidenzler1691 8 месяцев назад +1

      In general you would need to encode non-numeric features. Basically translating them into numerical features with associations between values and categories of data. There are quite a few ways to do this, like one-hot encoding and also label-encoding. If you have five categories for one feature (for example: a stock could be in the manufacturing sector, technology sector, farm sector, health sector, or retail sector) you could assign each category a value from 1-5 and use that in your feature set. This would be label encoding. There are some good guides on youtube and some more in-depth articles on medium if you google them.

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

    Love this video and your series. Keep it up bro.
    Question, how to start prediction once you've saved the model?
    iow, how can I generate a df['predictedprice'] column using model.predict? Without using the 0 - 1 scaled data conversion.

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

      Thank you for your support, to go back to original values you can use the inverse_transform function of the scaler

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

      ... but you might want to check this video first ruclips.net/video/lhrCz6t7rmQ/видео.html

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

      @@CodeTradingCafe Perdón por la pregunta super noob pero la función necesita un rango de características y estoy teniendo problemas para encontrar lo que es en el código como lo que debo poner como el rango de características. Podrías ayudarme por favor 😂

  • @sbkyoutu
    @sbkyoutu Год назад +3

    Thank u so much 4 ur efforts
    most of predictions or all them kind of shifting actual data by certain value
    it should be like this> use real data up to now then predict what after that

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

      Thank you for your comment, more of these to come... Good luck!

  • @steeltormentors
    @steeltormentors Год назад +3

    instead of predicting the next day price outcome, can we make the model to predict a trend? I'm not sure about the ideal timeframe but maybe between 2 weeks to 2 months ahead? So it's more like a medium term price predictor...
    If it's possible I would be very interested to see the next part the series to dig deeper into this.
    As always great video!

    • @CodeTradingCafe
      @CodeTradingCafe  Год назад +3

      Hi thank you for sharing your ideas, yes it's possible to try and predict let's an average market price over the next 5-10 days I think a video is worth it...

    • @DrJRMCFC
      @DrJRMCFC Месяц назад

      Good lucking trying to predict the next day’s close with a simplistic model such as this. It will not work. As for predicting weeks or months ahead? Absolutely no chance.

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

    Thank you for this video, would you have any idea, genreally speaking how to approach this if one had multiple stocks to predict?

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

      Hi thank you, honestly I wouldn't use neural networks for this, as the results are not that accurate, I would for a classic less computation and more reliable.

  • @phaneendhraajaythota1025
    @phaneendhraajaythota1025 Год назад +3

    along with this.. can you also include how market depth affect prediction. . and financial news of a company affects the price prediction at that time.

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

      Yes it's possible a bit more complicated though. Requires more time 🙂

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

    Thanks for the Video!
    Im currenly learnig a few things and your videos helped me a lot.
    I noticed that the model will give me different results with the same dataset and same parameters.
    Is there any way to avoid this behavior?

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

      Hi, thank you for your message, I am glad these videos are helpful. For the results differences might come from any parameter it's hard to guess but you should get something close anyway.

  • @NM-bd6bs
    @NM-bd6bs 9 месяцев назад +1

    Hi, when you scaled your entire dataset before splitting it into training and test sets, do you think information from the test set might have leaked into the training set during scaling, which could've maybe artificially boosted performance?

    • @CodeTradingCafe
      @CodeTradingCafe  9 месяцев назад +2

      Definitely yes, there is a leak of information especially the max and min values, but still with this the performance of RNN is still bad.

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

    can you combine this with time series forecasting algorithms? I done Autoregression with multi layer perceptrons before could we do ARIMA with RNNs?

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

      Hi, it's possible I am not sure about the results though we have to try it

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

    Super!!!!
    I didn't understand one point. When u define data[TargetClass] and set 1 if data ... Greater than 0 or 0 for i in a range.
    What it means to set it to 1 or 0?

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

      Hi thank you, 1 or 0 are 2 classes these are called labels in machine learning so that the model learns from these labels when. Price is going up and when it's going down.

  • @mohamednedal
    @mohamednedal Год назад +4

    Nice work! Shouldn't we shift the predictions back by one step to better match the real data?

    • @CodeTradingCafe
      @CodeTradingCafe  Год назад +2

      Hi, thank you. We are comparing the predicted future price to the real future price, so no shift needed here, because in real life if we use the model to predict future value... we can't shift values

  • @arthurhottier7594
    @arthurhottier7594 10 дней назад +1

    helllo, thanks a lot for your video, it was wonderful to watch. I have a question, in the end, your predicted prices are not scaled back to normal, it is possible for you to telle me how i can scale everything back to what it originally waws ? thank you !

    • @CodeTradingCafe
      @CodeTradingCafe  10 дней назад

      if you are using a scaler, you can use scaler.inverse_transform(...) function from sklearn. Thank you for your support.

  • @william_8844
    @william_8844 10 месяцев назад +1

    Aren't you supposed to use the normal distribution instead of min-max?
    Great video by the way. I enjoyed it's simplicity

    • @CodeTradingCafe
      @CodeTradingCafe  10 месяцев назад

      Hi thank you! it's an open question how to normalize data it seems that most of the times data scientists try both and they pick the better results, however in our case it wasn't worth it since we are far from real predictions.

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

    Thank you for your nice video. One comment is that because the the train-set and test-set are splitted AFTER applied the MinMaxScaler, so, to visualize and calculate MSE, the target and predicted value need to be inverted using the same scaler. You can find that your plot (to compare real and predicted close price) shows the price in range $0 - $1 while it should be the original close price which are much higher (> $700). Would be very appreciated if you can share that code to invert the predicted value if you did it lol

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

      You can use inverse_transform function for this... Just use it with the same scaler as you mentioned, good luck!

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

      @@CodeTradingCafe i did inverse_transform function , but i am getting error like that
      ValueError: non-broadcastable output operand with shape (503,1) doesn't match the broadcast shape (503,11), pls help how to solve this error

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

      @@Lbvi you have to apply the function on dataframe of the same shape so you are replying only on the target which is one column however you have transformed 11 column dataframe.

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

      @@CodeTradingCafe thanks you

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

      @@CodeTradingCafe This was a very helpful video for build my first NN for stocks. I'm also struggling with this inverse. I've been at it for days and cannot get it to match the shape. Any suggestion on how you take the single y_pred and reverse it back to the original 11 column df that the scaler was applied to?

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

    ahg i cant wait for the next video

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

      Lol you're not going to like it unfortunately, spoiler alert the hero dies ... The algorithm looses 😂

  • @Sean-es9zc
    @Sean-es9zc 10 месяцев назад +1

    Greetings from HK, thank you for the wonderful tutorial!
    I am wondering if there is a chance we may adjust the input parameter(s)' "time range" including the return change of the stock itself and other indicators, to make this suitable for stock prediction 1 year later (but not tmr), I am trying to include machine learning elements into equity research report that usually has stock target price set for 1 year later. Would appreciate it a lot if you could let me know how to amend the code, thankss!! 🙏

    • @CodeTradingCafe
      @CodeTradingCafe  10 месяцев назад +1

      Hi, thank you for your comment, you can change the target function parameter it takes a number of future candles, however for this I would use the weekly or monthly timeframe, it makes things easier and with less noise for your long term predictions.

    • @Sean-es9zc
      @Sean-es9zc 9 месяцев назад

      @@CodeTradingCafe Thank you very much!!!

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

    It seems that the gradient found that y( i ) = y( i - 5 ) reduce the error as much as it can~
    But would't act as prediction, it's just a forward shift of the past values. I'm pretty sure that if the models runs in autonomous mode for just 100 close steps it will diverge into a whole new plot.
    Plus, using minmax scaling to normalize price values than can exceed over 0 or 1 by far, doesn't seems a good idea. I would use price percentual derivative or percent change in pandas.

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

      I see your point but how do you mean percent regarding open high low and close values.
      ... actually you might be interested in next week's video as a continuation

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

      ​@@CodeTradingCafe You don't, you calculate all the indicators you want by closing price at first, and then, those indicators that are not index like RSI or Stochastic RSI that are already "normalized", you need to apply the percent change value over EMA, SMA, BB, MACD or any other indicator that still represents some direct price value. This last needs to be customize a little bit to each Indicator, because you have to decide which values are you applying the percent change ( like, Bollinger Bands, which pct change would be better for Top band? The pct change of itself, or relative to the middle band? )
      This is just what I've tested by my own, I actually never tried using the price directly which afaik neural networks don't like descriptors like that.
      And, since we are using time series input, seems to make sense to predict time series aswell, but did you think about classifier? Works even better.
      In case you feel curious about what looks like the classification I've made, here is an example by different cost functions and different periods.
      i.postimg.cc/fLcrpjL7/nn-class-sample.png
      This model was just using Stochastic RSI, annd no recurrent layer needed to this, just one layer basic model, but still need to test it on LSTM layer if makes some improve. I've already tried in CNN, but at more indicators you use, the complex it gets, specially if indicators have different periods.

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

      Thank you for sharing, that's a lot of work 🙂 will keep some ideas in mind for next projects... But to be honest lstm is the most challenging in this field I don't think it would work, simple methods are providing better results.

  • @shaman3198
    @shaman3198 4 месяца назад

    Nice work , I will learns this video for forex option trading.

    • @CodeTradingCafe
      @CodeTradingCafe  4 месяца назад +1

      Best of luck, and thank you for your support!

    • @DrJRMCFC
      @DrJRMCFC Месяц назад

      It won’t work. Sorry.

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

    Be careful, you did a very common mistake: the scaling of data must be done after train/test splitting and not before, otherwise it can introduce data leakage.

    • @CodeTradingCafe
      @CodeTradingCafe  Год назад +3

      Hey Jorge thanks for pointing this out indeed it can affect the scaler leaking the max and min of train data to the test data, but even with this it is still not a good technical indicator in spite the error which should play in favor of the prediction.

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

      During analysis train test split should be done with the way you mentioned, but during live deployment you are not splitting based on the params you use and you need as much as recent data possible. This makes significant improvement in my model. I haven’t lost a single penny over the past 6 months doing that. Plus another problem is that LSTM is not used to predict price, hence why the results are not amazing in the video, I have a live bot running on this and my use case is completely different from the video + I use as much as data possible, although this is an interesting video for beginners

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

      @@AI_BotBuilder hi sir i am working on a bot for trading and im using algo strategies and i am trying to implement machine learing to it. if you could help me with the process i would really apriciat.(even hints are appreciated)

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

      @@AI_BotBuilder Whats your use case

    • @kirwakelvinkering3122
      @kirwakelvinkering3122 6 месяцев назад

      I fell like this is the issue am having with my model , how is this even possible ?

  • @yaas
    @yaas Год назад +2

    For anyone wondering, this model means nothing as many previous videos have done, it’s simply a lag prediction, day 1 is 100: day 2 is 120 and model predicts 99 for day 2 for example, on day 3 the model will predict a number near day 2 ie 120, thus generating a lag graph.
    Now how to actually predict it works ? Let it predict percent change difference not just price therefore isn’t as affected by previous day price and the lag effect is gone and you can actually see how many correct predictions happen.

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

      Thank you Yassin, check my next week video, you might be interested in.

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

      @codeTrading hey i know you mentioned it in the description and you know this. Just thought I’d clarify for those who were wowed about it :D I did my thesis trading crypto with lSTM actually and got it to work (it did well but not amazing), but yeah I’d say there are better models than LSTM for this.

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

      @@yaas actually the reason I did this video is because it looks so good at first and might trick some of us. It's good you could get it to work for me it looked more challenging than other algos.

    • @yaas
      @yaas Год назад +2

      Yes it took months and tens of hyperoptimizations just to get about 65% accuracy ( When entered in a trading bot though profits where significant year B&H: -180% model profit 160%, in multiple coins. So yea overall not too shabby.

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

      I can imagine the amount of work sometimes I am drained after a RUclips video 😂

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

    ​ @CodeTradingCafe Can I use this model to predict the Index? My goal is to predict changes in NASDAQ with machine learning using of global market indices such FTSE, DAX, Nifty, etc.

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

      I am generally very skeptical with neural networks. But I guess you can give it a quick try on historical data and see what it gives.

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

      Thanks @@CodeTradingCafe. I think you are correct. I have tried with LSTM but is not working as expected for my use case. Let me try with bagged adaboost/xgbtree classification model.

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

      Thanks for the feedback, good luck!

  • @aaravguduru1469
    @aaravguduru1469 Месяц назад +1

    Nice video! How do we use this to predict the prices for tomorrow??

    • @CodeTradingCafe
      @CodeTradingCafe  Месяц назад

      It's not tested enough, and actually at this stage it would still waste/loose money, check my most recent videos for live trading from python.

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

    For me, the green line looks quite identical but also with an offset of one or two days. Its Not really a prediction If I Just repeat the values fromm the days before.
    Actually, I encountered the same issue but dont know how to deal with it yet.

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

      Hi, thank you, I agree, it's totally a copy of the previous price I have another video where I zoom into this issue and show why it happens ruclips.net/video/lhrCz6t7rmQ/видео.html I hope it helps

  • @aarondelarosa3146
    @aarondelarosa3146 10 месяцев назад +1

    Excellent. Could you make a video on Forecasting using Prophet?

    • @CodeTradingCafe
      @CodeTradingCafe  10 месяцев назад +1

      Thank you for your support! check this one I used Prophet ruclips.net/video/lmoHsgSKBNA/видео.html

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

    thx! I was able to combine some stuff from this video with some stuff from u're bbands scalping... backtested it on unknown data and the AI is able make some amazing signals! it performs better than all the normal strategies I've tested. Like suggested I've let it have to choose only one category: long or not long. However the AI signals alone are useless... but in combination with normals signal it performs really good.

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

      Thank you for your feedback, this is nice to here, I initially started this channel to share ideas where people can tweak and learn and experiment just like you did. Good luck!

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

      @@CodeTradingCafe does this community has a discord?

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

      Unfortunately not, I wouldn't be able to manage 🙂

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

    How would you inverse transform the predicted values to get actual predictions?

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

      there is function in sklearn called inverse_transform() for this. Good luck!

  • @ilpaghynonpaga
    @ilpaghynonpaga Год назад +2

    Do u seriously share the code?! Man u are just unique, this is so nice. Thanks so much, really!!

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

      Well to be honest I prefer education, understanding and critical thinking so why not? (Of course if the code would make us rich as well that would be nice but so far my codes can only make 20percent return per year... So not rich yet 🙂)

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

      @@CodeTradingCafe 20% per year is great, you got banks making 12 only.

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

      True! But greed is the culprit 😂 always looking for more return

  • @user-co7rq2ye2u
    @user-co7rq2ye2u 3 месяца назад

    Hi, I will be glad to get some help to understand better your network.
    as you said you predict the 10th day value based on the back candles days.
    so I expecting to get 1 value if I will send to the predict function of the model back candles number of data.
    but I actually get back a back candles predicted values.
    I will be glad if you can explain it better for me.

    • @CodeTradingCafe
      @CodeTradingCafe  3 месяца назад

      Hi, it's hard to debug if I am not running the code, but you are probably getting a single forecast value per point and you can have many points in the test set I mean in the code X_test is a range of values.

  • @trangdong7613
    @trangdong7613 Месяц назад

    Could you also do predictions with other mathematical models like Quantum Finance and Complex Fuzzy Logic
    ? Thanks.

    • @CodeTradingCafe
      @CodeTradingCafe  Месяц назад

      For fun yes, but don't expect much on the results side, all still experimental.

  • @vidaamericana_br
    @vidaamericana_br 10 месяцев назад +1

    Where do you grab that data? it's just import on python? can I configurate to take live data with this?

    • @CodeTradingCafe
      @CodeTradingCafe  10 месяцев назад

      Hi, yes you can get the data directly within python using yfinance module.

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

    Great video, but how can I re-scale to the original numbers

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

      Thank you, you can use inverse_transform() function for your scaler it brings back unscaled numbers.

  • @PeterdelCanal
    @PeterdelCanal Год назад +2

    Interesante..., ¿predecir el futuro sería Maravilloso.....?

  • @mohammedyasser9885
    @mohammedyasser9885 6 месяцев назад +1

    I tested the model and it is so accurate on testing data..I want to predict the future like 2024 values what should i do??

    • @CodeTradingCafe
      @CodeTradingCafe  6 месяцев назад

      Hi, it's impossible to predict 2024, a lot can happen in the meantime and market will change eventually.

  • @user-mv6es9df6e
    @user-mv6es9df6e 9 месяцев назад +2

    I think that using the price as a feature can't be the right thing, because we don't have a ceiling or a floor for the price, the maximum price in the train dataset may be 100, but in the real data, we have more than 100.

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

      you are right, absolute values are not useful in this case, we need relative variables like slopes or so.

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

    finished watching

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

    how do you do multistep predictions for this example?

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

    Thanks! Suscribed :)

  • @JamminStuff
    @JamminStuff 6 месяцев назад +1

    hey I'm trying to add indicators it says "ATR missing arg 'low' and 'close' any ideas?

    • @CodeTradingCafe
      @CodeTradingCafe  6 месяцев назад

      Hi, yes the atr function requires the arguments low close etc... try help(ta.atr) it should show you what input args are required.

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

    what activation function did you use?

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

      Hey, good questions, I don't remember I will have to re-watch the video but I assume RELU

  • @diask486
    @diask486 3 месяца назад +1

    Is there any reason why you chose adj close instead of closing price?

    • @CodeTradingCafe
      @CodeTradingCafe  3 месяца назад

      Adj close is more precise considering market changed occurring when sessions are closed, if it's available it's usually better to use, but we're not at that level of precision yet with the LSTM trading approach.

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

    Does this work with a small dataset? Let's say less than 15?

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

      Hi, no it shouldn't work neural networks require relatively larger amount of data

  • @mathewn7251
    @mathewn7251 Год назад +2

    I am completely NEW and just want to try out the sample in the video and ran into 2 problems below.
    I typed in all the codes, and guessed what toward the end, the screen got cut off. so help!
    model.fit(x = X_train, y = y_train, batch_size=15, epochs=30, shuffle=True, validati???????)
    ALSO the last line caused problem as well.
    lstm_input = Input(shape=(days,8), name='lstm_input')
    inputs = LSTM(150, name='first_layer')(lstm_input)
    inputs = Dense(1, name ='dense_layer')(inputs)
    output = Activation('linear', name='output')(inputs)
    adam = optimizers.Adam()
    model.compile(optimizer=adam, loss='mse')

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

      Hi thank you for your comment, you can download the code from the link in the description, you don't need to type all of it. Let me know if it works.

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

    Dear Sir,
    How to retrieve original value from scaled value. I.e. y_pred, y_test

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

      Hi, you can use the function inverse_transform()

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

      @@CodeTradingCafe I have tried but it will give ValueError: non-broadcastable output operand with shape (506,1) doesn't match the broadcast shape (506,11)

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

      @@CodeTradingCafe i have tried inverse_transform()

    • @CodeTradingCafe
      @CodeTradingCafe  Год назад +2

      The shape of the data has to match if you fit the data on a dataframe of 11 features then you can inverse transform on the same data size, try fitting the transform on a single column first if you want to inverse transform a single column

    • @rahulmarutidhokane9028
      @rahulmarutidhokane9028 Год назад +2

      @@CodeTradingCafe thank you so much sir you are awesome

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

    Is lstm really that practical? watched most lstm tutorial video all predicted with trailing prices (lagging)

    • @CodeTradingCafe
      @CodeTradingCafe  Год назад +2

      Hi there is a recent video check it out b it's the continuation of this one. Let me know what you think.
      ruclips.net/video/lhrCz6t7rmQ/видео.html

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

      @@CodeTradingCafe thank for your works on this, looking forward on your next video!

  • @user-px2os2rd9p
    @user-px2os2rd9p Год назад +1

    Wavevlet transform can help to denoise time series

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

      Hi, yes in general it does, I don't know if it would work for this dataset, there's only one way to find out I guess. Thanks for sharing.

  • @davyponte
    @davyponte 10 месяцев назад +1

    then this algorithm not is a prediction for future price?

    • @CodeTradingCafe
      @CodeTradingCafe  10 месяцев назад +1

      It is, but the results are not up to the expectations, check some other videos they provide better indicators "support and resistance", or "price patterns". Good luck!

  • @OkSid300
    @OkSid300 Месяц назад +1

    What edge is expected from this, if it's expected at all?

    • @CodeTradingCafe
      @CodeTradingCafe  Месяц назад

      Nothing at all, actually in another video I show why it's just an illusion that this works while actually for the moment it doesn't. (the video ruclips.net/video/lhrCz6t7rmQ/видео.html )

  • @slothner943
    @slothner943 2 месяца назад +1

    How would you do this without test data? For example if i want to se an prediction a week from now?

    • @CodeTradingCafe
      @CodeTradingCafe  2 месяца назад +1

      Hi, you would use the current week data as test data and see the prediction for the next day rather than the next week, but in this case you need to train the model also to detect next day or next week values, so the way we train the model influences how the model applies predictions.

    • @slothner943
      @slothner943 2 месяца назад

      @@CodeTradingCafe yes but since its a times series, how do I train lstm on future values rather than previous? Im new at this, sorry if I ask stupid questions

    • @CodeTradingCafe
      @CodeTradingCafe  2 месяца назад

      You don't train on future values because theoretically you don't have them yet, you train on past and you predict future using the same trained model.

    • @slothner943
      @slothner943 2 месяца назад +1

      @@CodeTradingCafe yes but this is the thing that im missing, what values do I fill testset with when I dont have access to it?

    • @CodeTradingCafe
      @CodeTradingCafe  2 месяца назад

      The current values are filled in the model so it will provide the future values.

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

    We’re do we put the code does it work at pycharm

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

      Pycharm, vscode, anaconda, Spyder... Any python interface works. But from your question I guess you haven't used python before, so I would start with some basic lessons, try my Python learning playlist for a quick start. Good luck!

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

      @@CodeTradingCafe fare enough nah I’m studying IT HAHA but u know how the asset that’s were like should we change it in the code I just want a bot that really good and passed funded accounts if that’s possible anyway thanks for replying❤️

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

    Splendid video, how could someone use that for unknown data?
    I don't really want to use it for live trading but i do want to forward test it!

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

      Hi forward testing can be done by saving the trained model and then you feed live features to the model which provides forecast. But if you are not familiar with python and ML it might take longer than expected.

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

      @@CodeTradingCafe Yes i was wondering how i could actually feed it live features, i made my own edit of your model which is pretty decent

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

      @@CodeTradingCafe I'm using an edit that uses GRU instead of LSTM and i tweaked the hyper parameters a little, but i can't really find a way to have it provide forecast for live stocks. Normally i'm good at this stuff 🥲

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

      @@CodeTradingCafe Also i was wondering if it would be smart to have a sort of "ultimate" forecast algorithm that uses a lot of different methods, neural networks or simple algorithms and use the (maybe weighted) average of the predictions as the forecast 🤣

    • @CodeTradingCafe
      @CodeTradingCafe  Год назад +2

      It might be an approach to have an ensemble method, but it might be time consuming to build such a tool, and sometimes a box of troubles you're opening 😂

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

    Forget predicting exact price, why not just make it follow the trend and learn when to buy or sell. Trading is not about predicting price but rather making profits from the ongoing moves or am I wrong?

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

      I am preparing something to predict the trend, I am not saying it's working though 😂

  • @QinZhang-xd7cu
    @QinZhang-xd7cu Год назад

    how to transform back to data got scaled before?

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

      Hi, you can use the function inverse_transform from your scaling model to get back to original values. Good luck!

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

    Rtx 2070 подходит для lstm ?

  • @zakkyang6476
    @zakkyang6476 8 месяцев назад +1

    scaler should be applied only on trained otherwise will lead to data leakage

    • @CodeTradingCafe
      @CodeTradingCafe  8 месяцев назад

      Theoretically scaler can be applied to both train and validation because if the model is trained on scaled data it will only work with scaled data. But I agree that to avoid data leakage scaling should be done independently on training and validation sets.

    • @kirwakelvinkering3122
      @kirwakelvinkering3122 6 месяцев назад

      Hey , how is this even possible ?

  • @Hakman1
    @Hakman1 2 месяца назад

    Anyone know how to scale the predicted values back up?

    • @CodeTradingCafe
      @CodeTradingCafe  2 месяца назад +1

      You need to use inverse_transform function: scaler.inverse_transform(predictions_scaled)

    • @Hakman1
      @Hakman1 2 месяца назад

      @@CodeTradingCafe thank you

  • @connectrRomania
    @connectrRomania Год назад +3

    Predicting the closing is nearly impossible cuz its affected by multiple factors, moreover a good causality and correlation analysis will help improving the predicting model performance

    • @CodeTradingCafe
      @CodeTradingCafe  Год назад +2

      Hi it's been a while... I agree completely it's impossible not even with the best data parameters at hand, next video might show it clearly.

  • @nikhilsuryewal9266
    @nikhilsuryewal9266 3 месяца назад +1

    cannot access the code
    could you please send the link again?

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

    where will i get dataset for this code

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

      Hi I usually use 2 sources yfinance and dukascopy both provide free data

  • @ThuyNguyen-ny3uo
    @ThuyNguyen-ny3uo Год назад +1

    Hi. I have error at this line
    lstm_input = Input(shape=(backcandles, 8), name='lstm_input')
    The error is:
    TypeError: descriptor '_values' for 'BaseContainer' objects doesn't apply to a 'RepeatedCompositeFieldContainer' object
    Can you kindly check and advise?
    Thank you.

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

      Hi, please make sure you ran the previous cells correctly to prepare the data.

    • @ThuyNguyen-ny3uo
      @ThuyNguyen-ny3uo Год назад +1

      @@CodeTradingCafe Thanks. it works now.

  • @gamingwithvillain1731
    @gamingwithvillain1731 2 месяца назад

    Why didn't you used closed price for input

    • @CodeTradingCafe
      @CodeTradingCafe  2 месяца назад

      Hi, closing price wouldn't help at all, in Machine Learning you need relative values instead of absolute prices, so the model picks up the trend.

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

    In my opinion, your model needs regularization and cross validation. Seems highly overfitted to me. Some prunning maybe will work fine, bias & variance balance needs to be applied to.

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

      Hi thanks a lot for your input, I think your are right regarding regularisation it's crucial, but I was expecting at least a small signal in the predictions which I haven't been able to get maybe I will revisit taking into account your comment. (If I remember correctly in a later video I did include some regularisation but with no major improvement, however I never did a full cross validation).

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

      @@CodeTradingCafe I think your model needs to decrease a bit in complexity in order to avoid overlearning the training data. A consequence of that could be not being able to predict unseen data due to overlearning on the training set mentioned above.
      I will probably try it with a much simpler polynomial regression(grade=3 maybe? If you actually plot it, you can see it has some similarities with the sigmoidal function you use in your RNN) and test my results, trying to find the best balance between the accuracy on the training data (I think you can check with .score()) while maintaining a healthy MAE ((mean_absolute_error(y_test,y_pred)).
      If polynomial regresion doesnt work as expected then try to reduce complexity on your RNN (I don´t know exactly how, I will probably have to study it).
      Sorry for my poor English. I am not native. I hope this helps.
      Best,

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

      Hi thank you, overfitting can be avoided by pruning some of the knots and we can also use less variables and layers, but I believe it is much more complex than this, neural networks are good in some cases but they perform very poorly in others (NN work will for CV for example).

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

      I have done the same thing regularlization and cross validation and i get similiar results

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

      Thank you for your feedback, yes I think it's kind of expected.

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

    Why should we used closed - open as target instead of using the close price directly

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

      Hi, because absolute values don't mean anything for the algorithm. Think about it this way if I tell you the price is 1$ could you guess the next price? or if I tell you the price difference is +0.5$ in this case you could guess the price is going up and you are more likely to guess the next price.

  • @AmarjeetSingh-sf6fs
    @AmarjeetSingh-sf6fs 7 месяцев назад +1

    No module named 'pandas_ta'

    • @CodeTradingCafe
      @CodeTradingCafe  6 месяцев назад

      Hi you need to install it, try in your notebook "!pip install pandas_ta"

    • @AmarjeetSingh-sf6fs
      @AmarjeetSingh-sf6fs 6 месяцев назад +1

      @@CodeTradingCafe Thanks

  • @alexCh-ln2gw
    @alexCh-ln2gw 9 месяцев назад

    All this is fine until a company/news event announces mid day that they have really great/bad news and your algo never trained on this sort of event because you're using historical prices that don't account for this as a feature. This happens all the time with anything that gets traded. Some new event happens and the price discontinuously jumps/falls to some new level that wipes out your account . I've never seen any machine learning prediction model take account of black swan events. Disingenuous.

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

      And if I may ask, since you seem very knowledgeable in this matter, how often big news happen? and why big news should wipe your account if your strategy is locked in a low risk trade management system? please enlighten my disingenuous understanding.

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

    Time series must not be shuffled

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

      Hi thank you, I don't think I shuffled I usually split in order, I will reverify

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

      @@CodeTradingCafe no need to check, my fault. The fit function generates batches that can be shuffled and, in theory, should preserve the sequential order of the TS in each batch. Anyway, thanks for the quality content.

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

      @@kadourkadouri3505 ah ok, thank you for the feedback.

  • @VadimChes
    @VadimChes 2 месяца назад

    why to use these moving averages and other lagging indicators.... It looks you just get the same lagging indicators implemented by neural network... And it's not logical to use min max scaler when future prices can be and will be out of the training range sooner or later...

    • @CodeTradingCafe
      @CodeTradingCafe  2 месяца назад

      I agree for the scaler unless we're just doing a test to see if it works, definitely we can't deploy the same model.

  • @TheSturgoenfish
    @TheSturgoenfish 28 дней назад +1

    I think that you are a little off. the last column shouldn’t be included.

    • @CodeTradingCafe
      @CodeTradingCafe  28 дней назад

      Hi, the last column, did you mean the future price value? it has to be there it's our target for the model.

  • @sdfgmksdg
    @sdfgmksdg 2 месяца назад +1

    Przewidywania są stale opóźnione. Model obrał najlepszą strategię w postaci podążania za trendem, stąd podobieństwo wykresów porównujących przewidywania i wartości prawdziwe - zwyczajnie model przewiduje wartość wejściową z wejściowej, czyli przewiduje, ze cena przyszła będzie taka sama jak obecna. Dlaczego? Niech sobie każdy sam odpowie. A idioci łykają to jak pelikany. Jeszcze jak widać nie było wysypu milionerów.

    • @CodeTradingCafe
      @CodeTradingCafe  2 месяца назад

      Hi, thank you, actually this is discussed in detail in the next video, showing why it doesn't work: ruclips.net/video/lhrCz6t7rmQ/видео.html

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

    It's not a prediction, it's only a lag.

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

    this is awful. when happen rise or fall, this will predict price

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

      No it doesn't, wait for next video couple of days... It's an excellent way to show what works and why it doesn't

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

      @@CodeTradingCafe my english is not well. tnx i waiting for it

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

      No problem, I hope you will enjoy coding on this channel. Good luck!

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

    Great video. THANK YOU!

  • @britox.6216
    @britox.6216 Год назад +2

    for anyone receiving error: module 'keras.optimizers' has no attribute 'Adam'
    solution: keras.optimizers.Adam()

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

      Thank you I guess it depends on the libraries version

    • @britox.6216
      @britox.6216 Год назад +1

      @@CodeTradingCafe of course no problem