About This Project

PSX Analyzer is a quantitative analysis tool for the Pakistan Stock Exchange. It fetches daily price and volume data for every listed equity, computes standard financial metrics, and presents the results in an interactive dashboard. The entire pipeline — data collection, computation, and visualization — is written in Python and open-sourced in the repository.

Live Updates & Automated Pipeline

This site is no longer a one-time static snapshot — it is rebuilt automatically every trading day. A GitHub Actions workflow fetches fresh data from PSX, Yahoo Finance, and macro APIs, commits the updated CSVs to the repository, and Netlify detects the commit and rebuilds the entire static site from scratch.

WhatDetail
ScheduleMonday – Friday, 17:45 PKT (12:45 UTC) primary run
Retry 117:55 PKT (~10 min later) — runs if the primary failed or produced no data
Retry 218:55 PKT (~1 hour later) — final fallback for the day
IdempotentLater runs skip committing if an earlier run already succeeded today
Holidays / weekendsPipeline runs but finds no new market data and exits without committing
If all runs failThe previous build stays live; data will be stale until the next successful run

A notice appears at the top of every page when the site data appears to be more than four days old, so you know at a glance if the pipeline has not run recently.

Data Sources
DataPrimary SourceFallback
Company listings & sectorsPSX Data Portal (dps.psx.com.pk)psx-data-reader library
Daily close & volumePSX /timeseries/eod/{SYMBOL}
KSE-100 IndexPSX /timeseries/eod/KSE100 (2021–present)Yahoo Finance ^KSE (2010–2021)
USD/PKR exchange rateYahoo Finance (USDPKR=X)Bundled CSV
CPI / InflationWorld Bank API FRED → Bundled CSV
SBP Policy RateFRED APIBundled CSV
Fundamentals (P/E, EPS, etc.)PSX Data Portal company pages
Metric Definitions
MetricDefinition
Total Return(Last Close − First Close) / First Close
CAGRCompound Annual Growth Rate: (Last/First)^(1/years) − 1
VolatilityStd. deviation of daily log returns, annualized (× √245 trading days)
Max DrawdownLargest peak-to-trough decline over the full history
Sharpe Ratio(CAGR − risk-free rate) / Volatility. Risk-free rate = avg SBP policy rate
BetaCov(stock, KSE-100) / Var(KSE-100), computed from daily log returns
CorrelationPearson correlation of daily log returns vs KSE-100
Real CAGRCAGR minus average annual CPI inflation
Volume Trend30-day avg volume / 90-day avg volume (above 1 = rising)
Disclosure & Limitations
CSV Data Files

master.csv

168.6 KB — 606 companies, 26 columns of summary metrics

sectors.csv

3.9 KB — 37 sectors with aggregate statistics

macro_kse100.csv

85.7 KB — KSE-100 daily close (2010–2026)

macro_usdpkr.csv

191.0 KB — USD/PKR daily rate (2010–2026)

macro_cpi.csv

0.3 KB — Annual CPI inflation (World Bank)

macro_tbill.csv

0.3 KB — SBP policy rate history

Source Code (Python)

The full pipeline and application code. Read these to understand exactly how every number was computed.

config.py

3.4 KB — Configuration, paths, API endpoints, constants

fetcher.py

16.9 KB — Stock data fetching from PSX Data Portal

macro.py

11.7 KB — Macro data: KSE-100, USD/PKR, CPI, T-bill

metrics.py

8.8 KB — Per-stock metric computation (CAGR, Sharpe, beta, etc.)

sectors.py

5.3 KB — Sector-level aggregation

fundamentals.py

6.3 KB — Fundamentals scraping (P/E, EPS, dividend yield)

export.py

3.7 KB — CSV export logic

run_pipeline.py

5.3 KB — Pipeline orchestrator

app.py

36.8 KB — Flask application, routes, chart generation

freeze.py

9.5 KB — Static site generator for Netlify deployment

run.py

3.5 KB — Main entry point (CLI)