Research PaperCompleted July 2026

PSX Stock Predictor: Walk-Forward Machine Learning for Pakistan Equity Returns

The complete research arc: from a rejected 15-stock price prototype, through BiLSTM return forecasters (V10-V16), to LightGBM cross-sectional rankers (V17 family) and a final net-of-costs portfolio study with significance testing, bootstrap robustness, regime-overlay sensitivity, and capacity analysis.

AM

Arham Mirkar

DataLayer - Enterprise Data Infrastructure

Primary evidence: saved JSON/CSV artifacts in the PSX Stock Price Predictor repository.

177,203
Model rows

Training panel, 77-78 PSX symbols, 2016-2026

44.2%
Final ann. return

Net of 0.5% RT costs, walk-forward 2020-2026

1.47
Final Sharpe

vs 0.86 equal-weight B&H, 1.21 KSE-100

t = 3.10
Alpha t-stat

Monthly active vs B&H, p = 0.0027, 7/7 years

Technical Summary

This study asks whether machine learning can produce deployable excess returns on the Pakistan Stock Exchange. Two model families were built on a 77-78 symbol panel with expanding walk-forward validation (each test year predicted by models trained only on prior data): BiLSTM-attention return forecasters, of which V14 is the strongest (61.4% mean 20-day directional accuracy across seven folds), and LightGBM cross-sectional rankers (V17 family) trained on percentile-rank targets computed from corporate-action-adjusted prices.

The central finding is negative for single models and positive for the ensemble: no individual model carries statistically significant portfolio alpha, but a 50/50 blend of the three-model rank ensemble with a 60/120-day momentum sleeve, wrapped in a 200-day moving-average regime overlay, earns 44.2% annualized net of 0.5% round-trip costs with Sharpe 1.47 versus 21.3% (Sharpe 0.86) for equal-weight buy-and-hold over 2020-2026. The monthly active return is +1.47% (t = 3.10, p = 0.0027) and survives block-bootstrap, parameter-grid, rolling-window, and liquidity-filter robustness checks — with returns compressing to 34.8% annualized on a realistically tradable universe.

The final answer is a blend, not a single best model.

Every individual model tested — V14 BiLSTM, V17 and V17b LightGBM rankers — fails significance on its own (alpha t between -0.03 and 1.47). The deployable result is a 50/50 combination of the three-model rank blend with a 60/120-day momentum sleeve: 44.1% annualized net, Sharpe 1.34, and the only configuration that beat buy-and-hold in all seven walk-forward years (alpha t = 3.10, p = 0.002).

Switching to cross-sectional rank targets fixed the objective.

The V17 LightGBM family predicts each stock's percentile rank of split-adjusted 20-day forward return within the daily cross-section, instead of absolute return. This matches what a long-only top-N portfolio actually needs and removes the corporate-action corruption that the LSTMs trained through (raw closes distorted by MARI 8.5:1, LUCK 5:1, SYS 5:1 splits).

A simple trend regime overlay pays for itself in bears.

Scaling gross exposure to 50% when the KSE-100 closes below its 200-day moving average, with the cash sleeve earning the SBP policy rate, lifts Sharpe from 1.34 to 1.47 and cuts max drawdown from -44% to -34.8%. In the 2022 bear the overlay held the strategy to -5.9% while buy-and-hold lost -24.2%. All 20 cells of the MA-window x floor robustness grid beat the no-overlay baseline on Sharpe.

Half the edge is momentum, and capacity is finite.

A plain 60/120-day momentum rank carries alpha t = 2.77 on its own; the pure ML sleeve is t = 1.70 — suggestive, not conclusive. Block-bootstrap keeps the combined active return positive (90% CI +8.6% to +27.2%), but on a liquidity-filtered universe (ADV >= PKR 25M) returns compress to 34.8% annualized at roughly PKR 100-400M deployable capacity.

Scope

The target is return ranking, not price memorization.

The research moved from next-close price regression to 20-day return forecasting because allocation depends on relative expected return, direction, and rank, not whether the model can reproduce split-adjusted price levels.

Observation grain

One symbol-date sample with a 60-trading-day lookback window and close-to-close forward return labels for 5d, 10d, and 20d horizons.

Primary target

20-trading-day return: (close[t+20] - close[t]) / close[t]. Direction is correct when predicted and realized returns have the same sign.

Validation design

Expanding walk-forward folds. Each test year is evaluated after training only on prior data, with a 30-calendar-day embargo around the validation boundary.

Feature families

Technical momentum, volatility, candlestick, market-index context, FIPI flow, USD/PKR, Brent crude, SBP policy-rate, sector-relative, regime, fundamental, and sentiment-derived inputs.

