ThemeFlow: An Expectation-First Industry Rotation Engine for A-Shares Inspiration Every quantitative system I'd built before ThemeFlow made the same mistake: it waited for proof. Backtests looked great because they used financial reports (F10) that, in China's A-share market, are published 1–4 months after the quarter ends. By the time a turnaround shows up in the numbers, the market has usually already re-rated the stock 30–50% higher. I kept watching industries bottom, reverse, and run — fully priced in — before any backtest-friendly signal fired.
The insight that started this project: A-shares trade on narrative before they trade on numbers. Policy shifts, supply-side contraction, order books, and analyst channel checks arrive weeks to months before audited earnings confirm them. If I could systematically detect when multiple independent sources start corroborating the same thesis — and keep tracking it honestly enough to catch when that thesis turns out to be false — I'd have something earlier and more durable than a lagging financial screen.
There was a second, harder-won insight, which came from watching myself trade: the point where a thesis feels most "obviously correct" is usually the point where it's already crowded and late. A system that rewards certainty will systematically buy tops. I wanted the opposite — a system suspicious of its own confidence.
What it does ThemeFlow tracks ~110 Chinese A-share industries and thematic chains through a seven-stage reversible cycle:
Observation Pool → Reversal Expectation → Reversal Confirmed → Trend Sustaining → Cooling → Overheat Warning → Removed (cooldown) Observation Pool→Reversal Expectation→Reversal Confirmed→Trend Sustaining→Cooling→Overheat Warning→Removed (cooldown)
Transitions are driven by a layered evidence model, not a single score:
E1 (news corroboration): independent events from Telegram channels, RSS, broker research, and earnings forecasts — deduplicated so five reposts of one announcement don't masquerade as five confirmations, and filtered to strip corporate-governance boilerplate and pure price-chase chatter from genuine catalysts. E2 (conviction persistence): does institutional belief in the thesis hold for multiple consecutive weeks, or was it a one-off upgrade? E3 (expectation rung): a four-step ladder from narrative/policy, to channel/price signals, to order/forecast visibility, to realized earnings — tracking how confirmed a thesis is without requiring it to already be fully confirmed. M (market acceptance): is price action actually rewarding the thesis, or is the market shrugging at good news? B (fundamentals): F10 data participates only as a confirming signal, never as a gate — it can never be the reason a reversal is rejected, only extra conviction once already in motion. A dedicated purity engine resolves each theme's true core constituents — using point-in-time index weights and business-composition disclosures — so a concept pool of 500+ loosely-related tickers gets reduced to the 40–60 stocks that actually drive the theme, with historically "future" information (like a company's 2026 index weight) never leaking into a 2021 evaluation.
Everything runs automatically after market close and surfaces through two dashboards: a market-wide radar across all tracked industries, and a deep-dive cockpit for actively watched sectors.
How I built it The system went through five major iterations, each forced by a failure the previous one couldn't see past:
V2/V3 established the basic pipeline — PIT-safe market structure computation (float market cap, turnover, relative strength vs. dual benchmarks), F10 parsing from raw three-statement filings, and a first cycle state machine. V4 was a near-total rebuild after discovering the earlier reversal signal had zero discriminating power out-of-sample — the "predictive" signal was an artifact of in-sample fitting. V4 introduced the expectation-first philosophy: entry doesn't require F10 confirmation at all; it requires independent, persistent, non-noise news corroboration, calibrated against the industry's own trailing baseline (not a fixed threshold) so a general news-volume spike doesn't light up every track at once. V4.1 added the leader purity engine — resolving true core stocks per theme using a leave-one-out lagged correlation attribution technique: for each candidate stock, compute 𝜌 self ρ self (correlation to the theme's anchor return, excluding itself) and 𝜌 home ρ home (correlation to its home industry, excluding itself), strictly on a [ 𝑡 − 120 , 𝑡 − 1 ] [t−120,t−1] trailing window so day 𝑡 t never leaks into its own classification. V4.2 fixed six systemic cognitive blind spots surfaced by a structured review: CapEx direction was backwards for growth industries (expansion is bullish demand signal, not oversupply); crowding was measured as absolute turnover share, which falsely tagged every sector as "overheated" during broad market-cap expansion; position gates used only absolute 3-year price percentile, missing cases where an industry was cheap relative to peers even if not at an all-time low. The current pass is an ongoing adversarial review cycle — every major change gets evaluated by a second independent pass hunting for look-ahead bias, threshold gaming, and silent regressions before it's frozen for forward (out-of-sample) tracking. Throughout, I enforced one non-negotiable rule: strict point-in-time (PIT) discipline. Every input — market cap, correlation windows, F10 financials, index constituents, institutional holdings — is filtered to what was actually knowable on the evaluation date, with statutory disclosure lag windows applied explicitly (e.g., quarterly fund holdings aren't visible until 15 trading days after quarter-end).
Challenges I ran into The F10 lag was worse than expected, and hid itself. Historical native financial data silently carried next year's comparative-column announcement date instead of the current year's — meaning years of backtests had financial data appearing roughly a year late without anyone noticing, because the error made results look more conservative, not less. News deduplication was nearly useless at first. A naive keyword-Jaccard merge compressed ~2,200 raw items down to only ~2,000 "events" — a 9% compression rate — because an LLM extracting keywords phrases the same story differently every time it's reposted. Fixing this required an anchor-term approach: merge items sharing a keyword rare enough (seen ≤15 times market-wide in 90 days) to be a specific proper noun, while still requiring shared specific numbers to avoid merging two different companies' monthly sales reports into one event. Every new signal needed its own trap door. Turnover crowding looked fine until a sector's market-cap weight itself grew — then "high turnover share" just meant "the whole sector got bigger," not "everyone's piling in." Overheat detection initially fired at absolute price/volume lows (0–10th percentile) because it didn't have a "not actually at the bottom" floor. Calibration without peeking at returns. Every threshold (minimum corroborating events, baseline heat ratio, cooldown weeks) had to be set by looking only at trigger-frequency distributions — never by checking which threshold produced better backtested returns — to avoid quietly overfitting the "expectation" layer to history it would never see again live. Accomplishments that I'm proud of A fully point-in-time backtest harness spanning 2018–2026 that I can run against historical snapshots without a single field leaking future information — verified by deliberately re-running the same evaluation with and without specific guardrails to confirm they actually matter. Catching and fixing a real production incident mid-project: a scheduler script failure silently caused a "frozen" forward-tracking snapshot to be generated under broken conditions, and building a parameter fingerprinting system specifically so that kind of drift can never again go undetected. A reversal-detection system that explicitly treats "this looks too certain" as a warning sign rather than a confirmation — operationalized as a real, testable rule, not just a design philosophy. What I learned The hardest problems weren't modeling problems — they were epistemics problems: how do you know what your model could have known on a given day, three years ago, inside a cache file that was regenerated yesterday? Most of the real bugs in this project were leaks of some kind: future index weights, future financial restatements, future knowledge dressed up as a historical signal. Building the discipline to ask "could I have actually seen this?" for every single field, every time, turned out to matter more than any individual trading idea.
What's next Thirteen weeks of genuine forward (out-of-sample) tracking, started cleanly after the review fixes above are applied — the first real test this system has faced where I don't already know the answer.