Personal investment research agent · how it works
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.
The system
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.
Division of work
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".
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.
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
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.
The store can only be read with a ceiling. There is no default date and no way around it in SQL.
Generated code gets only the tables its plan declared, already cut at the plan's date.
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
Code a model wrote runs in a throwaway container. Each limit has a test that tries to break it from inside.
| Limit | What it stops |
|---|---|
| No network | Fetching anything, or sending anything out |
| Read-only | Writing anywhere but its output folder and a small scratch space |
| Memory | 512 MB, no swap: a task that eats memory is killed and reported missing |
| Processes | 64 at most: a fork bomb stops |
| Time | 60 s of CPU and a wall-clock kill: an endless loop ends as a timeout |
| Docker socket | Held 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
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.
Every report opens with a short answer to the question, and code checks that it is there.
Measured
A prompt change reopens the gate. It passes only on results computed for today's prompts, models and questions.
| Check | What it asks | Result |
|---|---|---|
| Golden questions | Three sets: a synthetic market with a planted split, gap and delisting; the real market; my own account. Expected values computed by hand. | 30 / 30 |
| Determinism | Each plan's code written twice by the model must give the same tables. | 36 / 36 |
| Report quality | A 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.
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
Pocket Analyst answers my questions. The opportunity scanner looks for names I did not ask about, and is built to be sceptical of them.
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.
Results are checked, merged, ranked, with a cooldown. Names I already hold are left out.
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.
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