Back to trackLesson 9 of 25

Startup Runway 4: Regimes That Last

Uses Only Free-Tier SpiceGrinder

Problem statement

Lesson 2.3 put the stress months into the calendar at random: each month was stressed with a one-in-ten chance, whatever had happened the month before. Real bad months are not like that. A customer leaves and the next one follows, a downturn lasts a quarter, a supplier problem takes weeks to clear. If one month in ten is stressed, the stressed months come in stretches.

So we keep everything lesson 2.3 had and change one thing, the order of the months. Ten percent of the months are stressed, a calm month is Normal(-5, 5) and a stressed month Normal(-35, 20.12), in $k, so month by month the cash flow still has a mean of -8 and a standard deviation of 12. The only difference is that a stressed month now tends to be followed by another stressed month. Three questions:

  • Does that change the chance of ruin, given that no single month looks any different?
  • Does it matter how long the stretches last?
  • Does the model now behave in a way that a reader of its output should watch out for?

The model

A row is no longer a year. In lessons 2.1 to 2.3 a row was a founder’s year and the twelve months inside it were twelve independent draws. A model like that cannot have memory between months: no node looks at the month before. What a node can do is hold a state for a random number of rows. A different sample in the collection does exactly that, samples/simulation/machine-reliability.xml. It makes one row per minute of a shift: a machine is up for a random time, then down for a random repair time, then up again, and when it is up it makes a Poisson number of units per minute. The parts:

  • Sequence counts 0, 1, 2, … and Calculate with mod(x[0], 2) turns that into a flag that alternates 0, 1, 0, 1: up, down, up, down;
  • two lengths are drawn: the up time is a Weibull rounded up to whole minutes, the repair time a Lognormal rounded up;
  • Switch picks one of the two lengths by the flag, so each period gets a state and a length;
  • Pool with countColumn draws a period once and then repeats it, one row per minute, for as many rows as the length says;
  • a second Switch uses the repeated flag to decide whether a minute makes units (Poisson) or none.

Run with 2,000,000 minutes and seed 7 (the model’s own), the machine is down in 10.20% of the minutes (batch standard error 0.10), against 10.16% from the exact mean up and repair times. The completed up stretches average 216.3 minutes (8,302 of them, standard error 1.6) against 217.2 by the exact sum for the rounded-up Weibull, and the repair stretches 24.58 (standard error 0.18) against 24.55. We use the same pattern for the runway, with one tick per month.

The runway with regimes. Calm and stressed periods alternate, and each month inherits the state of the period it belongs to:

  • PeriodIndex and StateFlag give the alternating flag, 0 for a calm period and 1 for a stressed one. Every run starts calm;
  • CalmLength is Geometric with p = 1/27: a calm stretch ends each month with probability 1/27, so it lasts 27 months on average. StressLength is Geometric with p = 1/3: a stressed stretch lasts 3 months on average;
  • Period is a Switch that gives each period a length, from the calm or the stressed distribution by the flag; Regime is a Pool with countColumn that repeats the flag once per month of the period;
  • Month is a Switch that draws the month’s cash flow from CalmMonth or from StressedMonth according to the regime: the same two Normals as the mix in lesson 2.3;
  • Flow keeps only the cash flow column, and the rest is lesson 2.2’s: Year gathers twelve consecutive ticks into a row, Balance makes the running balances from $120k, and LowPoint and Ruin add the lowest balance and the ruin flag (LowPoint has dimension="14" to make room for the two columns).
