This project uses Long Short-Term Memory (LSTM) networks to forecast stock prices for multiple tickers. The model is built using historical price data combined with technical indicators such as Simple Moving Average (SMA), Exponential Moving Average (EMA), Relative Strength Index (RSI), and Moving Average Convergence Divergence (MACD). The model's performance is evaluated using metrics like Mean Absolute Error (MAE) and R-squared (R²), and the predictions are visualized for easy comparison with actual values.
The goal of this project is to predict future stock prices for multiple tickers, leveraging advanced machine learning techniques and time series forecasting methods. The LSTM model aims to capture the patterns in stock price data over time and provide actionable insights for financial decision-making.
- Stock Price Prediction: Predicts stock prices for multiple tickers using LSTM.
- Technical Indicators: Incorporates technical indicators like SMA, EMA, RSI, and MACD to enhance the prediction model.
- Data Preprocessing: Includes cleaning, feature engineering, and normalization of data.
- Model Training: LSTM network is trained on historical stock price data to make predictions.
- Visualization: The predicted vs. actual stock prices are visualized with plots, allowing for easy performance comparison.
- Evaluation Metrics: Utilizes MAE and R² to evaluate model accuracy and performance.
- Python
- TensorFlow/Keras for deep learning model implementation.
- pandas, numpy for data manipulation and preprocessing.
- yfinance for fetching historical stock data.
- scikit-learn for data scaling and model evaluation.
- matplotlib and seaborn for data visualization.
- Data Collection: Historical stock data is fetched from Yahoo Finance using the
yfinancelibrary. - Feature Engineering: Technical indicators such as SMA, EMA, RSI, and MACD are calculated and added as features to the dataset.
- Data Preprocessing: The data is scaled using MinMaxScaler, and sequences are created for LSTM input.
- Model Architecture: The LSTM model is built and trained using historical stock price data.
- Evaluation: The model's predictions are evaluated using MAE and R², and its performance is compared to actual stock prices through visualization.
- Visualization: The predictions and actual values are plotted to assess the model's performance.
This project is designed with flexibility in mind.
-
Changing Tickers: Modify the
TICKERSlist in the code to include the stock symbols you want to analyze. Simply replace the existing tickers with your desired ones.
-
Adjusting Forecast Length: You can change the number of days the model predicts by adjusting the
FORECASTvariable.
-
Model Hyperparameters: Adjust the learning rate, number of layers, and units in the LSTM model by changing the relevant parameters in the code. This allows for tuning the model for better performance.

The model outputs the following:
-
Performance Metrics: MAE and R² for each stock ticker.
-
Predicted vs Actual Graphs: Visual comparison between predicted stock prices and actual stock prices for each ticker.
Feel free to fork this repository, open issues, or submit pull requests if you'd like to contribute to this project.
- Fork the repository to your own GitHub account.
- Clone the repository to your local machine.
- Make your changes or improvements.
- Submit a pull request with a description of your changes.
