ranvar.periodicr

ranvar.periodicr, function

def pure ranvar.periodicr(
    start: date,
    end: date,
    horizon: ranvar,
    date: date,
    quantity: number,
    censoredDemandDate?: date)  : ranvar

Returns, for each item, the ranvar of the sums of quantity over periodic moving windows between start and end. One window starts on each non-censored day. The window length is distributed according to horizon, so the resulting ranvar is the probability-weighted mixture of the periodic windows associated with each supported horizon length.

Example

table Items[id] = with
  [| as id, as Start, as End, as Lead |]
  [| "A", date(2024,1,1), date(2024,1,5), 2 |]

table Orders = with
  [| as MyId, as Date, as Qty |]
  [| "A", date(2024,1,1), 2 |]
  [| "A", date(2024,1,3), 1 |]

expect Orders.id = Orders.MyId

Items.R = ranvar.periodicr(
  start: Items.Start,
  end: Items.End,
  horizon: dirac(Items.Lead),
  date: Orders.Date,
  quantity: Orders.Qty)

show table "Periodic mean" with
  id
  mean(Items.R) as "Mean"
  valueAt(cdf(Items.R), 0) as "P<=0"
  valueAt(cdf(Items.R), 1) as "P<=1"
  valueAt(cdf(Items.R), 2) as "P<=2"

This outputs the following table:

id Mean P<=0 P<=1 P<=2
A 1.2 0.2 0.6 1

This function computes, for each item, the ranvar of sums over all 2-day windows on the periodic cycle Jan 1st - Jan 5th. With events of 2 units on Jan 1st and 1 unit on Jan 3rd, the observed periodic windows are:

Thus, the resulting ranvar is 20% Q = 0, 40% Q = 1, 40% Q = 2.

When using the censoredDemandDate argument, the censored days are removed from the cycle before the periodic windows are built. Using the previous example, if Jan 2nd is censored, the cycle becomes Jan 1st - Jan 3rd - Jan 4th

Thus, the resulting ranvar is 25% Q = 0, 25% Q = 1, 25% Q = 2, 25% Q = 3.

Remarks

When horizon is a dirac ranvar, the window size is fixed. When horizon assigns positive probability to several lengths, ranvar.periodicr returns the mixture of the periodic-window ranvars associated with those lengths.

Unlike ranvar.segment, ranvar.periodicr has no step argument: a window starts on every non-censored day of the cycle.

The arguments date, quantity, and censoredDemandDate, when present, are typically supplied from downstream event tables related to the item table through a secondary dimension.

See also

User Contributed Notes
0 notes + add a note