ranvar.periodicr
ranvar.periodicr, function
def pure ranvar.periodicr(
start: date,
end: date,
horizon: ranvar,
date: date,
quantity: number,
censoredDemandDate: date): ranvar
Builds a ranvar by aggregating event quantities over moving windows whose
length is drawn from horizon. Compared to ranvar.segment, it treats the
series as periodic, so events near the edges are wrapped.
start: the first date (inclusive) for each item.end: the last date (inclusive) for each item.horizon: the ranvar of window lengths.date: the event dates.quantity: the event quantities.censoredDemandDate: optional dates to ignore.
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"
This outputs the following table:
| id | Mean |
|---|---|
| A | 1.2 |
Remarks
When horizon is a dirac ranvar, the window size is fixed. The periodic
behavior means windows that cross end wrap around to start.