Personal investment research agent · how it works

Inside Pocket Analyst

A research agent for my own stock account. I ask a question in plain words, and it answers with a short report against a benchmark: returns, costs, drawdowns, what-ifs. Claude plans the analysis and writes the prose. Code computes every number, runs the generated code in a sandbox, and checks the report before I see it. It researches; I decide and place every order myself.

0
paths to a broker: no credential, no order tool, enforced by tests
1,900+
automated tests in the code base
30 / 30
golden questions answered within tolerance of hand-computed values
≈ $0.50
model cost per question, capped at $1 before any call

The system

From a question to a report

I ask from a web page, on the laptop or the phone. Three Claude roles take turns, and between each of them sits plain code that validates, runs and checks their work. What fails goes back to its author with the reasons, a bounded number of times. Nothing reaches me unless every check passed.

Question web page POCKET ANALYST Planner Claude · a JSON plan Coders one per task, in parallel Writer prose, no numbers Plan validator 20+ rules in code Sandbox no network, no secret Report check no digit, no advice Report figure → cell Market data store DuckDB · read under a date tables cut at the plan's date
The models never touch the data or a number. They write a plan, code and prose; code does the rest.

Division of work

Three models, none of them writes a number

  1. 1

    Planner2 repairs max

    Turns the question into a plan: which data, which tasks, which benchmark, which date. Code checks it against more than twenty rules, among them "no benchmark, no report".

  2. 2

    Coders3 calls per task

    One small Python module per task, as thin glue over a finance library I wrote and tested: returns, risk, costs, a causal backtest. Each module is read by a static check, run in the sandbox, and judged on the host from the files it wrote.

  3. 3

    Writer2 repairs max

    Writes the report around placeholders. Code fills them from the result tables and writes the part about the date, the benchmark and the costs itself.

Every figure on the report page is a button: it names the table and the cell it came from, and the plan, the code and the checks are one click away.

Data

No peeking at the future

A backtest that can see tomorrow's prices looks brilliant and means nothing. So the date is enforced in code, not asked of the model.

Read under a date

The store can only be read with a ceiling. There is no default date and no way around it in SQL.

Sandbox sees no store

Generated code gets only the tables its plan declared, already cut at the plan's date.

Look-ahead test

A task that walks through time is run again on data cut at 50, 75 and 90 %. Its results up to each cut must not change, or it is refused.

Prices, splits and dividends are stored raw and adjusted at read time, checked against the vendor's adjusted close: 0.003 % apart over 1,580 sessions, a 4-for-1 split and 25 dividends.

Generated code

Neither trusted nor believed

Code a model wrote runs in a throwaway container. Each limit has a test that tries to break it from inside.

LimitWhat it stops
No networkFetching anything, or sending anything out
Read-onlyWriting anywhere but its output folder and a small scratch space
Memory512 MB, no swap: a task that eats memory is killed and reported missing
Processes64 at most: a fork bomb stops
Time60 s of CPU and a wall-clock kill: an endless loop ends as a timeout
Docker socketHeld by a small runner beside the app, never by the app itself

And when it runs fine, its output is still judged: impossible figures are refused, not warned about.

The report

Prose from the model, numbers from code

The writer may not type a digit. Code reads the final text for numbers, number words and advice, in English and French, and sends anything else back.

accepted
"{gain_1y} ahead of the benchmark"
A placeholder, filled from its table cell.
refused
"about 12 % ahead"
A number typed by the model.
refused
"worth adding to the position"
Advice. It reports; I decide.

Every report opens with a short answer to the question, and code checks that it is there.

Measured

A gate before it is trusted

A prompt change reopens the gate. It passes only on results computed for today's prompts, models and questions.

CheckWhat it asksResult
Golden questionsThree sets: a synthetic market with a planted split, gap and delisting; the real market; my own account. Expected values computed by hand.30 / 30
DeterminismEach plan's code written twice by the model must give the same tables.36 / 36
Report qualityA judge model, first tested on reports with planted faults, reads every report for advice.0 found

The determinism check earned its place early: it caught two wrong figures that had passed every other check. One was an index compounded twice, which came out at 10247. Both led to fixes: every column the coder reads now carries a note, and impossible figures are refused.

Spending

Teach

When a figure is wrong, I flag its cell on the report with the value I expected. That becomes a new golden question. On the laptop, a model edits copies of the prompts until the new question passes and no earlier one breaks, and the change arrives as a pull request that CI accepts only if it touches the prompts and the new question. Built and tested; not yet used on a real correction.

The second agent

A scanner that argues against its own ideas

Pocket Analyst answers my questions. The opportunity scanner looks for names I did not ask about, and is built to be sceptical of them.

  1. 1

    Screenscode only

    My own rules, each one SQL query, linted before it runs on an in-memory copy of the market as it stood that day. It cannot open a file or reach the store.

  2. 2

    Shortlist5 a week max

    Results are checked, merged, ranked, with a cooldown. Names I already hold are left out.

  3. 3

    Bear caseClaude + judge

    A model writes the case against each name: three points, each tied to a value code filled in. Code refuses numbers and advice; a second model, tested on planted texts, reads what code let through.

  4. 4

    Thesis checkPocket Analyst

    Each name becomes a question to Pocket Analyst, with the same checks as mine. Then my phone gets a notice, in fixed words.

Every idea goes into an append-only log and is scored against the benchmark when its horizons close. Replays of past weeks go into a separate book, so hindsight never mixes with live picks.

Where it stands. Built and tested on a synthetic market; I read twenty bear cases and kept all twenty.

It has not run live yet: the free market-data plan keeps about six listings fresh, too few to scan.

Safety and privacy

Built so it cannot trade