The Algorithm That Knows Your Future (Or Thinks It Does)
Darshan demos a full-stack app that extracts financial goals from natural language and runs Monte Carlo simulations to show whether your retirement plan actually works.
Most people can state a financial goal in one sentence: retire in twenty years with a million and a half dollars, saving five thousand a month. Turning that sentence into a real answer about whether the plan works usually means a spreadsheet, a financial advisor, or a lot of guesswork. Darshan built a system that skips the form-filling entirely and lets you type the goal the way you'd say it out loud, then backs it with thousands of simulated market outcomes.
A goal extraction pipeline built on local AI
The application is a full-stack platform with a FastAPI backend and a React frontend, and its first job is understanding what the user actually wants. Rather than asking for a structured form, it accepts a plain-English description of a goal and runs it through a local Llama 3.1 model served by Ollama. The model extracts structured data from the sentence, along with a confidence score, and because it's a language model doing the parsing rather than a rigid form, typos and casual phrasing don't break it. The backend exposes this as one of three core REST endpoints, alongside health checks and simulation, and each is documented through FastAPI's interactive API docs so another developer can see the exact parameters and response bodies without reading the source.
That decoupling matters beyond the demo. Because the endpoints are independent of the React frontend, they can be called from a mobile app, wired into a spreadsheet, or dropped into a chatbot workflow built in n8n, which is the same automation tool used elsewhere in Humanitarians AI's other finance-focused work under the Mycroft project.
Monte Carlo simulation with real market data
Once a goal is extracted, the real work happens in a custom Monte Carlo engine. It pulls real historical market data from Yahoo Finance through the free yfinance library, then runs the numbers across thousands of simulated scenarios to calculate portfolio statistics and a success probability. The engine relies on numpy for vectorized computation, which keeps it fast even at scale: a run of a thousand simulations across two goals at once finished in under a second.
Three-step workflow: extract, configure, view results
The interface walks a user through three stages. First, they describe the goal in natural language with no jargon and no required format. Clicking "extract goal" sends the sentence to the backend, which parses it and pre-populates a configuration form with details like target amount, timeline, and current savings. From there, the user can adjust the assumptions: asset allocation percentages, which must add up to 100 percent, and the inflation rate used in the projections. Once the configuration looks right, running the simulation produces the third stage, a results view built with Recharts on a Tailwind CSS interface.
The results screen leads with the overall portfolio success rate, the probability of hitting the stated goal given the chosen allocation and contributions. Below that sits a breakdown of median, worst-case, and best-case outcomes, an expected shortfall figure, and an interactive chart showing percentile outcomes across the simulation. When a goal isn't on track, the system also surfaces recommendations for what to change.
Stress-testing multiple goals at once
The demo doesn't stop at a single goal. Darshan added a second one, a fifteen-year timeline with $45,000 in current savings, and ran the Monte Carlo simulation again with both goals combined. The combined configuration was too ambitious for the contributions on the books, and the success rate dropped straight to zero. The system still computed the worst-case outcomes and offered a recommendation: increase the monthly contribution by about $3,500. Bumping the contribution to $4,000 and re-running the simulation pushed the success rate back up to 99.9 percent, a concrete before-and-after that shows the tool isn't just producing a static report but letting users iterate toward a plan that actually works.
Built for reliability, not just demos
Two engineering choices stand out for making this practical rather than fragile. On the language model side, the extraction pipeline uses prompt engineering with few-shot examples and structured output parsing, so the system handles messy natural language input, including misspellings, without failing outright. On the simulation side, the numpy-vectorized Monte Carlo engine is what keeps thousands of scenarios across multiple goals running in near real time instead of taking minutes. Full documentation for the system, including the API reference, lives in the project's GitHub repository.
Key takeaways
- The system pairs a locally run Llama 3.1 model with FastAPI to turn a plain-English financial goal into structured, confidence-scored data.
- A custom Monte Carlo engine pulls real market data from Yahoo Finance via yfinance and uses numpy for fast, vectorized simulation.
- Three decoupled REST endpoints (health, goal extraction, simulation) mean the backend can plug into mobile apps, spreadsheets, or chatbot tools like n8n.
- The results view reports a success probability alongside median, worst-case, and best-case outcomes and an expected shortfall.
- Adding a second goal shows how combined targets can drop a success rate to zero, and how a specific contribution increase can recover it.
- Prompt engineering with few-shot examples keeps goal extraction resilient to typos and casual phrasing.
Try it yourself
If you're comfortable with FastAPI, Ollama, or Monte Carlo methods in Python, the project's GitHub repository has the full documentation needed to set this up locally, including the API reference for building your own front end on top of it. Anyone curious about how natural language processing and financial simulation can work together should find the walkthrough a useful starting point.
Full transcript(auto-generated, with timestamps)
[0:00]Hello everyone, my name is Daran and today I'm excited to walk you through the Microsoft goal extraction and simulation system, an airpowered investment planning platform that combines natural language processing with Monte Carlo simulations to help users plan their financial future. This is basically a fullstack application featuring a fast API backend with Olama LLM integration and a modern React front end with real-time data visualization. So let's dive in. Uh the architecture follows a clean separation of concerns. Uh on the back end we have a fast API serving three main endpoints. Uh health checks, goal extraction and Monte Carlo simulation. Uh the goal extraction pipeline uh uses Olama running Llama 3.1
[0:45]For natural language understanding. Users can describe their goals in plain English and the LLM extract structured data with confidence scoring. For simulations, I built a custom Monte Carlo engine that pulls real market data from Yahoo Finance uh using the Y Finance library uh which is free to use uh and it calculates portfolio statistics across thousands of scenarios to generate success probabilities. And the front end is basically a React app with white and tailwind CSS uh that features recharge for uh interactive visualizations. Uh so I've created this detailed API documentation uh that covers all the endpoints, requests and uh possible examples of how just the back end could
[1:33]Be used. Uh this is important uh because these rest API endpoints are completely decoupled from the front end. Uh which means that they can be integrated into uh any application. So whether you want to build a mobile app uh integrate with Excel or use it as a chatbot in some other backend service such as nitin uh which is what we've been using for other projects here at Microoft. You can just use these uh endpoints and it should work just fine. Uh also uh fast API creates uh these interactive documentations. Uh here uh you can see three main endpoints. the health checks, the goal extraction and the simulation. Uh this
[2:18]Just makes it easy for uh other developers to integrate without looking at the source code since uh each of these are providing all the parameters and how they need to be executed and also shows the response body if your uh backend service is running. Uh now uh let's just see this in uh action through the users perspective. So this is the front end. Uh as you can see it's divided into three section which is one is for extracting goals, one is for configuring and the other is uh just to view the results. So for goal extractions uh let's say uh the users here have to describe their financial
[2:57]Goals in natural language. Uh there's no form, there's no jargon, there's no uh detailed format they need to follow. They just have to type it out. So let's say uh the goal is something like I want to retire in 20 years with 1.5 m and I can save 5,000 monthly also. I'll just keep it as it is because we are using a LLM to do the understanding. It should just take care of all the typos that come with natural language. Uh once we click extract go uh it calls the backend API and automatically computes all the results and uh pre-populates the configure file form here. Uh you can see all the
[3:52]Details are over here. Uh if you want to change these these are configurable. The asset allocation is assumed to be standard. Uh but if you want to change just make sure this is adds up to 100%. And then these are the simulation configurations which are pretty standard but if you want to adjust for inflation you could change the inflation rate as well. So yeah uh once this done you can just run the simulations and yeah so here are our results uh in step three view results. Uh at the top uh you see the overall uh portfolio metrics uh the success is 100%. Uh for achieving the
[4:35]Goal with uh the combined target being 1.5 million. Uh you can see these uh for this goal you can see the breakdown for median outcome the worst case the best case and the expected shortfall. Uh an interactive chart to see percentile scores which are also important and then a few recommendation in case uh the goal was uh not possible. Uh this was just for one goal but if you want you could add another goal. Uh let's say the target amount is this timeline is again 15 years current savings let's say there are 45,000 and we run the Monte Carlo. This will take into account both of the uh goals
[5:24]And you can see as like it was just uh too much for the configuration that we had set. you'll see the success rate is zero and it still calculates all the outcomes in the worst case uh scenarios and gives some recommendations. So the current recommendation is to increase the contribution by about 3500. Let's just try doing that to see how the thing works 4,000 and if we run the simulation now you can see the success rate shows up to 99.9%. Uh so uh let me just highlight a few technical details here that makes this system very uh robust. Uh first the LLM integration uh we've
[6:10]Used proper prompt engineering with few short examples and structured output passing. Uh so it won't fail and because it's natural language uh it will take care of all the uh typos and misspellings in the uh user input. Uh next the Monte Carlo uh uses numpy for vectorzed computation making it efficient. As you can see 10,000 uh simulations uh sorry a thousand simulations over two goals took barely even a second. So uh as you can see uh the uh documentation for the system is on the Microsoft GitHub repository. So, uh, if you have any trouble setting this up for yourself or just have any questions in general,
[6:55]Uh, you can contact me. My details are at the bottom. Thank you so much.
More videos
2:08Bridging the Pixel Gap in Browser Automation.
2:23How One Narrow Safety Rule Can Make an AI Less Safe Everywhere Else.
2:04Why splitting a chunk from its document makes it retrieve for the wrong question
4:20Three You Can Take Back. One You Can't.
2:21Why a 50-turn agent pays for the same screenshot 35 times unless it caches the pixels
1:53