Leakage controls

Training-only scalers, temporal split by date, lagged macro/flow context, label thinning to reduce overlapping-target autocorrelation, and explicit corporate-action adjustment work.

Method

BiLSTM attention with explicit directional pressure.

The dominant architecture projects the feature window, encodes sequence dependence with bidirectional LSTMs, uses multi-head self-attention for temporal weighting, and predicts multi-horizon returns. Later versions add loss terms for sign agreement, downside recall, magnitude matching, variance floor, and bias correction.

Input window: (batch, 60 trading days, N features)
  -> feature dropout + linear projection
  -> sinusoidal position context
  -> 2-layer bidirectional LSTM, hidden=128
  -> 4-head self-attention + residual normalization
  -> feed-forward block + residual normalization
  -> last-step latent state
  -> return heads: 5d, 10d, 20d
  -> loss: Huber + sign penalty + asymmetric downside + variance + bias

Lookback

60 trading days

Primary horizon

20 trading days

V14 features

97 filtered inputs

V16 features

130 filtered inputs

Training split

Expanding walk-forward

Embargo

30 calendar days

Model Audit

Every major result changes the interpretation.

The research is incomplete if it only reports the best number. The archive shows why objectives, features, and validation definitions matter.

V1

15-stock price-regression prototype

36,035 samples, 15 liquid KSE names, 53 features

Final holdout: 49.46% true direction, 6.41% MAPE

Rejected as the final paper basis. It learned price levels more than tradable return rankings and did not beat naive price baselines on MAPE.

V10.1

Monthly 20d production trial

78-symbol feature table, monthly horizon, production dashboard branch

2025 holdout: 51.68% direction. 2026 test: 40.93% direction. Production backtest direction was 73.74% but is treated as optimistic.

Useful operational prototype, not a strict research endpoint. The production backtest is reported as an audit artifact, not as a final scientific claim.

V10.5

Quant research-driven multi-horizon model

92 model features, 5d/10d/20d heads, volatility-scaled targets

Manifest 2024-2026: 58.1% mean direction, 0.277 return correlation, 14.35% MAPE.

Strong ranking candidate, especially in 2026, but official summary covers only three folds and needs broader stability checks.

V14

Best complete deep-learning model

97 model features, BiLSTM attention, sign penalty, down-loss asymmetry

2020-2026: 61.4% mean direction, 0.172 return correlation, 15.30% MAPE.

Strongest standalone deep-learning evidence set. Retained as one leg of the final blend, but its top-10 portfolio alpha is not significant alone (t = 0.83).

V16-old

Expanded feature model

130 model features with fundamentals, FIPI, regime, and sentiment additions

2026 fold: 56.7% direction, 0.128 return correlation, 72.7% down recall.

Improved downside recognition in 2026 but reduced up precision. Extra features introduced calibration and overfitting risk.

V16-fixed

Bias-calibrated V16 branch

130-feature V16 feature table, asymmetric loss, stronger bias correction, sign-balance penalty

Common 2020-2023 raw predictions: 57.40% direction, 0.143 IC, 10.86% return MAE.

Magnitude calibration improved, but direction and ranking degraded. Calibration alone did not solve ranking.

V17

LightGBM cross-sectional ranker

V14 feature table, target switched to daily percentile rank of split-adjusted 20d forward return

Mean daily rank IC +0.063 across 2020-2026 folds; early stopping collapsed to one tree on half the folds.

Proof that the rank objective on adjusted prices works, but the validation-window design was fragile under regime shifts.

V17b

Primary

Regularized multi-seed ranker

features_v16 with documented noise features removed, fixed 400 rounds, 3-seed averaging, no early stopping

Rank IC positive in 6 of 7 folds (peak +0.109 in 2024); top-3 portfolio 36.7% ann. standalone.

The most reliable single ranker. Still not significant alone (t = 1.47) — its value is realized inside the blend.

V17c

Ranker with explicit momentum block

V17b plus 60/120/240d momentum, 12-1 momentum, 52-week-high distance, and volatility features on adjusted closes

Rank IC comparable to V17b, but top-N portfolios weaker (top-10 t = 0.72 vs 1.70 for the blend).

Negative result worth keeping: feeding momentum into the GBM diluted it. Momentum works better as a separate sleeve combined at the portfolio level.

V14 Evidence

Direction survives most regimes; rank quality does not.

V14 is directionally stable across most folds, but Spearman IC turns negative in 2022 and varies sharply by regime. The result is real enough to study, not stable enough to ship without a risk layer.

