Charlie KrugThe Build Log

← All posts

A stock, a deadline, a batting slump: the same three sliders.

Skein runs thousands of Monte Carlo paths live from three sliders. A stock return, a slipping deadline, and a hitter regressing to the mean are all one equation with different labels.

A project deadline that keeps slipping, a stock's monthly return, and a hitter cooling off toward his career average look like three problems for three different apps. They are the same three numbers: a middle, a spread, and how much today leans on yesterday. Skein is a Monte Carlo sandbox that lets you hold those three numbers in your hands and watch a thousand possible futures fan out across the screen.

Why one canvas, no domain

Almost every tool that runs a Monte Carlo simulation locks it to a single domain. A finance app frames it as expected return and volatility; a project planner frames it as optimistic and pessimistic estimates. The math underneath is identical, but you can't carry the intuition from one tool to the next, and the simulation is usually hidden behind a static report: a table of percentiles, rendered once and left there. You never get to feel the shape of the uncertainty move as the assumptions move.

Skein strips the domain out entirely. Three sliders (mean, variance, correlation) drive an engine that sweeps a few thousand simulated paths in real time, with a fan chart, the 5/25/50/75/95 percentile bands, drawn over the raw threads. It assumes no statistics past two facts: higher variance means less certain, and correlation means today depends on yesterday.

Three numbers, three behaviors

Each path is an AR(1) process, a one-line recurrence: x[t] = mean + correlation * (x[t-1] - mean) + noise, where the noise is drawn from a Normal distribution with the variance you set. That single expression is more flexible than it looks. Set correlation to 0 and each step is an independent draw, pure scatter around the mean. Push it near 1 and the path clings to where it just was, wandering off in slow, mean-reverting swings. Push it negative and consecutive steps fight each other, giving you choppy oscillation. Independent noise, momentum, and chatter, all from one knob, with no domain-specific model bolted on for any of them.

The other decision that makes it feel alive is what the frame does when you drag. The vertical axis holds steady while you move the variance slider, so the cone of outcomes visibly opens and closes instead of the whole view rescaling to fit and looking like nothing changed. Turn volatility up and the fan widens under your cursor, in well under a second, no Run button and no spinner. The input and the output become the same gesture.

The presets are only labels

Here is the honest part. Skein ships presets called things like "volatile stock," "slipping timeline," and "streaky shooter," and it would be easy to assume each one runs different math. It doesn't. A preset sets the three slider values and swaps the copy, and that is all it does. The simulate() function never checks which preset is active; there is no finance branch and no sports branch anywhere in the core. That restraint is the whole point. The moment the tool special-cases a domain, it stops being a lens on uncertainty and quietly becomes a finance calculator wearing costumes.

Under the hood the simulation core is pure TypeScript with zero DOM dependency, unit-tested for seeded reproducibility and for the statistical properties you'd want (it converges to the configured mean, and the spread scales with variance). The only D3 piece is d3-random for the seeded Gaussian noise. Everything else, the value-to-pixel scales and the percentile-band geometry, is hand-rolled so the canvas can draw thousands of strokes at 60fps without a charting library in the way.

Try it

Open Skein and drag the variance slider up. Watch the cone widen in real time, then pull correlation toward 1 and see the paths start to wander in long runs instead of scattering. Load the "volatile stock" preset, nudge the numbers, and notice that nothing about the picture knows or cares that it's a stock. The full scenario lives in the URL, so when you find a shape you like, the link reproduces it exactly, or one click exports it as a PNG.

Skein is live. Free, in your browser, no signup.

This post is part of the build log: every app my automated factory ships gets written up here, honestly. Browse everything at apps.charliekrug.com. Comments are open below.

Comments

Loading comments…