<dataset columns="balanceM1, balanceM2, balanceM3, balanceM4, balanceM5, balanceM6, balanceM7, balanceM8, balanceM9, balanceM10, balanceM11, balanceM12, lowPoint, ruin" seed="204">
  <root node="Ruin"/>
  <nodes>
    <Sequence name="PeriodIndex" start="0" step="1"/>
    <Calculate name="StateFlag" expression="y[0] = mod(x[0], 2)">
      <input name="PeriodIndex"/>
    </Calculate>
    <Geometric name="CalmLength" p="0.037037037037037035"/>
    <Geometric name="StressLength" p="0.3333333333333333"/>
    <Switch name="Period" key="0">
      <input name="StateFlag" role="input"/>
      <input name="CalmLength" value="0"/>
      <input name="StressLength" value="1"/>
    </Switch>
    <Pool name="Regime" countColumn="1" interleave="1">
      <input name="Period"/>
    </Pool>
    <Normal name="CalmMonth" mean="-5" sigma="5"/>
    <Normal name="StressedMonth" mean="-35" sigma="20.12461179749811"/>
    <Switch name="Month" key="0">
      <input name="Regime" role="input"/>
      <input name="CalmMonth" value="0"/>
      <input name="StressedMonth" value="1"/>
    </Switch>
    <Arrange name="Flow" columns="1">
      <input name="Month"/>
    </Arrange>
    <Redimension name="Year" dimension="12">
      <input name="Flow"/>
    </Redimension>
    ...                      Balance, LowPoint, Ruin: as in lesson 2.2
  </nodes>
</dataset>

The model is samples/simulation/cash-runway-regimes.xml, 14 nodes, well inside Free’s limit of 20. The regime carries over from one row to the next: if a stressed stretch is running at the end of one year it is still running at the start of the next. Run it like the others:

grind --count 1000000 cash-runway-regimes.xml

The first ten rows with the model’s own seed, 204 (you get exactly these values if you leave the seed alone). Beside the balance after month 12, the low point and the ruin flag is a picture of the year’s months with # for a stressed month, which comes from running the same seed with --node Month, the node that holds each month’s regime and cash flow:

