9 min read

InvestPilot — A Framework That Keeps LLMs Honest in Investment Research

Table of Contents

Recently I built an automated investment research workflow called InvestPilot. Over the past while, using the agent capabilities of Claude Code, I put together a deep fundamental research framework. It does not aim to “pick stocks for you with AI”; it tries to solve a harder problem: how do you make a large language model run a rigorous research process without making things up.

Why I built it

First, the background. I am a deep fundamental investor in the secondary market, tilted toward high-payoff setups and looking for expectation gaps that can close within zero to three months.

Everyone has tried using LLMs for research. The pain points are clear:

  • It invents numbers. PE, EPS, net profit — it states them with great confidence, and they are wrong.
  • It mixes conventions. Trailing PE one moment, forward PE the next; peer-comparison tables mixing T+1 and T+2, so every comparison is wrong.
  • It skips steps and goes on autopilot. You ask for analysis; it runs along and announces “done,” but when you look back the middle steps were never done properly.
  • Its conclusions are prompt but unfalsifiable. “I am bullish on this stock” — under what conditions would you change your mind? It cannot say.

The essential problem: a large model is a very articulate but undisciplined intern. Give it freedom and it gives you a polished-looking hallucination.

So I wanted to try: can you use software-engineering discipline to wrap it in hard constraints and force it to honestly run an investment-research SOP end to end?

That is InvestPilot. Below are a few of its core designs.

I. What it looks like

It is an agent harness built on Claude Code. The pipeline takes the deep-research SOP of a sell-side institute and breaks it into 9 steps (plus a front gate):

Step 0  Quick screen (Gate: PASS / WATCH / Full)


Step 1  Business deep-dive  ──┐
Step 2  Competitive moat     ──┤  Serial — a step cannot start until the previous one finishes
Step 3  Marginal change      ──┤
Step 4  Hypothesis matrix    ──┤  ← 15-check gates; fail and you block
Step 5  Financial modeling   ──┤
Step 6  Monte Carlo          ──┤
Step 7  Payoff strategy      ──┤
Step 8  Independent audit    ──┤
Step 9  IC review            ──┘  ← Auto-generates HTML / Markdown report

Supporting this pipeline are 10 prompt templates under prompts/ totaling 3,293 lines, and 21,000 lines of Python under src/ (including 15,000 lines of tests).

One-line definition: it compiles the “research SOP” into a state machine with a dependency graph, so the model can only travel along compliant paths.

II. A few designs I find interesting

Design 1: Compiling the research SOP into a state machine

This is the part I am most satisfied with.

Every step has a mandatory three-part action:

# Before starting
python -m src.cli workflow {workspace} start --step 5

# After producing the artifact
python -m src.cli workflow {workspace} complete --step 5 --artifact step5_financial_model.md

# Missing inputs → block
python -m src.cli workflow {workspace} block --step 5 --reason "..."

All step metadata (dependencies, required artifacts, gates, stage) is defined in a single step_contracts.json contract file; the workflow guard, report generation, and all validators read this one file — single source of truth.

The effect: Step 7 wants to run but Step 6 is not done? No way in. The agent cannot skip steps or declare completion hallucinatorily.

My earlier judgment was: do not trust the agent’s self-reporting; use code to force its behavioral boundary. So far this holds.

Design 2: “Self-computed valuation” — cutting numerical hallucination at the source

The place LLMs fail hardest in research is numbers. The news says PE 30x, a research report says 35x, some API returns 28x — the LLM will copy any of them, but the conventions may be completely off.

So I set an iron rule in the prompt (marked with 🚨 to signal it is hard):

All valuation metrics must be self-computed. PE, PB, PS, EV/EBITDA must be calculated from raw data; citing ready-made values from news, reports, or third-party APIs is forbidden. Each calculation must annotate: the price and date, the EPS/BPS/revenue value and source, the formula, and source: calculated.

It also explicitly forbids mixing trailing and forward PE, mixing T+1 and T+2, and inconsistent conventions in peer comparisons.

The rule is blunt but effective — it cuts off the most common error source in LLM research at the root.

Design 3: “No bare growth rates” — forcing falsifiable hypotheses

This is the methodological rule I am most stubborn about.

In Step 4 (hypothesis research) I stipulate:

A bare growth-rate percentage is a hard error. Every revenue forecast must be decomposed into two to four quantifiable drivers (e.g., “volume × ASP” or “store count × same-store revenue”); each driver must carry a contribution_pct (whose sum must equal the segment growth rate) and at least one evidence_id.

Why so stubborn? Because this step’s output feeds directly into the Monte Carlo simulation in Step 6.

If you feed in only “revenue grows 15% next year,” the Monte Carlo will dutifully produce P10/P50/P90 distributions, looking precise — but it is garbage in, garbage out. A pile of precise numbers masking a guess at the input.

Forcing the agent to break “15%” into “volume +8% × ASP +6.5%” and attach evidence to each factor is essentially forcing “a guess” into “something falsifiable.”

Design 4: Monte Carlo + t-Copula + Kelly — probabilistic thinking

Most “AI valuation” gives a target price and stops. I wanted to give a distribution.

