Skip to content

A full-stack stock prediction platform combining Next.js frontend with Python FastAPI backend. Features PyTorch LSTM neural networks for price forecasting, Alpha Vantage API integration, and interactive data visualization.

Notifications You must be signed in to change notification settings

AnikMajumdar/stockPredictorDeployment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ˆ Stock Market Predictor

A full-stack stock prediction platform combining Next.js frontend with Python FastAPI backend. Features PyTorch LSTM neural networks for price forecasting, Alpha Vantage API integration, and interactive data visualization.

πŸš€ Quick Start

Prerequisites

  • Node.js 18.0 or higher
  • Python 3.8 or higher
  • pip package manager
  • Modern web browser

Installation & Setup

```bash

1. Install all dependencies (frontend + backend)

npm run setup

2. Set environment variables

Create a .env.local file with:

NEXT_PUBLIC_API_URL=http://localhost:8000

ALPHA_VANTAGE_API_KEY=your_alpha_vantage_api_key

=======

Create a .env.local file in the root directory with:

NEXT_PUBLIC_API_URL=http://localhost:8000

ALPHA_VANTAGE_API_KEY=your_api_key_here

2. Set environment variables

Create a .env.local file in the root directory with:

NEXT_PUBLIC_API_URL=http://localhost:8000

ALPHA_VANTAGE_API_KEY=your_api_key_here

3. Run both frontend and backend

npm run dev:full ```

Alternative Manual Setup: ```bash

Install frontend dependencies

npm install

Install Python backend dependencies

cd backend pip install -r requirements.txt cd ..

Run both servers

npm run dev:full ```

Troubleshooting

If you get "'concurrently' is not recognized" error: ```bash

Delete node_modules and reinstall

rm -rf node_modules package-lock.json npm install npm run dev:full ```

If you get "Missing script" errors:

  • Make sure you're in the root directory (not in /backend)
  • Run npm install first to install concurrently

If PyTorch installation fails:

  • The requirements.txt uses PyTorch 2.7.1 (latest compatible version)
  • For older systems, you may need to install PyTorch separately: pip install torch torchvision

If backend connection fails:

  • The frontend works without the backend (shows fallback data)
  • To use real ML predictions, ensure both servers are running
  • Check that NEXT_PUBLIC_API_URL=http://localhost:8000 is set
  • Verify that ALPHA_VANTAGE_API_KEY is set with a valid API key
  • Verify that ALPHA_VANTAGE_API_KEY is set with a valid API key

πŸ“Š Features

πŸ” Stock Viewer

  • Interactive price and volume charts

  • Popular stocks quick access

  • Real-time data from Alpha Vantage (API key required) =======

  • Real-time data from Alpha Vantage API

  • Technical indicators and pattern analysis

  • Real-time data from Alpha Vantage API

  • Technical indicators and pattern analysis

πŸ€– AI Prediction Engine

  • Real PyTorch LSTM models (not simulations)
  • Multiple architectures: LSTM, GRU, Transformer
  • Live model training with progress tracking
  • Performance metrics: RMSE, MAE, directional accuracy

🧠 Model Training Interface

  • Interactive hyperparameter tuning
  • Real-time training visualization
  • Model comparison and persistence

πŸ—οΈ Architecture

Hybrid Stack:

  • Frontend: Next.js + React + TypeScript

  • Backend: FastAPI + PyTorch + Python

  • Data: Alpha Vantage (API key required) =======

  • Data: Alpha Vantage API (requires API key)

  • Data: Alpha Vantage API (requires API key)

  • ML: Real neural networks with GPU support

  • Deployment: Docker-ready with environment variable configuration

  • Deployment: Docker-ready with environment variable configuration

Project Structure: ``` β”œβ”€β”€ app/ # Next.js frontend application β”œβ”€β”€ app/ # Next.js frontend application β”‚ β”œβ”€β”€ components/ # React components β”‚ β”œβ”€β”€ lib/ # API client and utilities β”‚ └── styles/ # CSS and styling β”‚ β”œβ”€β”€ lib/ # API client and utilities β”‚ └── styles/ # CSS and styling β”œβ”€β”€ backend/ β”‚ β”œβ”€β”€ models/ # PyTorch LSTM models β”‚ β”œβ”€β”€ data/ # Data fetching & preprocessing β”‚ β”‚ └── alpha_vantage_fetcher.py # Alpha Vantage API integration β”‚ β”œβ”€β”€ main.py # FastAPI application β”‚ β”‚ └── alpha_vantage_fetcher.py # Alpha Vantage API integration β”‚ β”œβ”€β”€ main.py # FastAPI application β”‚ └── utils/ # Training & model management β”œβ”€β”€ .env.local # Environment variables └── docker-compose.yml # Docker configuration β”œβ”€β”€ .env.local # Environment variables └── docker-compose.yml # Docker configuration ```

🎯 Model Performance

Accuracy Benchmarks:

  • Large Cap Stocks: 65-75% directional accuracy
  • RMSE: $3-8 for major stocks (AAPL, MSFT)
  • Best Performance: 1-7 day predictions
  • Limitations: Cannot predict news events or market crashes

Performance by Time Horizon:

  • 1-3 days: 70-75% accuracy
  • 1 week: 60-70% accuracy
  • 1 month: 50-60% accuracy
  • 3+ months: Approaches random (not recommended)

πŸš€ Available Scripts

```bash

Development

npm run dev # Frontend only npm run dev:full # Both frontend + backend npm run setup # Install all dependencies

Backend specific

npm run backend:start # Start Python API server npm run backend:install # Install Python dependencies

Production

npm run build # Build frontend npm start # Start production server ```

πŸ”§ Configuration

Environment Variables:

Model Parameters:

  • Hidden Size: 16-256 (default: 64)
  • Layers: 1-6 (default: 2)
  • Learning Rate: 0.0001-0.01 (default: 0.001)
  • Sequence Length: 10-60 days (default: 30)

πŸš€ Deployment

Recommended: Vercel + Railway ```bash

Frontend to Vercel

vercel deploy

Backend to Railway

railway login && railway deploy ```

Docker Option: ```bash docker-compose up --build ```

⚠️ Important Notes

Data Source: Uses Alpha Vantage (API key required via ALPHA_VANTAGE_API_KEY)

Data Source: Uses Alpha Vantage API (requires free API key) Data Source: Uses Alpha Vantage API (requires free API key)

  • Free tier has limitations on request frequency (5 calls per minute, 500 per day)
  • Consider upgrading to a paid plan for production use

Model Limitations:

  • Cannot predict black swan events, earnings surprises, or news impacts
  • Accuracy decreases significantly for predictions beyond 30 days
  • Best used for short-term trend analysis, not investment decisions
  • Model performance depends on quality and quantity of training data
  • Model performance depends on quality and quantity of training data

Disclaimer: For educational purposes only. Not financial advice.

πŸ“„ License

MIT License - see LICENSE file.


Tech Stack: Next.js β€’ FastAPI β€’ PyTorch β€’ Alpha Vantage β€’ TypeScript β€’ Python Tech Stack: Next.js β€’ FastAPI β€’ PyTorch β€’ Alpha Vantage β€’ TypeScript β€’ Python

About

A full-stack stock prediction platform combining Next.js frontend with Python FastAPI backend. Features PyTorch LSTM neural networks for price forecasting, Alpha Vantage API integration, and interactive data visualization.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published