FoldDirectionICMAPEDown RecallUp PrecisionInterpretation
2020
64.2%
+0.31313.56%53.1%64.8%Strong broad-market signal
2021
60.2%
+0.06014.85%90.3%51.5%Defensive bias helped downside calls
2022
60.4%
-0.07215.91%92.7%28.3%Direction survived, rank IC failed
2023
57.3%
+0.09315.93%32.2%59.9%Rally regime challenged down bias
2024
57.8%
+0.20417.62%60.3%66.9%Positive ranking recovery
2025
54.7%
+0.10016.30%41.3%58.1%Weakest completed calendar fold
2026
75.3%
+0.50312.97%84.5%71.6%Partial-year stress-regime outlier
Head-to-Head

Common-fold comparison prevents cherry-picking.

The table below is freshly recomputed from raw prediction CSVs on shared 2020-2023 folds. It is not generated from the old comparison report. IC is Spearman rank correlation between predicted and realized 20-day returns.

ModelFoldsNDirICRet MAEBiasTop-10 AlphaBeat Rate
V10.52020-202313,83860.65%+0.25712.21%-4.98 pp+0.85 pp59.9%
V142020-202322,86860.47%+0.23415.44%-4.44 pp+0.48 pp48.9%
V16-old2020-202322,86860.34%+0.20315.44%-5.84 pp-0.07 pp50.2%
V16-fixed2020-202322,86857.40%+0.14310.86%-2.90 pp+0.43 pp50.5%

Top-10 alpha is the average realized 20-day return of the top-10 predicted stocks minus the same-date universe average. It is a period statistic, not a compounded strategy return.

Cross Section

The signal is stock-specific.

Per-stock performance shows that the model is not learning a single universal PSX rule. Banks and defensives often rank better than high-volatility technology names in the common-fold audit.

V14 top symbols

2020-2023 common folds
THCCL
70.3%+0.411
NBP
70.2%+0.367
BAHL
70.2%+0.407
PPL
68.2%+0.321
HUBC
66.6%+0.408
HBL
66.6%+0.437
MCB
66.2%+0.485
UBL
65.9%+0.441

V16-fixed top symbols

2020-2023 common folds
PPL
69.2%+0.285
MCB
68.2%+0.349
POWER
67.9%+0.329
HUBC
66.9%+0.271
NBP
65.6%+0.267
THCCL
65.0%+0.305
BAHL
63.9%+0.338
HBL
63.6%+0.252
Portfolio Translation

Ranking alpha exists, but compounding claims are fragile.

The local files include very high compounded top-N results when overlapping 20-day predictions are chained. Those figures are not suitable as a research claim; the conservative evidence here is average per-period top-basket return over the same-date universe. The proper daily net-of-costs backtest that resolves this question appears in the strategy study further below.

V14 all folds

2020-2026

+0.78 pp

Top-5

+0.69 pp

Top-10

51.9%

Beat

The best complete model creates a modest positive top-10 return spread over the same-date universe, but the edge is small relative to PSX volatility.

V10.5 all saved folds

2020-2026 raw CSVs

+0.80 pp

Top-5

+0.65 pp

Top-10

56.3%

Beat

V10.5 ranked better than the universe more consistently in raw saved folds, but its official manifest summary only covers 2024-2026.

V16-fixed common folds

2020-2023

+0.45 pp

Top-5

+0.43 pp

Top-10

50.5%

Beat

Calibration preserved some top-basket alpha while weakening direction. This is a research branch, not a superior model.

A separate non-overlapping V10.5 final audit reported combined 20-day rebalanced returns of +65.1% for Top-5 over eight periods, with -15.2% max drawdown. It is promising but too sparse to substitute for the broader walk-forward classification evidence.

Data Integrity

Corporate actions were a first-order error source.

PSX bonuses, splits, and rights issues create mechanical price discontinuities. If those are not adjusted, the model is rewarded or punished for predicting accounting mechanics rather than investor returns.

SymbolEventPeriodResearch impactStatus
SYS5:1 stock splitMarch 2025Raw price discontinuity caused the model to interpret a mechanical share split as a crash.Adjusted
LUCK1:1 bonus issueJuly 2024Unadjusted labels inflated price-error metrics and distorted return targets around the ex-date.Adjusted
UBLBonus issue2024Incorrect raw close continuity made bank-sector forecasts look worse than the adjusted series.Adjusted
MARIRight issue2023Return series required ratio-style adjustment to separate entitlement mechanics from market repricing.Adjusted
ENGRO1:1 bonus2021Historical levels needed back-adjustment so the model did not learn a false structural break.Adjusted
Phase 2: Rank Objective

