How the engine works
Everything the dashboard shows is produced by the pipeline described here. No step is hidden.
The problem this addresses
Around 527 companies list on the Pakistan Stock Exchange, and all of them publish audited accounts. Almost none of that information reaches a retail investor in a usable form. The gap is filled by brokers, whose revenue comes from commission on trades rather than from the outcome of those trades, so the incentive to recommend activity is structural rather than personal.
The engine is an attempt to close that gap mechanically: read the accounts every company already files, rank the market on the evidence, and say in plain language why each name sits where it does. It is scoped to the KSE-100 rather than the full market because index constituents have the cleanest, most complete filings and enough traded volume for a recommendation to be actionable.
The pipeline
Ingest
PSX filings and end-of-day prices, SBP macro series. Every filing is stored with both the period it describes and the date it was published.
Standardise
Line items are mapped onto one chart of accounts so a bank, a cement maker and a refinery can be compared without pretending they are the same business.
Derive
Twenty-nine ratios on a trailing-twelve-month basis, then a winsorised z-score of each against sector peers in the same period.
Score
Five pillars combine into a 0-100 composite. Piotroski and Altman fold into quality and safety, and hard risk rules cap the result.
Rank
A gradient-boosted ranker is retrained walk-forward on the same features and blended into the composite.
Explain
The metrics that moved the score the most are turned into sentences, with the figures that produced them attached.
Validate
The whole thing is replayed quarter by quarter against the KSE-100, paying costs and respecting liquidity.
Point-in-time discipline
The single assumption that separates a real backtest from a flattering one.
A company's December quarter describes December, but nobody could read it until the accounts were filed. Scoring December using December's numbers on the first of January would hand the model information it could not have had, and it is the most common reason a stock screen looks brilliant on paper and disappoints in practice.
Annual accounts
120 days
Filing deadline used as the date an annual report becomes usable.
Quarterly accounts
45 days
The equivalent lag applied to interim filings.
Label horizon
63 days
The model may only train on a quarter whose return had already been realised.
The five pillars
Each pillar is the mean of its sector-relative z-scores, mapped so that 50 is the sector average and three standard deviations reaches either end of the scale.
Profitability & earnings quality
30% of the compositeWhether the business earns a real return on the capital it employs, and whether the profit it reports turns into cash.
Return on equity, assets and invested capital, net and operating margin, cash conversion, accrual ratio, free cash flow margin, Piotroski F-Score.
Valuation
25% of the compositeWhat you pay for that stream of earnings relative to what sector peers cost.
P/E, P/B, P/S, EV/EBITDA, earnings yield, free cash flow yield, dividend yield.
Balance-sheet strength
20% of the compositeWhether the balance sheet can survive a bad year without diluting or defaulting.
Debt to equity, interest cover, net debt to EBITDA, current ratio, equity to assets, Altman Z''-Score.
Growth
15% of the compositeWhether the business is getting bigger, and whether the growth reaches the bottom line.
Trailing revenue and earnings growth, three-year revenue CAGR, equity growth.
Price trend
10% of the compositeWhether the market has already started agreeing, which historically persists over months.
12-1 month momentum, price against the 200-day average, six-month relative strength, three-month return, one-year volatility.
Piotroski F-Score
Nine binary tests of whether a business improved on itself over the past year: is it profitable, is it cash generative, are returns rising, is profit backed by cash, is leverage falling, is liquidity improving, has it avoided issuing shares, is the margin widening, and are assets working harder.
Banks and insurers have no gross margin, no inventory and no meaningful current ratio, so the three tests that depend on them are replaced with lender equivalents: capital strengthening, spread widening and balance-sheet productivity. Where a test cannot be assessed at all, it is recorded as such rather than silently counted as a pass.
Altman Z''-Score
The original 1968 Z-Score was fitted on US manufacturers. The engine uses Altman's later emerging-market variant, which drops the sales-to-assets term that penalises asset-heavy firms, uses book rather than market equity, and adds a constant so the scale is comparable across markets. Above 5.85 is sound, below 4.15 is distress.
Financial companies are excluded from the Altman score entirely, as Altman himself excluded them: working capital and asset turnover do not describe a balance-sheet lender. Those names are assessed on capital adequacy and interest cover instead.
Risk gates
Rules that override a flattering composite. A statistically cheap company in trouble is not a buy, and the score is not allowed to say otherwise.
Where the numbers come from
This deployment runs on a simulated point-in-time history of the KSE-100.
PSX publishes company accounts as PDFs and offers no free, survivorship-free bulk history of standardised financial statements, so a decade of clean panel data cannot be assembled from its public endpoints. Rather than backtest on data that does not exist, the project ships a structural simulator: a Pakistan-shaped macro path drives a business cycle, each company carries persistent latent traits, statements are built to satisfy the accounting identities, and prices are pulled toward a fundamental fair value by a mean-reverting force alongside market and sector factors.
That makes every figure on this dashboard a simulation result, not a claim about any real company. The scoring, the explanations and the walk-forward testing work the same way on real data; what a live version still needs is a reliable source of standardised statements built from the PDFs companies publish.
Regulatory position
Distributing personalised investment recommendations to the public in Pakistan falls under the SECP's investment-advisory framework, including its Securities Managers and digital advisory regimes. This project is an academic research prototype: it produces a mechanical ranking with its reasoning attached, it is not tailored to any individual's circumstances, and it is not offered as advice. Any move toward distribution through broker platforms would need to be licensed first, which sits outside the scope of the final year project and is noted here as future work rather than an implementation step.
Research and educational project. Not investment advice. Figures are produced by a point-in-time simulation of the KSE-100 built for reproducible backtesting. Generated 2026-09-12 12:55:38 · universe KSE-100 · history 2014-01-01 to 2025-12-31 · model xgboost.XGBRanker(rank:pairwise).