Skip to content

SiD-array/StockView

Repository files navigation

πŸ“ˆ StockView

StockView is a desktop web application for real-time stock market analysis. It combines interactive data visualization, anomaly detection, news sentiment insights, and machine learning–based price predictions into a single dashboard.

πŸš€ Live Deployment:

  • Frontend (Vercel) β†’ View App
  • Backend (Render) β†’ See DEPLOYMENT_COMPLETE_GUIDE.md for deployment instructions

✨ Features

  • Real-time Stock Data β†’ Current price, open, high, low, and volume.

  • Interactive Charts β†’ Zoom/pan with SMA, anomaly highlights, and prediction overlays.

  • Technical Indicators β†’ SMA, RSI, MACD, Bollinger Bands, ATR, and more.

  • Anomaly Detection β†’ Detects unusual price movements via Z-score.

  • Machine Learning Predictions β†’

    • Algorithms: Linear Regression, Random Forest, XGBoost, LightGBM, CNN.
    • Metrics: RΒ², MAE, RMSE, MAPE.
    • Algorithm comparison dashboard.
    • Model evaluation framework β†’ Chronological backtesting across multiple symbols with automated reports and charts.
  • News & Sentiment Analysis β†’ Headlines with Positive/Neutral/Negative labels and sentiment charts.

  • Watchlist β†’ Add/remove stock symbols, synced with Firebase.


πŸ—οΈ Tech Stack

Frontend (React + Vite)

  • React + Hooks for state management
  • Recharts for interactive visualization
  • TailwindCSS for UI styling
  • Firebase (Cloud Firestore) for watchlist persistence

Backend (FastAPI)

  • FastAPI for REST API
  • Yahoo Finance (yfinance) for stock data
  • VADER Sentiment Analyzer for news sentiment
  • ML Models: scikit-learn, XGBoost, LightGBM, TensorFlow (CNN)
  • Technical indicators with ta library
  • Matplotlib for evaluation visualizations

πŸ“Š Model Evaluation Framework

StockView includes a reproducible backtesting pipeline in backend/evaluation.py that benchmarks all five forecasting models on historical data.

What it does

  • Downloads OHLCV data via yfinance (same pipeline as the live API)
  • Applies chronological 80/20 train/test split (no random shuffling β€” avoids look-ahead bias)
  • Reuses shared modules (features.py, models/training.py) used by the live API
  • Computes MAE, RMSE, MAPE, and RΒ² on the held-out test set
  • Exports results to CSV, a summary report, and comparison charts

Models evaluated

Model Description
Linear Regression Time-index trend baseline
Random Forest Ensemble on 21 engineered features
XGBoost Gradient boosting on engineered features
LightGBM Light gradient boosting on engineered features
CNN 1D convolutional network on raw Close price sequences

Benchmark results (5 symbols, 1y daily data)

Evaluated on AAPL, MSFT, TSLA, GOOGL, AMZN with an 80/20 chronological split:

Model Avg MAE Avg RMSE Avg MAPE Avg RΒ²
Random Forest $17.60 $20.65 5.13% -1.02
LightGBM $17.49 $20.34 5.17% -1.11
XGBoost $17.68 $20.67 5.21% -1.14
Linear Regression $30.96 $33.64 9.10% -2.93

Per-symbol highlights:

Symbol Best Model MAPE RΒ²
TSLA LightGBM 1.22% 0.92
MSFT LightGBM 2.05% 0.38
AAPL Linear Regression 4.24% 0.35

Full results: evaluation_results.csv Β· Summary: evaluation_report.txt Β· Charts: evaluation_outputs/

Run the evaluation

Requirements: Python 3.11 (see .python-version) and pip install -r backend/requirements.txt. CNN evaluation requires tensorflow-cpu.

cd backend

# Evaluate a single symbol
python -c "from evaluation import evaluate_symbol; evaluate_symbol('AAPL')"

# Evaluate multiple symbols (default: AAPL, MSFT, TSLA, GOOGL, AMZN)
python evaluation.py

Outputs generated at project root:

evaluation_results.csv       # Per-model metrics (CSV)
evaluation_report.txt        # Best/worst models, averages, recommendations
evaluation_outputs/          # Actual vs predicted charts, error & performance comparisons

πŸ“‚ Project Structure

StockView/
│── frontend/
β”‚   β”œβ”€β”€ src/App.jsx           # React app (UI and chart logic)
β”‚   └── ...
β”‚
│── backend/
β”‚   β”œβ”€β”€ main.py               # FastAPI routes
β”‚   β”œβ”€β”€ config.py             # Environment configuration
β”‚   β”œβ”€β”€ features.py           # Technical indicators & feature engineering
β”‚   β”œβ”€β”€ data.py               # yfinance data pipeline with caching
β”‚   β”œβ”€β”€ metrics.py            # Chronological splits & evaluation metrics
β”‚   β”œβ”€β”€ recommendations.py    # Symbol-specific model recommendations
β”‚   β”œβ”€β”€ models/               # Training & multi-step prediction
β”‚   β”œβ”€β”€ evaluation.py         # Offline backtesting framework
β”‚   β”œβ”€β”€ tests/                # pytest unit tests
β”‚   └── requirements.txt
β”‚
│── evaluation_results.csv    # Benchmark metrics (generated by evaluation.py)
│── evaluation_report.txt     # Summary report with recommendations
│── evaluation_outputs/       # Evaluation charts (actual vs predicted, comparisons)
│── README.md

πŸ–ΌοΈ Preview

StockView Dashboard Preview

StockView Predictions and Anomalies

StockView Predictions and Anomalies

StockView Predictions and Anomalies

Replace the placeholder images above with actual screenshots of your app for a better showcase.


πŸš€ Deployment

For complete deployment instructions, see DEPLOYMENT_COMPLETE_GUIDE.md

Quick Overview:

  • Backend: Deploy to Render (see guide for details)
  • Frontend: Deploy to Vercel (see guide for details)
  • Firestore: Configure security rules in Firebase Console

βš™οΈ Local Development

Environment variables

Copy backend/.env.example to backend/.env and set:

Variable Required Description
NEWS_API_KEY Yes (for news) NewsAPI key
CORS_ORIGINS No Comma-separated frontend URLs (default: *)

On Render, set NEWS_API_KEY in the dashboard (see render.yaml).

Backend (FastAPI)

cd backend
pip install -r requirements.txt
uvicorn main:app --reload

Runs at β†’ http://localhost:8000

Frontend (React + Vite)

cd frontend
npm install
npm run dev

Runs at β†’ http://localhost:5173


πŸ–₯️ Usage

  1. Search for a stock symbol (e.g., AAPL, TSLA).
  2. Explore real-time price charts with SMA and anomalies.
  3. Toggle ML predictions and model comparison.
  4. Check news headlines with sentiment analysis.
  5. Save your favorite stocks in the watchlist.

⚠️ Disclaimer

This project is for educational purposes only. Predictions and insights are not financial advice.


πŸ“Œ Notes

  • Optimized for desktop browsers only (not mobile responsive).
  • Requires valid API keys (NEWS_API_KEY for news; Firebase for watchlist).
  • Live ML metrics use chronological 80/20 holdout (out-of-sample).
  • Symbol-specific algorithm recommendations via /evaluation/recommendation.
  • GitHub Actions CI runs backend unit tests on push.
  • Works best on Chrome, Edge, or Firefox.

About

πŸ“ˆ Real-time stock analysis dashboard with ML predictions, anomaly detection, technical indicators & sentiment analysis. Built with React + FastAPI.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors