Downloads & Methodology
Data files, source code, and documentation on how everything was computed · Jan 2010 – May 2026
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.
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.
| What | Detail |
|---|---|
| Schedule | Monday – Friday, 17:45 PKT (12:45 UTC) primary run |
| Retry 1 | 17:55 PKT (~10 min later) — runs if the primary failed or produced no data |
| Retry 2 | 18:55 PKT (~1 hour later) — final fallback for the day |
| Idempotent | Later runs skip committing if an earlier run already succeeded today |
| Holidays / weekends | Pipeline runs but finds no new market data and exits without committing |
| If all runs fail | The 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 | Primary Source | Fallback |
|---|---|---|
| Company listings & sectors | PSX Data Portal (dps.psx.com.pk) | psx-data-reader library |
| Daily close & volume | PSX /timeseries/eod/{SYMBOL} | — |
| KSE-100 Index | PSX /timeseries/eod/KSE100 (2021–present) | Yahoo Finance ^KSE (2010–2021) |
| USD/PKR exchange rate | Yahoo Finance (USDPKR=X) | Bundled CSV |
| CPI / Inflation | World Bank API | FRED → Bundled CSV |
| SBP Policy Rate | FRED API | Bundled CSV |
| Fundamentals (P/E, EPS, etc.) | PSX Data Portal company pages | — |
| Metric | Definition |
|---|---|
| Total Return | (Last Close − First Close) / First Close |
| CAGR | Compound Annual Growth Rate: (Last/First)^(1/years) − 1 |
| Volatility | Std. deviation of daily log returns, annualized (× √245 trading days) |
| Max Drawdown | Largest peak-to-trough decline over the full history |
| Sharpe Ratio | (CAGR − risk-free rate) / Volatility. Risk-free rate = avg SBP policy rate |
| Beta | Cov(stock, KSE-100) / Var(KSE-100), computed from daily log returns |
| Correlation | Pearson correlation of daily log returns vs KSE-100 |
| Real CAGR | CAGR minus average annual CPI inflation |
| Volume Trend | 30-day avg volume / 90-day avg volume (above 1 = rising) |
- – Price data comes from the PSX public data portal. It may contain gaps, errors, or delays. Corporate actions (splits, bonuses) might not be adjusted where data was not properly available.
- – This is a research and analytical tool, not financial advice. All code is open and available for download below. Verify any result independently before relying on it.
- – Macro data (CPI, T-bill) has triple fallback: live API, secondary API, bundled CSV. If all live sources fail, bundled data ships with the project.
- – This project was built in it's entirety using Windsurf.
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
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)