free web page hit counter
๐Ÿ›ก๏ธ
Copyright Notice: This video is officially sourced and embedded from YouTube. For all copyright inquiries, reports, or removals, please contact YouTube's legal team here.
NeuralNine

NeuralNine

476,000 subscribers

โฑ ๐Ÿ‘ 38,702 views

Stock Price Prediction in Python with PyTorch - Full Tutorial

Video Overview & Insights

In this video we will learn how to do stock price prediction in Python with PyTorch using an LSTM-based architecture.

Did you make the video with the indicators? I would like to see it.

โ€” @Doug091549

DISCLAIMER: None of this is financial advice. This is purely a programming tutorial and I am not responsible for any financial decisions you make. Don't use this for actually trying to predict stock prices.

โ—พโ—พโ—พโ—พโ—พโ—พโ—พโ—พโ—พโ—พโ—พโ—พโ—พโ—พโ—พโ—พโ—พ

@NeuralNine Iโ€™m having a hard time understanding yfinance and how live data connection works. Is there a delay? Can ML be applied to faster intraday assets like futures ES1! For shorter predictions next 15 mins or hour?

โ€” @sketchykindaguy8204

๐Ÿ“š Programming Books & Merch ๐Ÿ“š

๐Ÿ The Python Bible Book: https://www.neuralnine.com/books/

Homebrew has no - -cask called YFinance to be install only binance which is a cryptocurrency trading app. ๐Ÿ˜ฎ that is because it doesnโ€™t exist in home brewed.

โ€” @marlonb2035

๐Ÿ’ป The Algorithm Bible Book: https://www.neuralnine.com/books/

๐Ÿ‘• Programming Merch: https://www.neuralnine.com/shop

Thank you.

โ€” @shwe7211

๐Ÿ’ผ Services ๐Ÿ’ผ

๐Ÿ’ป Freelancing & Tutoring: https://www.neuralnine.com/services

isn't the standard scaler fit on entire data cause data leakage, as we are using the mean and std of the entire data which is technically not available to us so we shouldn't use it, when testing for out of sample performance we are bound to get a little better results than we'd get in the real world here

โ€” @unmol.e

๐Ÿ–ฅ๏ธ Setup & Gear ๐Ÿ–ฅ๏ธ: https://neuralnine.com/extras/

๐ŸŒ Social Media & Contact ๐ŸŒ

bring some real deal, go deep dude. with all those indicators and some features that does make a difference. different targets

โ€” @Lotfan-e5t

๐Ÿ“ฑ Website: https://www.neuralnine.com/

๐Ÿ“ท Instagram: https://www.instagram.com/neuralnine

Has anyone tried this on renko charts to get rid of the noise?

โ€” @rhybez1

๐Ÿฆ Twitter: https://twitter.com/neuralnine

๐Ÿคต LinkedIn: https://www.linkedin.com/company/neuralnine/

where is the code of this video??

โ€” @kahkashabano5983

๐Ÿ“ GitHub: https://github.com/NeuralNine

๐ŸŽ™ Discord: https://discord.gg/JU4xr8U3dm

thanks for this bro

โ€” @kaluzaq

More User Perspectives

@

please provide LSTM explanation too in detail !

@aamirabbas6289
@

I sent your code to ChatGPT for explanation, and it flagged some issues:

Problems in this code

1. Scaler input shape

StandardScaler.fit_transform expects 2D. You passed a 1D Series.

โœ… Use:

df['Close'] = scaler.fit_transform(df[['Close']])

or df['Close'].to_frame().

Data leakage

You fit the scaler on all data before the train/test split. For time series, that leaks future info.

โœ… Fit the scaler on the training portion only, then transform both train and test with that fitted scaler.

Window array shape

data = np.array(data) after appending Series gives a 2D array (n_windows, 30) โ€” no feature dimension.

But later you index ...,:-1,: which assumes 3D (batch, seq_len, features).

โœ… Build windows as (seq_len, 1):

