Skip to content
Tutorials Center
My learning

Topics

Lesson 45 of 50 ยท Projects

Project: A Sprint and Velocity Simulator

Build a Monte Carlo sprint simulator in JavaScript: a backlog, team capacity, random variation, velocity and a probability-based delivery forecast.

"When will it be done?" is the question every project hears most often, and the honest answer is a range, not a date. In this project you will build a small simulator of agile sprints. It has a backlog of stories with point estimates, a team whose capacity varies from sprint to sprint, and a random element for absences, interruptions and new work arriving mid-project. Run it once and you get a plausible project. Run it two thousand times and you get a probability distribution of finish dates, which is exactly what a good forecast looks like.

The earlier lessons gave you the vocabulary: story points, velocity and forecasting, the Scrum sprint and risk. The code is a JavaScript stand-in running in the browser console editor. The team, numbers and probabilities are invented to make a point: they are not data from any real team, and a real forecast must use your own history. The random numbers come from a small seeded generator, so every run of the examples prints exactly the same results.

Step 1: decide what to model

A simulator is a deliberate simplification. Decide first what matters for the question you are asking. Our question is "how many sprints will this backlog take?", so the model needs:

  • A backlog: an ordered list of stories, each with a size in points (1, 2, 3, 5 or 8, the usual Fibonacci-like scale).
  • A team: five people and ten working days per sprint. Each person-day yields about half a story point on average, with day-to-day variation.
  • Absence: each person-day has an 8% chance of being lost to illness or leave.
  • Interruptions: in 35% of sprints something unplanned (a production incident, an urgent meeting) costs 5 points of capacity.
  • Scope growth: after each sprint there is a 50% chance that one new story of random size is added to the end of the backlog.
  • Rules of work: the team works down the backlog in order. Partly finished work carries over, but velocity counts only stories finished during the sprint, as in real Scrum.

Everything else is left out: people with different skills, dependencies between stories, bug work, holidays, learning. Leaving things out is fine as long as you say so; adding them later is a good exercise.

What the simulator models

Backlog Stories with point sizes.
Capacity People times days, with noise.
Randomness Absences, interruptions, new stories.
Output Velocity and finish date.

One run is a story. Many runs are a forecast.

1 / 2

Step 2: the random number generator

A simulation uses random numbers, but a teaching simulation must repeat exactly. A seeded pseudo-random generator does both: the numbers look random, but the same seed always gives the same sequence. The code below uses a tiny, well-known generator (mulberry32) and passes the function around as random, so each run of the model is controlled by one seed. Do not use it for security; it is for simulations only.

Passing the generator into every function that needs randomness is also a design choice: the model code does not call Math.random itself, so it can be tested and replayed. It is the same idea as injecting a clock into code that needs the time.

Step 3: simulate one project

The core function is runProject. Each loop iteration is one sprint: draw a capacity (sprintCapacity), apply it to the top of the queue, count stories finished, maybe add a new story, and record the sprint. Press run and read the table. The capacity column is the work the team could do; done is the points of stories actually finished; new is scope added after the sprint; remaining is points left including partial progress.

JS One simulated project

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Look at the table before reading further. Capacity wobbles between about 12 and 20 points, and velocity wobbles even more (from 1 to 19). Two things cause that. Early on, a story only counts when it is whole, so sprint 1 shows 10 points done although the team had about 14 points of capacity; the rest is partly finished work carried over. At the end, the backlog is nearly empty, so in sprints 9, 10 and 11 the team finishes whatever small story arrived last sprint and then has nothing left to do. The remaining work does not fall in a straight line either: new stories keep arriving, so a burndown chart bends and can even rise, which is why a single average hides how bumpy a real project is.

The run finishes after 12 sprints. Is that typical? You cannot tell from one run, which is the problem with a single plan or a single "simulation": it is one sample.

Step 4: forecast with many runs

The Monte Carlo method answers by repetition. Run the project 2,000 times with different random draws, record how many sprints each took, and look at the spread. The second program does that and compares the result with the naive forecast many teams use: divide the remaining points by average recent velocity (here 14, 18 and 16, so 16) and round up.

