A machine learning project that predicts Apple Inc. (AAPL) stock prices using a neural network implemented in PyTorch. This project demonstrates time series forecasting for stock market data.
- Fetches real-time Apple stock data using Yahoo Finance
- Implements a deep neural network for price prediction
- Uses historical price data to forecast future stock prices
- Configurable sequence length for time-series analysis
- Training progress visualization
- Python 3.6+
- PyTorch
- pandas
- yfinance
- scikit-learn (for data preprocessing)
-
Clone the repository:
git clone https://github.com/Prime-Lasking/AASP.git cd AASP -
Install the required packages:
pip install -r requirements.txt
Or install them individually:
pip install torch pandas yfinance scikit-learn
-
First, fetch the latest stock data:
python stock.py
This will download the latest Apple stock data and save it as
stock.csv. -
Run the prediction model:
python main.py
The script will train the neural network and output the predicted next closing price.
The neural network consists of:
- Input layer (sequence length)
- 4 Hidden layers (32 neurons each) with ReLU activation
- Output layer (1 neuron for price prediction)
The model is trained using:
- Mean Squared Error (MSE) loss function
- Adam optimizer with a learning rate of 0.01
- 10,000 training epochs
- Sequence length of 20 days for time-series analysis
The model outputs the predicted next day's closing price based on the most recent sequence of closing prices. The prediction is printed at the end of the training process.
main.py: Main script containing the neural network implementation and training loopstock.py: Script to fetch stock data using yfinancestock.csv: CSV file containing historical stock dataREADME.md: This file
Stock market prediction is inherently uncertain and past performance is not indicative of future results. This project is for educational purposes only and should not be used for making investment decisions.
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
- Fork the repository
- Create a new branch for your feature (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Yahoo Finance for providing stock market data
- PyTorch team for the deep learning framework
- Pandas for data manipulation