A full-stack machine learning application that predicts next-day stock price movements using a Random Forest classifier.
- 🤖 Machine Learning: Random Forest model with 51.88% test accuracy
- 🔮 Stock Predictions: Predicts UP/DOWN movement for next trading day
- 📊 Technical Analysis: Uses 30+ technical indicators (RSI, MACD, Bollinger Bands, etc.)
- 📈 Interactive Charts: 3-month historical price visualization
- 🌐 REST API: Flask backend with comprehensive endpoints
- ⚛️ Modern UI: React frontend with Tailwind CSS
- 🚀 Production Ready: Configured for Railway (backend) and Vercel (frontend)
- Python 3.11
- Flask - REST API framework
- scikit-learn - Machine learning (Random Forest)
- yfinance - Real-time stock data
- pandas/numpy - Data processing
- gunicorn - Production server
- React 19 - UI framework
- Tailwind CSS - Styling
- Recharts - Data visualization
- Axios - API client
- Lucide React - Icons
stocky/
├── backend/
│ ├── app.py # Flask API server
│ ├── train_model.py # Model training script
│ ├── predict.py # Prediction logic
│ ├── feature_engineering.py # Technical indicators (30 features)
│ ├── data_fetcher.py # Stock data downloader
│ ├── models/
│ │ └── spy_model.pkl # Trained model
│ ├── requirements.txt # Python dependencies
│ ├── Procfile # Railway deployment config
│ └── runtime.txt # Python version
├── frontend/
│ ├── src/
│ │ ├── App.js # Main React component
│ │ ├── index.js # React entry point
│ │ └── index.css # Tailwind styles
│ ├── public/
│ ├── package.json # Node dependencies
│ ├── vercel.json # Vercel deployment config
│ └── .env.example # Environment variable template
├── DEPLOYMENT.md # Comprehensive deployment guide
├── RAILWAY_DEPLOY.md # Quick Railway guide
└── VERCEL_DEPLOY.md # Quick Vercel guide
- Python 3.11+
- Node.js 16+
- Git
git clone https://github.com/YOUR_USERNAME/stock-predictor.git
cd stock-predictorcd backend
# Create virtual environment
python -m venv venv
# Activate virtual environment
# Windows:
venv\Scripts\activate
# Mac/Linux:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Train the model (optional - model is already included)
python train_model.py
# Run the server
python app.pyBackend will run at http://localhost:5000
cd frontend
# Install dependencies
npm install
# Start development server
npm startFrontend will open at http://localhost:3000
GET /api/health- Health checkGET /api/model/info- Model informationGET /api/assets- Supported assets
GET /api/predict/<symbol>- Get prediction for symbolGET /api/historical/<symbol>?period=1y&interval=1d- Historical dataGET /api/info/<symbol>- Stock informationPOST /api/predict/batch- Batch predictions
curl http://localhost:5000/api/predict/SPY{
"success": true,
"symbol": "SPY",
"prediction": "UP",
"confidence": 52.3,
"current_price": 450.25,
"probabilities": {
"up": 52.3,
"down": 47.7
},
"timestamp": "2025-10-09T..."
}- Price-based: Returns, gaps, streaks
- Moving Averages: SMA_5, SMA_20, SMA_50, EMA_12, EMA_26
- Volatility: ATR, Bollinger Bands position
- Momentum: RSI, MACD, Stochastic, Williams %R, ROC
- Volume: OBV, MFI (Money Flow Index)
- Trend: CCI, DI_Diff (directional indicators)
- Test Accuracy: 51.88%
- Cross-Validation: 46.9% (5-fold)
- Model: Random Forest (300 estimators, balanced weights)
- Training Data: SPY (2,708 days)
Stock prediction is extremely difficult. Even 52% is better than random (50%) and can be profitable with proper risk management. This is for educational purposes only!
See detailed guides:
- DEPLOYMENT.md - Complete deployment guide
- RAILWAY_DEPLOY.md - Backend deployment (Railway)
- VERCEL_DEPLOY.md - Frontend deployment (Vercel)
-
Backend (Railway)
- Push to GitHub
- Connect Railway to your repo
- Set root directory:
backend - Generate domain
- Get backend URL
-
Frontend (Vercel)
- Connect Vercel to your repo
- Set root directory:
frontend - Add env var:
REACT_APP_API_URL=https://your-backend.railway.app/api - Deploy
- Get frontend URL
Both platforms offer free tiers and auto-deploy on Git push!
PORT- Auto-set by RailwayFLASK_ENV=production- Optional
REACT_APP_API_URL- Backend API URL (required)
Example:
REACT_APP_API_URL=https://stock-api.up.railway.app/api
cd backend
python test_api.py# Health check
curl http://localhost:5000/api/health
# Get prediction
curl http://localhost:5000/api/predict/SPY
# Historical data
curl http://localhost:5000/api/historical/AAPL?period=1mo- Stock symbol search
- Prediction display (UP/DOWN with confidence)
- Current price and probabilities
- Stock information
- 3-month price history
- Interactive line chart
- Clean, modern design
The model is trained on SPY but can predict any stock:
- ETFs: SPY, VOO, QQQ, IWF, SCHD
- Stocks: AAPL, MSFT, GOOGL, TSLA, etc.
- Commodities: GLD, SLV
- Crypto: BTC-USD, ETH-USD
- Not financial advice - Do not invest real money based on these predictions
- 52% accuracy - Only slightly better than random chance
- Past performance ≠ future results - Markets are unpredictable
- No guarantee - Model can be wrong, especially during volatile periods
- Use at your own risk - Always do your own research
Want better predictions? Try:
- More data: Train on 10+ years instead of ~5 years
- More features: Add sentiment analysis, economic indicators
- Better algorithms: Try LSTM, XGBoost, ensemble methods
- Feature selection: Remove low-importance features
- Hyperparameter tuning: Use GridSearchCV
- More assets: Train separate models per stock
- Different targets: Predict price ranges instead of binary UP/DOWN
Contributions welcome! Feel free to:
- Report bugs
- Suggest features
- Improve the model
- Add new technical indicators
- Enhance the UI
MIT License - feel free to use for learning and personal projects!
- yfinance - Free stock data
- scikit-learn - Machine learning library
- Create React App - React setup
- Tailwind CSS - Styling framework
- Recharts - Charting library
For issues or questions:
- Check DEPLOYMENT.md for deployment help
- Review API documentation in backend/API_GUIDE.md
- Check browser console for frontend errors
- Review Railway/Vercel logs for backend errors
After deployment:
- ✅ Share your app with friends
- ✅ Add more features (watchlists, alerts)
- ✅ Improve the model accuracy
- ✅ Add user authentication
- ✅ Set up custom domain
- ✅ Add more technical indicators
- ✅ Train on more stocks
Built with ❤️ using Python, React, and Machine Learning
Happy Predicting! 📈🚀