The V17 family predicts ranks, not returns.

The corporate-action findings above motivated a redesign: LightGBM models trained on the daily cross-sectional percentile rank of split-adjusted 20-day forward returns. Predicting which stocks beat the cross-section is exactly what a long-only top-N portfolio needs. The table shows out-of-sample daily rank IC (Spearman) per walk-forward fold.

FoldV17 (early stop)V17b (3-seed, 400 rounds)V17c (+momentum block)
2020+0.013-0.024-0.010
2021+0.085+0.037+0.034
2022+0.059+0.078+0.099
2023+0.012+0.013+0.032
2024+0.058+0.109+0.106
2025+0.070+0.068+0.071
2026+0.147+0.107+0.093

V17's early-stopping window collapsed to a single tree on half the folds because the last 10% of training dates rarely resembled the test year. V17b fixes this with a fixed 400 boosting rounds, stronger regularization, and 3-seed averaging: its IC is positive in six of seven folds. V17c adds explicit momentum features but did not improve portfolios — momentum proved more valuable as a separate sleeve.

Strategy Study

No single model is significant. The ensemble is.

Every configuration below is a daily net-of-costs backtest over 2020-2026: top-N equal weight, rebalanced every 20 trading days with 1-day execution lag, 0.5% round-trip costs, corporate-action adjusted prices, and idle cash earning the SBP policy rate. Alpha t is a monthly regression of active returns against equal-weight buy-and-hold.

ConfigurationAnn. ReturnSharpeMax DDAlpha tBeat B&HReading
KSE-100 index24.4%1.21-37.0%Market benchmark
Equal-weight buy & hold21.3%0.86-46.0%Universe benchmark all alpha is measured against
V14 top-10 (best single model)25.8%0.92-41.9%0.836/7Positive but not significant
V17b top-3 (best single ranker)36.7%1.03-50.7%1.474/7Higher return, concentrated and unstable
3-way ML rank blend, top-1033.9%1.12-43.6%1.706/7Diversifying model errors beats any single model
Momentum 60/120d, top-1039.9%1.22-41.5%2.776/7The strongest standalone factor in PSX 2020-2026
50% ML blend + 50% momentum, top-1044.1%1.34-44.0%3.217/7Only configuration to beat B&H every year
Final: combo + 200d-MA regime overlay44.2%1.47-34.8%3.106/7Production configuration (V17_PROD)

The blend's value is error diversification: V14 (sequence model, raw-price era), V17 (GBM on V14 features), and V17b (GBM on expanded features) make different mistakes, so averaging their cross-sectional ranks is more stable than any member. Adding the momentum sleeve at the portfolio level — rather than as model features, which V17c showed dilutes it — produces the only configuration that beat buy-and-hold in all seven years.

Final Result

Year by year, the overlay earns its keep in bears.

V17_PROD is the production configuration: the 50/50 ML-momentum combo with gross exposure halved whenever the KSE-100 closes below its 200-day moving average, cash earning the SBP policy rate (13-22% during the 2022-23 tightening cycle).

YearV17_PRODCombo, no overlayEW Buy & HoldKSE-100
2020+51.7%+58.8%+41.4%+4.6%
2021+19.7%+17.1%-4.9%+0.4%
2022-5.9%-15.5%-24.2%-9.4%
2023+51.5%+56.1%+33.1%+54.5%
2024+140.3%+140.3%+88.2%+87.4%
2025+76.8%+76.8%+40.0%+50.7%
2026*-6.4%-1.6%-4.4%-3.0%

2026 is a partial year through June. The overlay's value concentrates in 2022: -5.9% against -24.2% for buy-and-hold. Its cost shows in choppy 2026, where MA whipsaws left the strategy behind the no-overlay combo.

+1.47%/mo

Monthly alpha regression

Active return vs equal-weight buy-and-hold: t = 3.10, p = 0.0027, information ratio 1.22, 71% monthly hit rate over 78 months.

P(<=0) = 0.000

Stationary block bootstrap

2,000 draws of daily active returns with mean 21-day blocks: annualized active +17.5%, 90% CI [+8.6%, +27.2%]. No bootstrap path produced non-positive active return.

20/20 cells

Overlay parameter grid

Every combination of MA window {100,150,200,250} and risk-off floor {0.0-0.7} beats the no-overlay baseline on Sharpe. The chosen (200d, 0.5) cell is not a lucky corner.

99% positive

Rolling 12-month windows

Of all rolling 12-month windows, 99% show positive active return vs buy-and-hold. Worst window: -1.6%. Median: +26.8%.

