Skip to content

AmoghRG/Stock-Analytics-Platform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ˆ Stock Data Warehouse โ€” "Big Bull"

A full-stack stock market intelligence platform for Indian equities โ€” built with Node.js, MySQL and React.


๐Ÿงญ What Is This?

Stock Data Warehouse is a personal Bloomberg Terminal for Indian stocks. It:

  • ๐Ÿ“ฅ Fetches live data from the IndianAPI (prices, profiles, news)
  • ๐Ÿ—„๏ธ Stores everything locally in a MySQL database (zero repeat API calls after first load)
  • ๐Ÿ“Š Visualises it through a modern dark-theme React dashboard
  • ๐Ÿ” Screens stocks using 15+ financial & technical filters
  • ๐Ÿงฎ Analyses data using advanced SQL โ€” Window Functions, Views, Stored Procedures

๐Ÿ—๏ธ Tech Stack

Layer Technology
Database MySQL 8.0
Backend Node.js 18 + Express
Frontend React 18 (Vite)
Styling Tailwind CSS (utility classes) + Vanilla CSS
External Data IndianAPI
HTTP undici (backend), axios (frontend)

๐Ÿ—ƒ๏ธ Database Schema

7 tables + 1 View + 1 Stored Procedure:

exchanges              โ†’ Stock exchanges (NSE, BSE)
companies              โ†’ 22 tracked Indian stocks + cached profile JSON
stock_prices           โ†’ Daily OHLCV candles (1 year per company)
technical_indicators   โ†’ MA50, MA200, RSI per company per day
market_news            โ†’ News headlines
trades                 โ†’ Buy/sell trade records
corporate_actions      โ†’ Dividends, splits (schema ready)

vw_screener_base       โ†’ VIEW: pre-joins companies + prices + indicators
sp_refresh_technicals  โ†’ PROCEDURE: recalculates MA50/MA200/RSI from raw data

Key Design Decisions

  • profile_data JSON column stores the full IndianAPI response (avoids 50+ extra columns)
  • UNIQUE KEY (company_id, timestamp, span) on stock_prices prevents duplicates
  • BIGINT primary keys for price/indicator tables โ€” they grow fast
  • DECIMAL(10,2) for prices โ€” avoids floating-point rounding errors
  • Indexes on (company_id, timestamp) make time-series queries fast

๐Ÿš€ Getting Started

Prerequisites

  • Node.js v18+
  • MySQL 8.0+ running locally

1 โ€” Database Setup

mysql -u root -p < backend/schema.sql

Or open backend/schema.sql in MySQL Workbench and execute it.

2 โ€” Backend Setup

cd backend
npm install

Copy .env.example to .env and fill in your credentials:

PORT=5000
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=your_mysql_password
DB_NAME=stock_data_warehouse
INDIAN_API_KEY=your_api_key_here

Start the backend:

npm run dev
# Server runs on http://localhost:5000

3 โ€” Run the DB Migration (one-time)

Creates the vw_screener_base View and sp_refresh_technicals Stored Procedure:

node migrations/run_migration.js

4 โ€” Seed Companies (optional but recommended)

Adds 20 Nifty 50 companies with full profile + historical data:

node seed_nifty20.js

โš ๏ธ This makes ~3 API calls per company. Make sure you have sufficient IndianAPI credits.

5 โ€” Frontend Setup

cd frontend
npm install
npm run dev
# Opens on http://localhost:5173

๐Ÿ“ฑ Features & Pages

Dashboard

Home screen โ€” lists all tracked companies with live price and 1-day change.

Company Detail โญ

Full financial deep-dive for a single stock:

  • P/E Ratio, Market Cap, ROE, 52W High/Low โ€” parsed from cached JSON
  • Interactive candlestick price chart (1yr history)
  • MA50, MA200, RSI overlays
  • Analyst buy/hold/sell sentiment
  • Latest news feed

Stock Screener โญ

Filter stocks by 15+ criteria simultaneously:

Category Filters
Price & Volume Min/Max price, Min/Max volume
Returns 1-Day %, 30-Day % change
Fundamentals ROE, Debt/Equity, Net Profit Margin, Revenue Growth 5Y
Size Market Cap range
Momentum Distance from 52W High, Price vs 50DMA
Category Sector
Signals Golden Cross, Death Cross, Volume Spike, Near 52W High/Low

Analytics โ€” Advanced SQL โญ

5 panels powered by distinct SQL techniques:

Panel SQL Feature
Sector Heatmap GROUP BY sector, AVG(), GROUP_CONCAT()
Sector Rankings RANK() OVER (PARTITION BY sector ORDER BY change_pct)
Streak Detector LAG(close_price) OVER (PARTITION BY company_id ORDER BY timestamp)
DB Objects SELECT FROM information_schema.VIEWS / ROUTINES
Refresh Technicals CALL sp_refresh_technicals(company_id)

Research

Market news + price chart exploration across multiple time frames.

Add Company