data = np.array([seq.values.reshape(-1, 1) for seq in data])

Tensor dtypes & device

torch.from_numpy will give float64 for floats; PyTorch layers expect float32.

And you never move tensors to device.

โœ… Cast and move:

X_train = torch.from_numpy(...).float().to(device)
y_train = torch.from_numpy(...).float().to(device)

Constructor typos

__init__(self,input_dim,hidden_dime,num_layers,output_dim) but inside you assign self.hidden_dim = hidden_dim โ€” mismatch (hidden_dime vs hidden_dim).

โœ… Make the arg name consistent.

What exactly youโ€™re predicting

Your window of length 30 is split into:

X: first 29 steps

y: the 30th step within the same window
Thatโ€™s fine (predict โ€œnext step inside windowโ€), but often for forecasting we prefer predict the next step after the window (i.e., use a 30-step input to predict step 31). Your current code is okay conceptually for a simple setup, just be clear on intent.

@becksafarov
@

Truly one of the best. Just followed through step by step and coded using VS Code and MT5 XAUUSD Forex data. Any minor problems were 'typos' and using ChatGBT helped resolve very quickly. Printed the graphs to file. Still trying to figure out how to understand & use the information to improve MT5 (EA) trading. Excellent video - many thanks.
Been working with MT5 but this is my first venture with Python, VS Code and NNs / AI -so taken me from ZERO to much further than I could have 'predicted'

@peterwlliams1394
@

Thank you for the very good tutorial on how to use LSTM for predicting time series!

@kancukatattva6570
@

Very useful, does someone know how to implement LSTM faster for a trading algo?? im having a hard time implementing model to test them out in papper money

@tripastian9554
@

Would love to see a model trained on multiple indicators to predict sequences of values, maybe even a markov chain

@jiufu
@

20:31 Would love more discussion here to get a better grasp over the dimension of the matrices.

@aurkom
@

Thanks a lot! Very useful and informative.
Nice topic, so please go ahead and make more like that :)

@dmytrokozubenko6913
@

LSTM hell yeah!!! What i NEEDED from you. Chhers mate!!!

@lekhazadapa36
@

๐Ÿ‘‹ I truly appreciate the quality content you bring to this platform. I have a humble request โ€” could you please make a video on 'WorldQuant BRAIN'? It's a fascinating platform for financial data modeling and crowd-sourced alpha research, but thereโ€™s very little quality information available on YouTube. Your detailed explanations would help so many of us who are curious about finance, quantitative research, and how BRAIN actually works in real life. Hope you consider it! ๐Ÿ™ Thanks for everything you do!"

@machapraveen7737
@

Thanks

@kitzesplana5457
@

you must use forward sliding window , move forward x price tics every epoch , also plot the real price , predicted price and train eval price plot , you need prevent overfiting , use at least 64 layer 3 deep , i can give you the code to play ,is just an advance moving average , you can predict only if you normal distribute a range of prices ....

@johnstream9172
@

If anyone serious about stock price prediction, then you should first learn Econometrics before Deep Learning. People want to jump directly to Deep Learning. There is no shortcut.

@sinan_islam
@

Thanks a lot bro this is very helpful to us developers ๐Ÿ”ฅ๐Ÿ’ฏโœ…๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ This demonstrate the power of python, market and matchine learning...is the feature. Definitely waiting for more content like this โค

@FHULUFHELONORMANMAMUSHIA-ng1up
@

Can you guys stop making these ridiculous stock price prediction videos? You CANNOT predict stock prices and you CANNOT predict asset returns. You are simply overfitting a model and will not be able to generate any profit whatsoever with this stuff.

@JuliusKaesar
@

this is really good class!

@f_gun20
@

Thanksโค

@andrew-ld1jg
@

Thanks ๐ŸŽ‰โค

@tiwariji9985
@

First pin pls

@ScratchersTech
@

Thanks ๐ŸŽ‰

@andiglazkov4915