Capacity

The strategy is deployable at PKR 100-400M, not unlimited.

Re-running the production strategy with average-daily-value floors on the selection universe, assuming 15% volume participation, quantifies how much of the edge lives in small caps.

Universe filterAnn. ReturnSharpeAlpha tDeployable AUM
No filter44.2%1.473.10~PKR 31M median
ADV >= 10M34.5%1.221.83~PKR 150M
ADV >= 25M34.8%1.221.93~PKR 209M median
ADV >= 50M32.2%1.141.65~PKR 300M
ADV >= 100M24.6%0.920.54PKR 400M+

The unconstrained 44.2% headline is honest only for personal-account size. On an ADV >= PKR 25M universe the result is 34.8% annualized, Sharpe 1.22, with median deployable AUM around PKR 209M (2026 median ~PKR 485M).

Limitations

What the paper does not prove.

A research paper becomes stronger when its negative evidence is visible. These caveats are not footnotes; they define the boundary between a promising signal and an investable system.

Roughly half the final edge is medium-term momentum, and PSX 2020-2026 was a momentum-friendly market. The pure ML sleeve alone is t = 1.70 — suggestive, not conclusive.

2026 year-to-date the production strategy is -6.4% versus -4.4% for buy-and-hold: the regime overlay whipsawed in the current choppy market. It earns its keep in sustained bears (2022: -5.9% vs -24.2%) and costs a little in chop.

The backtest assumes fills at the close with 15% volume participation and 0.5% round-trip costs; long-only, no leverage, no borrow. Tick size, circuit breakers, and intraday impact are not simulated.

Unconstrained headline numbers rely on small-cap picks with ~PKR 31M median deployable capacity. On an ADV >= PKR 25M universe the annualized return falls to 34.8% and alpha significance weakens to t = 1.93.

V14 LSTM predictions refresh only with walk-forward retrains; only the LightGBM models have a live inference path. A live blend today leans more on the GBM sleeve than the backtest did.

The 2026 fold is a partial year. All seven-fold aggregates and 7/7 beat counts include it, and conclusions could shift when the year completes.

Conclusion

Final verdict: the best model is the ensemble.

Asked "which model was best," the honest answer has two levels. Among single models, V14 remains the strongest complete deep-learning evidence set (61.4% mean direction) and V17b is the most reliable ranker (positive rank IC in six of seven folds) — but neither carries significant portfolio alpha alone. The research-grade result is the production strategy: a 50/50 blend of the V14 + V17 + V17b rank ensemble with 60/120-day momentum, under a 200-day-MA regime overlay, delivering 44.2% annualized net (Sharpe 1.47, alpha t = 3.10) against 21.3% for buy-and-hold — compressing to a still-attractive 34.8% on a realistically tradable universe. What remains is not modeling but evidence: a live, auditable track record.

1

Build an auditable live track record

Paper-trade the production configuration first: refresh features, run live LightGBM inference, rebalance every 20 trading days, and reconcile live versus backtest monthly. A verified live record is the single most valuable remaining artifact.

2

Give the LSTM sleeve a live inference path

V14 predictions currently refresh only at walk-forward retrains. Porting it to the same daily inference pipeline as the GBM rankers would let the deployed blend match the backtested one exactly.

3

Re-test when 2026 completes

The partial 2026 fold is the strategy's weakest year and the overlay's worst regime. Re-running significance and robustness on the full year is the honest out-of-sample continuation of this study.

4

Stress the momentum dependence

Half the edge is medium-term momentum in a momentum-friendly sample. Testing the combo through synthetic momentum-crash scenarios and on pre-2020 data would bound the downside of that concentration.

Sources and Reproducibility

Primary local artifacts reviewed: results/all_results.json, results/baseline_comparison.json, results_v10.1_monthly/all_results.json, results_v10.5_quick_test/walk_forward_results.json, results_v14/walk_forward_results.json, results_v16/walk_forward_results.json, raw prediction CSVs under results_v10.5_quick_test, results_v14, results_v16, results_v16_fixed, results_v17/ v17b/ v17c, and the full strategy evaluation suite in results_v17_eval (top-N comparisons, significance tests, overlay robustness grid, block bootstrap, rolling 12-month actives, capacity analysis) plus V17_PRODUCTION_REPORT.txt.

Data sources include Pakistan Stock Exchange OHLCV histories, KSE index histories, NCCPL/FIPI flow files, SBP policy-rate data, USD/PKR, Brent crude, corporate announcements, and parsed company financials where available.

This research is educational and methodological. It is not investment advice, a solicitation, or a representation of live trading performance.