RowMonth 12Low pointRuinMonths (# = stressed)
03.53.50.....##.....
157.757.70............
272.372.30............
3-49.5-49.51.....#......
417.517.50#...........
525.525.50......#.....
666.866.80............
773.873.80............
841.041.00.##........#
962.562.50............

Five of the ten years had no stressed month at all, which is more than lesson 2.3’s mix would give (about three in ten). Row 0 shows a stretch of two stressed months in the middle of the year; row 8 has a stretch of two near the start and a single stressed month at the end. Row 3 went below zero with a single stressed month, a bad one (-$68.8k) after calm months that ran worse than average (about -$9k a month instead of -$5k).

Is it still the same monthly cash flow?

The claim to check first is that the new model has the same monthly numbers as lesson 2.3. Grind --node Month prints the month itself, one value per tick. Here are 6,000,000 months (seed 204):

MeasureMeasuredWhat it should be
Share of stressed months0.10003 / (27 + 3) = 0.1
Mean monthly flow-7.997 (standard error 0.005)-8
Standard deviation of the monthly flow11.991 (ten chunks of 600,000: 11.925 to 12.024)12
Calm stretches, mean length26.99 months (200,065 completed)27
Stressed stretches, mean length3.000 months (200,065 completed)3
Lag-1 autocorrelation of the stressed flag0.62971 - 1/27 - 1/3 = 0.6296

Only completed stretches are counted in the stretch lengths. A run always ends in the middle of a stretch, and including that last, cut-short one would bias the average down a tiny amount.

The last row is the new thing. In lesson 2.3 the flag of one month told nothing about the next, an autocorrelation of 0. Here, given a stressed month, the next month is stressed with chance 2/3 (the stretch has not ended yet), against 1/10 for any month. The monthly flow inherits some of that persistence. Month by month this is exactly lesson 2.3’s mix; only the order of the months has changed.

A strip of 480 months as bars of monthly cash flow with the stressed months in rust, and below it the balance paths of the 40 years those months make; the years that contain a stressed month fall far and cross zero, the rest drift down gently

The figure shows 40 consecutive years of the model (rows 2,000 to 2,039 of seed 204): the 480 months as bars, and the 40 balance paths. Most paths are quiet. A rust line is a year with at least one stressed month, and every one of the nine years that went below zero had one.

The chance of ruin

Each model with 2,000,000 rows (years), starting from $120k. The regime model uses seed 204, the independent mix of lesson 2.3 its own seed 2032 and the Normal of lesson 2.2 seed 42. The numerical theory for the independent models is lesson 2.3’s, and for the regimes it is the new one explained in the check below:

Start $120kRuin within the yearStandard errorNumerical theory
Normal30.00%0.0329.98%
Independent mix25.55%0.0325.59%
Regimes, mean stretch 3 months23.39%0.0323.41%

Lesson 2.3 found that moving from the Normal to the independent mix lowered ruin at $120k, and this does it again: persistence lowers it a further 2.2 percentage points, to 23.4%. Now the $200k start. A copy of the model with every 120 + in Balance replaced by 200 + (made in a scratch directory, it is not another sample), the same seeds:

Start $200kRuin within the yearStandard errorNumerical theoryTimes the independent mix
Normal0.651%0.0060.646%0.34
Independent mix1.93%0.0101.93%1
Regimes, mean stretch 3 months8.34%0.0208.35%4.31 (theory 4.33)

The same arrangement that lowered ruin at $120k raises it more than fourfold at $200k, and 12.8 times the Normal’s (theory 12.9). Three models with the same mean and standard deviation of the monthly flow give a $200k founder ruin chances of 0.65%, 1.9% and 8.3%.

Dot plot on a log scale of the chance of ruin for the Normal, the independent mix and the regime model at a start of 120 and 200 thousand dollars: at 120 the dots are at 30, 26 and 23 percent, at 200 at 0.65, 1.9 and 8.3 percent

Why persistence moves ruin both ways

The monthly flow is the same, so the answer must lie in the year. The cleanest way to see it is to count the stressed months in each year. This table is from the same 2,000,000 years (seed 204; shares from the run, which the exact chain computation matches to within 0.0002), with the independent mix’s shares from the binomial and the ruin rates measured on the years in each row:

Stressed months in the yearShare of years, regimesShare, independentRuin at $120kRuin at $200k
059.4%28.2%0.03%under 0.005%
112.5%37.7%12.6%under 0.005%
29.1%23.0%50.4%0.70%
36.5%8.5%79.0%9.4%
44.5%2.1%92.4%32.4%
53.0%0.38%97.5%58.8%
6 or more5.0%0.05%99.6%88.4%

Persistence does not change how many stressed months there are, only how they are packed into years. With regimes, almost six years in ten contain none, and a few contain a lot: 5.0% of years have six or more stressed months, against 5 in 10,000 for independent months, and nearly every one of those years is ruined even from $200k.

At $120k the cash is in the middle of the distribution of the year. A year with none of the stressed months is almost never ruined, and there are twice as many such years with regimes (59% against 28%). What replaces the independent mix’s 38% of years with exactly one stressed month, a 12.6% risk, is mostly years with none, so the total goes down. At $200k the cushion survives up to two stressed months and falls to the third, so only years with three or more matter, and with regimes there are 19.0% of those against 11.1%, with a long tail of years that have far more than three. Six or more stressed months alone give 5.0% x 88.4% = 4.4 of the 8.3 percentage points.

There is a second way to say the same thing. The year-end balance changes by an average of -$96k over twelve months in all three models. For independent months its standard deviation is 12 x sqrt(12) = $41.6k (measured 41.57 for both the Normal and the mix). With regimes it is $65.4k (measured, 2,000,000 years; theory 65.5): the variance of each month is unchanged, but months in the same stretch move together, so their variances do not just add. Their covariances add on top.

Another way in: ruin depends strongly on the regime the year starts in. A year that starts in a calm month is ruined at $120k with probability 18.7% (measured 18.66% on the 90% of years that start calm; theory 18.68%), a year that starts in a stressed month with probability 66.0% (65.95% measured; theory 65.94%). At $200k the two are 6.0% and 29.5% (measured 5.99% and 29.51%, theory 6.00% and 29.46%). The old model had one number; this one has two, and which of them a year gets depends on a regime that comes from the year before.

How long is a stretch?

The mean length of 3 months was a choice. To see what it does, keep the share of stressed months at 10% and change only the length of the stretches. A stressed stretch of mean length L months goes with a calm stretch of mean 9 L: StressLength gets p = 1/L, CalmLength p = 1/(9 L). Each variant is a scratch copy of the sample with the two probabilities rewritten (and 200 for the start where needed), run with 2,000,000 rows and seed 204. Simulated first, the exact theory in brackets:

Mean stretch (months)Ruin at $120kRuin at $200kTimes the independent mix at $200kYear-change standard deviation
125.37% (25.38%)1.31% (1.31%)0.6839.3
225.19% (25.20%)5.90% (5.92%)3.0555.2
323.39% (23.41%)8.34% (8.35%)4.3165.5
619.16% (19.12%)10.55% (10.56%)5.4682.2
1215.40% (15.38%)10.93% (10.92%)5.6594.7
independent25.55% (25.59%)1.93% (1.93%)141.6

(The last column is exact theory.) The standard error is 0.03 percentage points at $120k and between 0.007 and 0.03 at $200k.

Chance of ruin against the mean length of a stressed stretch on log axes: at a start of 120 thousand dollars it falls from 25 to 15 percent as stretches grow from 1 to 12 months; at 200 thousand it rises from 1.3 percent to 8.3 percent at 3 months and levels off near 11 percent

So if the founder’s stress stretches lasted 6 months instead of 3, at $200k ruin would rise from 8.3% to 10.6%: a quarter more, and 5.5 times the independent mix’s. The exact curve flattens out after that, peaks around a mean of 12 months at 10.9%, and is a little lower again for stretches of 24 months (10.7%). Longer stretches do not keep adding risk. The 10% of stressed months stay 10%, so beyond a point the year is either all calm or all stressed.

A stretch of 1 month is the curiosity in the table. A stressed month is never followed by another, which spaces them out more evenly than independent draws do, and a year with several stressed months becomes rarer. Ruin at $200k is 1.31%, lower than the independent mix’s 1.93%. Less clustering than random gives less ruin at $200k, and more clustering gives more. At $120k it goes the other way once the stretches are longer than a month or two: ruin falls from 25.4% at one month to 15.4% at twelve, because more and more years have no stressed month at all.

All of this is in the companion page: pick the start and the mean stretch, see the measured and the exact chance of ruin, and the share of years by number of stressed months.

Do consecutive rows depend on each other?

Yes, a little. Since every earlier lesson relied on rows being independent, it’s good to address what changes.

Every run starts calm. The first period of a run is calm, so the first year cannot start in a stressed stretch. By theory its chance of ruin at $120k is 18.7% instead of the long-run 23.4%. To measure that, we need the first row of many separate runs: 3,000 runs with seeds 1 to 3,000, one row each. 17.5% of them (standard error 0.7) were ruined: close to 18.7%, nowhere near 23.4%. After a few years the run forgets the start (the regime’s memory fades by a factor of 0.63 each month, so by the second year it is below 0.5%). For a 2,000,000-row run the first row changes the average by about 2 parts in 100 million. For a ten-row sample such as the CSV in the repository, it is one tenth of the data.

The end of a run cuts the last stretch short, but cuts nothing inside a row. Every row has its twelve months, so no row is biased by where the run stops.

Neighboring rows are correlated. A year in which stressed months run into December often means a stressed January. Measured on the ruin flags of consecutive rows at $120k, the correlation is 0.0685 (seed 204, 2,000,000 rows). Six more runs with seeds 11 to 16 give 0.0695, 0.0686, 0.0700, 0.0693, 0.0703 and 0.0710: an average of 0.0698 (standard error 0.0003), and exact theory says 0.0703. At $200k it is 0.0407 against theory 0.0405. Between rows two or three years apart there is nothing (the correlations are within 0.0015 of zero), and in the independent models it is zero as well (0.0002 and 0.0005 measured, standard error 0.0007).

The size of the effect is small, but it has a use: the standard error from the binomial formula, sqrt(p (1 - p) / n), is a little too small when rows are correlated, by a factor of about sqrt((1 + r) / (1 - r)) = 1.07. For the ruin probability at $120k the binomial formula gives 0.00030 and the spread of 100 batches of 20,000 rows 0.00032. The standard errors for the regime runs in this lesson all come from the batches.

Check: do the numbers match the math?

There are five checks we can make to confirm this.

The monthly flow. The table above: share, mean, spread and autocorrelation of the flag are all within sampling noise of exact values. The mean of -7.997 is 0.6 standard errors from -8.

The ruin probabilities against exact theory. The theory is a Markov chain over (balance, regime): the balance is put on a grid of $0.5k, and the regime of each month chooses which Normal moves it; the probability then moves between calm and stressed by the chances 1/27 and 1/3 (for L months: 1/(9 L) and 1/L), and the probability that falls below zero is counted as ruin and removed. The start is the long-run mix, 90% calm and 10% stressed. The independent mix is the same chain with each month’s regime drawn afresh. A grid of $0.25k gives 0.23407 at $120k and 0.08349 at $200k, the same as $0.5k to the fifth digit. The regime model’s two headline numbers are 0.6 and 0.5 standard errors from theory (batch standard errors), the Normal’s and the mix’s four numbers are all within 1.3 standard errors, and the ten cells of the stretch-length table are within 1.5.

The year. The shares of years by number of stressed months are within 0.0002 of the exact chain values for every row of the table, ruin by starting regime within 0.1 percentage point of theory at $120k and 0.05 at $200k, and the standard deviation of the year-end change 65.44 against 65.51.

The comparison. The differences are far outside noise: 2.2 percentage points at $120k is about 48 standard errors of the difference, and the 6.4 points at $200k about 290. It matches the ratio of the exact numbers (4.33).

The model is valid and fits Free. ModelValidatorApp reports VALID for the sample: 14 nodes, against Free’s limit of 20. Pro has a Perturb component that does what Pool, the two Switch nodes and the index do here: it alternates a “normal” stream and a “disturbance” stream with given waiting and duration lengths. The same model with it has 9 nodes. Run with 2,000,000 rows and seed 2041 it gives a ruin chance of 23.38% (standard error 0.03) against 23.41% by theory.

What the model leaves out

The model has two states and every stretch length is Geometric, which is memoryless: a stressed stretch that has lasted five months is no closer to ending than one that has lasted one. A real downturn may have a more regular length. A stressed month’s size does not depend on how long the stretch has run, and the transition chances (1/27 and 1/3) and the two Normals are invented for the example; none of them was fitted to a business. The founder never reacts: a real one cuts costs after two bad months, which would stop the stretches from doing so much damage. The balance is still looked at once a month. And the model still has just one starting regime, calm. A third regime (a deep crisis, or a boom), or a regime that changes the cost of staying alive, would need more nodes: this one uses 15 of the 20 Free allows.

What this gives you: a way to build memory into a model with rows as ticks: a flag that alternates, random period lengths, a Pool to repeat each period, and a Switch to act on it; the check that the monthly flow has exactly the mean and spread of the model it replaces, and the one thing that does differ, the autocorrelation of the regime; and a result worth remembering. The mean and the standard deviation of the monthly flow, and even its whole distribution, do not tell you the chance of ruin. The order of the months does too. With the same 10% of stressed months, ruin at a $120k start goes from 25.6% (independent) to 23.4% (stretches of three months) and at $200k from 1.9% to 8.3%, and with stretches of six months it is 10.6%. And a result to watch for: once a model has memory, its rows are no longer independent, so a run starts in a made-up state, and error bars should come from batches or from several seeds.

That raises a question that has been in the background for four lessons. Every number in this module came with a check against exact theory, and the checks all passed. Most simulations have no exact theory to check against, and a model can pass every check we have used so far, because they only ask whether the code does what we meant, and still be a poor picture of a real business. The next lesson separates the two questions, whether we built the model right (verification) and whether it is the right model (validation), and asks how a simulation can be compared with history.