Add any NSE/BSE-listed stock by ticker. One form submission triggers:

  1. Company record creation (DB)
  2. Full profile cache (IndianAPI โ†’ profile_data column)
  3. 1-year historical prices (โ†’ stock_prices table)
  4. News fetch (โ†’ market_news table)

๐Ÿ”„ Data Flow

Add Company
  โ””โ”€ POST /api/companies           โ†’ creates DB record
  โ””โ”€ POST /api/external/profile    โ†’ fetches + caches JSON blob
  โ””โ”€ POST /api/external/historical โ†’ populates stock_prices + technical_indicators
  โ””โ”€ POST /api/external/news       โ†’ populates market_news

View Company Page
  โ””โ”€ GET /api/companies/:symbol    โ†’ reads from DB (zero API calls)
  โ””โ”€ GET /api/stocks/:id           โ†’ reads stock_prices from DB

Run Screener
  โ””โ”€ GET /api/screener?filters...
       โ”œโ”€ Pre-query: JSON_EXTRACT financials from profile_data
       โ”œโ”€ Main query: filters applied via vw_screener_base
       โ””โ”€ JS merge: ranks computed, results returned

๐Ÿงฎ DBMS Concepts Demonstrated

Concept Where
Normalisation (3NF) 7 tables with foreign keys
Referential Integrity FOREIGN KEY constraints throughout
Indexing idx_stock_time, idx_indicator_time, idx_trade_time
JSON data type profile_data column in companies
Aggregate Functions AVG(), MAX(), MIN(), COUNT(), SUM()
Correlated Subqueries Latest price per company in screener JOINs
Window Functions RANK(), DENSE_RANK(), LAG() in analytics
Database Views vw_screener_base โ€” abstraction over complex JOINs
Stored Procedures sp_refresh_technicals โ€” procedural SQL in DB engine
UPSERT INSERT ... ON DUPLICATE KEY UPDATE
GROUP_CONCAT Best/worst performer per sector in heatmap
information_schema Live inventory of DB objects
Connection Pooling mysql2 pool in config/db.js
Parameterised Queries All queries use ? placeholders (SQL injection safe)

๐Ÿ“ Project Structure

Stock-Data-Warehouse/
โ”œโ”€โ”€ backend/
โ”‚   โ”œโ”€โ”€ server.js                  # Express entry point
โ”‚   โ”œโ”€โ”€ schema.sql                 # Database DDL
โ”‚   โ”œโ”€โ”€ .env                       # Secrets (not in git)
โ”‚   โ”œโ”€โ”€ seed_nifty20.js            # Seeds 20 companies
โ”‚   โ”œโ”€โ”€ config/db.js               # MySQL pool
โ”‚   โ”œโ”€โ”€ middleware/errorHandler.js
โ”‚   โ”œโ”€โ”€ controllers/
โ”‚   โ”‚   โ”œโ”€โ”€ companyController.js   # CRUD for companies table
โ”‚   โ”‚   โ”œโ”€โ”€ stockController.js     # Historical price queries
โ”‚   โ”‚   โ”œโ”€โ”€ externalController.js  # IndianAPI integration + caching
โ”‚   โ”‚   โ”œโ”€โ”€ screenerController.js  # Dynamic filter query builder
โ”‚   โ”‚   โ””โ”€โ”€ analyticsController.js # Window functions, heatmap, procedures
โ”‚   โ”œโ”€โ”€ routes/                    # URL โ†’ controller mappings
โ”‚   โ””โ”€โ”€ migrations/
โ”‚       โ”œโ”€โ”€ run_migration.js       # Creates VIEW + PROCEDURE
โ”‚       โ””โ”€โ”€ check_sector.js        # Backfills sector data from JSON
โ””โ”€โ”€ frontend/
    โ””โ”€โ”€ src/
        โ”œโ”€โ”€ App.jsx                # React Router routes
        โ”œโ”€โ”€ components/Layout.jsx  # Navigation bar
        โ”œโ”€โ”€ services/api.js        # Centralised API calls
        โ””โ”€โ”€ pages/
            โ”œโ”€โ”€ Dashboard.jsx
            โ”œโ”€โ”€ CompanyDetail.jsx  # Rich stock detail page
            โ”œโ”€โ”€ Screener.jsx       # Multi-filter stock screener
            โ”œโ”€โ”€ Analytics.jsx      # Advanced SQL showcase
            โ”œโ”€โ”€ Research.jsx
            โ”œโ”€โ”€ TradeData.jsx
            โ””โ”€โ”€ AddCompany.jsx

๐Ÿ“Š Current Data

Metric Value
Companies tracked 22
Distinct sectors 13
Screener filters 15+
Analytics SQL techniques 5
DB Tables 7
DB Views 1
Stored Procedures 1
API calls per page view (after seeding) 0

๐Ÿ“„ License

This project is for educational/academic use โ€” DBMS coursework project.

About

Full-stack stock analytics platform built with React, Node.js, Express.js, and MySQL for financial data visualization, stock screening and market analysis.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors