"# APPL-stock-price-prediction-using-LSTM-with-pytorch"
This project focuses on the development of a Long Short-Term Memory (LSTM) model using PyTorch to predict the closing price of Apple (APPL) stock. The dataset used spans from January 3, 2011, to December 30, 2022. Key Highlights
• Data preprocessing • LSTM model development • Training and evaluation • Results visualization
Data Preprocessing
-
Data Source: Historical APPL stock price data is retrieved from Yahoo Finance using the yfinance library in Python.
-
Data Attributes: • Open, high, low, close, and adjusted close prices • Volume traded for each day
-
Data Split: • Segregation into training set (first 80% of rows) and test set (last 20% of rows)
-
Target Variable: • Closing prices are selected as the target variable for prediction.
-
Normalization: • Closing prices are normalized by dividing them by the opening price on the first day. LSTM Model
-
Architecture: • An LSTM model is constructed using PyTorch. • 1 hidden layer with 50 units. • Dropout applied after the LSTM layer to prevent overfitting.
-
Loss Function: • Mean Squared Error (MSE) is employed as the loss function.
-
Optimization: • Adam optimizer is used for model optimization.
Training
-
Epochs: • The model is trained for 100 epochs.
-
Sequence Input: • Training data is provided in sequences of 60 days to capture trends.
-
Batch Size: • A batch size of 1 is utilized.
-
Model Checkpointing: • Implementation of model checkpointing to save the best model weights.
Evaluation
-
Performance Metric: • Model performance is assessed on the test set using Root Mean Squared Error (RMSE) between predicted and actual closing prices.
-
RMSE Score: • Achieved an RMSE of 0.06 on the test set.
Results
- Prediction Accuracy: • Model predictions closely align with actual movements in APPL stock prices on the test set.
- Potential Improvements: • Consider increasing the number of LSTM units and training for more epochs for potential performance enhancement.
- Project Impact: • Demonstrates the effectiveness of LSTMs in modeling stock price movements. • Provides a PyTorch codebase for developing similar financial forecasting models. Usage Include instructions on how to run the code and reproduce the results. License Specify the license under which your project is distributed. Acknowledgments Give credit to relevant sources or libraries used in the project.