Skip to content

beingprince/StockPricePredictor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

📈 Stock Price Trend Predictor Hey there! 👋 This little side project is something I threw together to experiment with stock prices and neural networks. It’s a fun dive into using machine learning—specifically PyTorch—to predict whether a stock’s price is likely to go up or down based on its past few days of performance.

⚠️ Disclaimer: This won’t make you rich (I wish it did 😅), but it’s a neat way to see how neural networks handle something as tricky as stock trends.

💡 What This Project Does For each stock in a predefined list (currently Apple (AAPL), Tesla (TSLA), Microsoft (MSFT), and Nvidia (NVDA)), it:

Takes the last 5 days of closing prices

Predicts whether the next day’s price will go up (1) or down (0)

Trains a fresh model for each stock

🚀 How to Run It Install Python Make sure you have Python 3.8 or newer installed.

Install Dependencies Run this command: pip install torch pandas yfinance numpy scikit-learn Clone the Repo: git clone https://github.com/yourusername/StockPricePredictor.git cd StockPricePredictor Run the Script python stock_predictor.py 📊 What You'll See For each stock, the program will: Print how many “up” days were in the training data Show the training loss every few epochs Output the test accuracy after training

Example Output: Working on AAPL... Up days in training for AAPL: 0.52 AAPL - Epoch [40/200], Loss: 0.6890 AAPL - Epoch [200/200], Loss: 0.6765 AAPL - Test Accuracy: 55.12%

🧠 Under the Hood Here’s a breakdown of what’s happening behind the scenes: Data Source: Uses yfinance to pull daily closing prices from 2023-01-01 to 2025-04-01

Data Processing: Prices are normalized between 0 and 1 Creates 5-day chunks to use as input Labels each chunk as 1 (if day 6 > day 5) or 0 (otherwise) Train-Test Split: 80% for training 20% for testing

Neural Network Architecture: Input Layer: 5 neurons Hidden Layers: Two layers, 16 neurons each, ReLU activation Output Layer: 1 neuron, Sigmoid activation (binary classification)

Training: 200 epochs Optimizer: Adam (lr = 0.001) Loss Function: Binary Cross Entropy

Prediction: If the output > 0.5 → Predict "Up" Else → Predict "Down" Compares predictions to actual movements and calculates accuracy

🧪 The Algorithm in Plain English Get the stock's closing prices for the past two years. Normalize those prices. For each set of 5 consecutive days: Predict whether the next day will go up or down. Train a neural network using these labeled samples. Test the model on unseen data to measure how well it predicts.

✅ What Works Well Very simple and easy to understand Can be run on multiple stocks at once Usually performs slightly better than guessing

⚠️ What Needs Work Only uses closing prices (no volume, news, etc.) Accuracy tends to hover around 50–60% Doesn’t handle market volatility well

🔐 License This project is licensed under the MIT License, so feel free to fork, tweak, or use it however you like! (Check the LICENSE file in the repo for the fine print.)

📬 Contact If you hit any snags or just wanna chat about machine learning and stocks, shoot me an email at p.pdsn7@gmail.com. Always happy to help (or at least try)!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages