What-If Simulation Agent & Workflow Validation | Mycroft AI
The video explains how a stress-testing workflow turns a named scenario into a portfolio loss, using a minus 78% example on invented stocks. It then shows how the author built a second adder, matched it on 24 requests and tested a validator with deliberately flawed inputs.
A tech sector crash scenario took a portfolio of three invented chip stocks from $10,000 down to $2,200, a loss of 78%. In this video, Tanmay Kulkarni of Humanitarians AI asks where that 78 comes from and takes it apart. The work comes from a contribution to the Mycroft repository, a working collection of finance pipelines it calls recipes.
The scenario stress-testing recipe
One of the recipes is a scenario stress-testing agent. It shocks a portfolio with a named scenario and reports what is left. The portfolios in the video are invented by the author, and the tickers come from the workflow's own list. The numbers are scenario arithmetic, not predictions and not investment advice.
How shocks are added up
A scenario is a short list of named shocks. The tech sector crash names five: four price shocks, market minus 15%, technology sector minus 30%, semiconductors minus 35% and AI stocks minus 40%, plus a fifth that is a volatility number. The engine's rule is simple. For each holding, it adds up the shocks that belong to it. The biggest holding, a chip designer, belongs to the market, to semiconductors and to the AI list, so it takes minus 15, minus 35 and minus 40, which adds to minus 90. The workflow's own readme prints this exact sum as a worked example, and it also names a different way to combine shocks, so the rule is a choice you can see.
From shocks to the final number
The third holding is a chip maker that is not on the AI list, so it takes minus 15 and minus 35, which is minus 50. The second chip stock takes minus 90 like the first. With shares of 40%, 30% and 30%, the contributions are 36, 27 and 15, which total 78. A smaller scenario follows the same rule: an aggressive rate hike with market minus 10%, growth stocks minus 20% and technology sector minus 15%. Across four equal-share growth names, three take minus 30 and one, also filed under technology, takes minus 45. The book loses 33.75%, which the workflow labels critical, its word for losses above 30.
Checking the engine with a second adder
To verify the original, the author wrote a second adder, a Python copy of the engine's first steps, and ran both on the same portfolios. The original code comes straight from the workflow file. On 24 requests, every number, label and message matched. The author then added 12 deliberate breaks to the checks, and each one was caught.
The input validator
Before any adding, a validator reads each portfolio using the workflow's own rules plus one addition from the author. Portfolios whose shares total 6/10 or 1.2 are accepted, because the workflow rescales them to one. A holding with no ticker, a share that is not a number, or an empty list is stopped with its reason written down. All 10 of the author's deliberately flawed portfolios were stopped, so a bad sum never reaches the screen.
What remains open
Nothing in the checked code calls the outside world. The model call, the market data request and the reply to a caller are written down as handoffs, not approved. Five items in the recipe remain open, and it says draft on purpose.
Key takeaways
- A stress-test result is built from added shocks, so the number can be traced term by term.
- Each holding receives the shocks that belong to it, such as market, sector and theme lists.
- The minus 78% example comes from weighting 90, 90 and 50 percent losses by 40%, 30% and 30% shares.
- An independent second implementation matched the original on all 24 requests.
- Deliberate breaks and flawed portfolios are a way to test the checks themselves.
- A validator stops bad inputs with a written reason before any arithmetic runs.
Try it yourself
The next time a stress test gives you one number, ask what was added, which shocks from which lists, and whether anyone has run an independent adder beside the original. The Mycroft repository by Nik Bear Brown, which holds the recipes discussed here, is a good place to see the workflow itself.
Full transcript(auto-generated, with timestamps)
[0:00]Tech sector crash minus 78%. That is what one scenario did to a portfolio of three invented chip stocks, $10,000 taken down to 2200. Where does 78 come from? Let me take it apart. Hi, this is Tanmay Kulkarni in for Humanitarian's AI. This week I contributed to mycroft, a book in a working repository of finance pipelines and it calls them recipes. One of them, the scenario stress testing agent shocks a portfolio with a name scenario and reports what is left. The portfolios here are mine invented. The tickers come from the workflows own list. The numbers are scenario arithmetic, not predictions and not investment advice. A scenario is a short list of named
[0:39]Shocks. Tech sector crash names five. Four are price shocks, market minus 15%, technology sector minus 30, semiconductors minus 35 and AI stocks minus 40. The fifth is a volatility number. The engine's rule is simple. For each holding, add up the shocks that belong to it. Hold a guess. If the market alone falls 15%, how far does the biggest holding fall? Take the biggest holding, a chip designer. Everything belongs to the market, so a block of minus 15. It is a semiconductor stock, so minus 35. And it is on the AI list, so minus 40. The engine adds them, minus 90. The workflows own read me prints this exact
[1:16]Sum as its worked example, which is a big part of why it is so easy to check. It even names a different way to combine them, so the rule is a choice you can see. The third holding is a chip maker that is not on the AI list. A block of minus 15 for the market, minus 35 for semiconductors. That is minus 50, not 90. The second chip stock takes minus 90 like the first. Now give each its share, 40% 30 30. 36 plus 27 plus 15 makes 78 and there is the number. A smaller scenario shows the same rule. An aggressive rate hike, market minus
[1:49]10%, growth stocks minus 20, technology sector minus 15. Four growth names equal shares. Three of them take minus 30. One is also filed under the technology sector, so a third block lands on it and it takes minus 45. The book loses 33.75%, which the workflow labels critical. It's word for losses above 30. Here is the part I wanted to be sure of. To check the original, I wrote a second adder, a Python copy of the engine in its first steps, and ran both on the same portfolios. The original code comes straight out of the workflow file. On 24 requests, every number, every label, and every message matched. Then, I added 12
[2:25]Deliberate breaks to my checks, and each one was caught. Before any adding, a validator reads each portfolio with the workflow's own rules and one addition of mine, and it protects the sum. Portfolios whose shares total 6/10 or 1.2 are accepted because the workflow rescales them to one. A holding with no ticker, a share that is not a number, an empty list, each is stopped with its reason written down. 10 out of 10 of my deliberately flawed portfolios, a sum of nothing never reaches the screen. Nothing here calls the outside world. The call to a model, the market data request, and the reply to a caller are
[2:58]Written down as handoffs, not approved. Five items in the recipe are still open, and it says draft on purpose. That leaves a good list for next time. So, next time a stress test gives you one number, ask what was added, which shocks from which lists, and has anyone run the adder beside the original. A good answer names the terms. This was Tanmay Kulkarni for Humanitarian's AI. The contribution is pull request 74 on the Mycroft repository.
More from Mycroft Financial AI
4:50Exploring Open-Source AI Development & GitHub Collaboration | Mycroft AI
3:54Open-Source AI Development & Pull Request Review | Mycroft AI
3:35JBoss Migrator Explained | Application Migration & Java Modernization | Mycroft AI
2:11Automated Testing, Pytest & GitHub Actions CI/CD | Mycroft AI
3:35JBoss Migrator Explained | Application Migration & Java Modernization | Mycroft AI
4:46