Two numbers describe the spread well. A percentile is the value below which a given share of the runs fall: the 85th percentile is the number of sprints within which 85% of runs finished. Stakeholders can then be told "50% likely by sprint 7, 85% likely by sprint 9", and each of those is a sentence they can plan around.

JS Monte Carlo forecast of the finish date

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The naive forecast says 6 sprints, and in the simulation only about 14% of projects finish that quickly. The central estimate is 7 sprints, 85% of runs are done by sprint 9, and 95% by sprint 11. Why is the plain-average forecast so optimistic? Three reasons are built into the model:

  1. Scope grows. The naive formula treats the backlog as fixed. Here the backlog gains about 2 points per sprint on average (half the sprints add a story of 3.8 points on average), which quietly eats roughly an eighth of the team's output.
  2. Variation is lopsided. Absences and interruptions can only subtract from capacity; nothing in the model adds a lucky bonus. A long project therefore rarely beats the average and often falls behind it.
  3. The tail. New stories arrive after every sprint, so the last story added is always finished in a sprint of its own, often a mostly empty one that still counts as a whole sprint. Partly finished stories also do not count as velocity until they are whole.

The exact numbers belong to this made-up team, but the lesson carries over: a single-number forecast ignores uncertainty, and the uncertainty is mostly on the late side. That is also what the cone of uncertainty says about early estimates.

Step 5: experiments to run

A simulator earns its keep when you use it to ask "what if?". Change one number at a time in the code above and re-run; because the seeds are fixed, any difference comes from your change.

  1. No scope growth: set creepChance: 0 in team. The distribution should move left and tighten. How much of the delay was scope growth?
  2. Fewer interruptions: halve interruptionChance. Compare the 85th percentile before and after: this puts a number on what a calmer sprint is worth.
  3. A bigger team: change people from 5 to 7. Does the finish date improve by the 40% more people suggest? Add a rule that new members reduce capacity for a sprint, as in "adding people to a late project makes it later".
  4. Split the large stories: replace the 8-point sizes by two 3-pointers. Does a better-sliced backlog improve velocity stability?
  5. Use real data: replace pointsPerDay and the probabilities with numbers from your own team's last ten sprints. This is the step that turns the toy into a tool.

When you present results, show the model's assumptions next to the numbers. A forecast is only as good as its inputs, and a simulator makes those inputs explicit, which is a real advantage over a plan that hides them.

What the project teaches

  • Velocity is an output, not a target. In the simulation nobody "decides" velocity; it emerges from capacity, variation and how work is sliced. Pushing a team to raise it usually inflates estimates instead.
  • Averages mislead. The average velocity of the single run was 11.1, below the 16 from the history, because the project included slow tail sprints.
  • Percentiles communicate risk. "85% likely by sprint 9" is more honest and more useful than "done in 6".
  • Models need validation. Compare the simulator's past predictions with what happened, and fix the assumptions that were wrong.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does the simulator use a seeded random number generator instead of Math.random()?

    A seeded generator produces the same sequence each time, so results can be replayed, compared and tested.
  2. 2. In this model, why can velocity in a sprint be much lower than the capacity of the team?

    Velocity counts the points of finished stories. A large story left half done adds to remaining work but not to that sprint's velocity.
  3. 3. What does 'the 85th percentile of finish time is 9 sprints' mean?

    A percentile is the value below which that share of the runs fall, so it states a probability, not a promise.
  4. 4. Why does the naive forecast (remaining points divided by average velocity) come out too optimistic here?

    The formula treats the backlog as fixed and capacity as steady, but real projects gain scope and lose capacity to interruptions, so they usually finish later.

Summary

  • A simulator models only what the question needs: a backlog, a team with variable capacity, random absences, interruptions and scope growth, and the rule that only finished stories count as velocity.
  • A seeded generator makes random simulations repeatable, and passing the generator into functions keeps the model testable.
  • One run shows how bumpy a project is, with velocity swinging and the burndown bending; many runs (Monte Carlo) produce a distribution of finish dates.
  • Percentiles turn that distribution into statements stakeholders can plan with, such as "50% likely by sprint 7, 85% by sprint 9".
  • The model's numbers are invented; the value comes from understanding why single-number forecasts are optimistic and from replacing the inputs with your own team's data.

Next: Project: A Requirements Traceability Tool.