How to model demand over lead time

This guide shows how to simulate demand over a random lead time using a minimal ISSM and Monte Carlo sampling.

Use the playground script if you want a preloaded session.

/// Illustration of the demand integrated over the lead time

present = date(2021, 8, 1)
keep span date = [present .. date(2021, 10, 30)]
 
Day.Baseline = random.uniform(0.5 into Day, 1.5) // 'theta'
alpha = 0.3
level = 1.0 // initial level
minLevel = 0.1
dispersion = 2.0
 
Day.Q = each Day scan date // minimal ISSM
  keep level
  mean = level * Day.Baseline
  deviate = random.negativeBinomial(mean, dispersion)
  level = alpha * deviate / Day.Baseline + (1 - alpha) * level
  level = max(minLevel, level) // arbitrary, prevents "collapse" to zero
  return deviate
 
show linechart "A sample demand trajectory" with Day.Q

L = 7 + poisson(5) // Reorder lead time + supply lead time

montecarlo 500 with
  h = random.ranvar(L)

  Day.Q = each Day scan date // minimal ISSM
    keep level
    mean = level * Day.Baseline
    deviate = random.negativeBinomial(mean, dispersion)
    level = alpha * deviate / Day.Baseline + (1 - alpha) * level
    level = max(minLevel, level) // arbitrary, prevents "collapse" to zero
    return deviate

  s = sum(Day.Q) when (date - present <= h)
  sample d = ranvar(s)

show scalar "Raw integrated demand over the lead time" with d
show scalar "Smoothed integrated demand over the lead time" with smooth(d)

Run the script and verify:

User Contributed Notes
0 notes + add a note