A few designs of the probability engine:

  • PE/PB use a log-normal distribution (strictly positive, right-skewed);
  • Growth rates / margins use a normal distribution;
  • Variables are modeled with a t-Copula (degrees of freedom 6, capturing non-Gaussian tail dependence — under extreme conditions variables collapse together);
  • A 7-point percentile grid: P5 / P10 / P30 / P50 / P70 / P90 / P95;
  • Finally a half-Kelly formula gives a position-size cap, with an extra 50% haircut for poor Edge ratings.

At Step 7 the payoff ratio is computed from this distribution:

RRR = P(up) × E[upside] ÷ P(down) × E[downside]
RRRDecision
> 2.0Open position
1.0–2.0Wait for catalyst confirmation
< 1.0Do not open

The choice of t-Copula parameters, the granularity of the percentile grid, the boundary of Kelly in practice — all of this has room for discussion.

III. A real case that ran through: MINISO (MNSO)

Designs are no fun without an example. On June 12, 2026, I ran MINISO (MNSO / 9896.HK) through it, when the stock was HKD 26.

Here is the expectation gap it proposed itself in the Step 0 quick screen:

MINISO’s FY2025 revenue grew +26.2%, but adjusted net profit grew only +6.5% — revenue up, profit flat. The market therefore assigned a very low valuation (Forward PE ~9x). Our gap: if the Q2 2026 results confirm a margin recovery (from Q1’s 9.7% back toward a full-year 13.5%+), this stock should see a PE re-rating.

It then reasoned all the way to Step 7 and gave the payoff:

MetricValue
Current priceHKD 26.00
P50 targetHKD 30.66
P70 targetHKD 41.15
Probability of upside61.1%
Probability of downside38.9%
RRR3.06 (above the 2.0 threshold; open position)
Half-Kelly20.6%

But what I want to emphasize is its disconfirmation check and IC review — these two steps are what separate this framework from an “AI cheerleader.”

In the Step 7 disconfirmation check it answered, itself, “under what conditions does RRR fall below 1.0”:

Scenario one: structural margin deterioration confirmed. Q2 adjusted net margin stays below 10% (same as Q1’s 9.7%), proving the direct-store transition permanently dilutes margin. Net margin falls to 9%, EPS drops to ~RMB 1.5, PE 8x → target HKD 13 (−50%), RRR falls to 0.5.

Scenario two: Yonghui Superstores (601933.SH) loss reversal. If Yonghui’s Q1 profit of +RMB 287M is unsustainable and it returns to heavy losses, the market will apply a permanent diversification discount, PE compressing to 6–7x, RRR dropping below 1.0.

At the Step 9 IC review, the “head of research AI” gave conditional endorsement, not a bullish blanket:

Override Decision: Conditional Endorsement

① Until Q2 2026 results confirm adjusted net margin ≥12%, position size capped at 15%; ② At current price (HKD 25–26) open only 8% initially; the remaining 7% to wait for a pullback to HKD 24 or right-side Q2 confirmation; ③ Q2 results trigger mandatory re-review; adjusted net margin <12% → cut to 5%; ④ Kill switch: any single-quarter adjusted net margin <9% → liquidate immediately.

It did not say “strong buy, go all in.” It said “this is fundamentally a binary bet on Q2 margin recovery; the 38.9% probability of loss is real.”

This report, from Step 0 screening through Step 9 IC review plus the HTML report, was run automatically by the agent. The full five deliverables (HTML report, Markdown summary, distribution chart, PE Band, sensitivity heatmap) are all in the workspace.

The complete output of this case is in the repository.

IV. A detail: it was iterated through real failure

I do not want to write this as self-praise, so I must be honest: this framework was terrible in the beginning.

Look at its evolution log. The most recent full study (another stock: SMIC H-shares) exposed 11 engineering defects (FIND-029–039), several of them P0:

🔴 The balance sheet would not balance: in the three-statement model, the asset side and the liabilities-plus-equity side were each calculated independently, with no balancing plug; the old version could silently tolerate a 30% imbalance. After the fix a balancing item was introduced so that A = L + E by construction, with a transparent gate warning if the plug exceeds 15%.

🔴 PE valuation distorted for asset-heavy cyclicals: for a heavy-asset contract manufacturer, depreciation eating profit pushed PE above 200x, and price targets computed via PE × EPS were meaningless. After the fix the Monte Carlo supports valuation_primary="pb", preferring a BPS × PB path.

🔴 The Monte Carlo did not deduct R&D and interest: the simulation path missed R&D expense and interest expense, overstating EPS by about 2.6x, caught only when an alignment gate failed hard.

The naming, grading (🔴P0 / 🔵P1 / 🟡P2), and regression-test additions for these defects are all recorded in _optimization_findings.md. Current test baseline: 1061 passed / 0 failed.

I share this to say: whether an agent framework is mature is not in how pretty the README is, but in whether it has an honest record of its own pitfalls. Every real study exposes problems no one thought of before. This pace of iteration is the framework’s real value.

Closing

A responsible word at the end.

InvestPilot is a research tool for educational and informational purposes. It does not constitute any form of investment advice.

It will not make money for you. What it tries to do is: when a large model meets a sufficiently rigorous process framework, can it become a research partner that does not make things up, helping us do research more systematically, more falsifiably, more reproducibly.

The MINISO (MNSO / 9896.HK) data in this piece are all example outputs of the InvestPilot framework as of 2026-06-12 and do not constitute any investment advice. Markets carry risk; decisions require caution.