Forecasting leadtime and demand

The script below illustrates how probabilistic forecasts can be produced, first for leadtime, second for demand. The forecasts are persisted to a Ionic file. The Ionic file format is required because regular flat files - e.g. CSV - don’t support the direct export of the distribution data type. Finally, the distributions are extended into a grid.

/// Probabilistic forecasts both for leadtime and demand
read "/sample/Lokad_Items.tsv" as Items [Id] with
Id : text
Category : text
SubCategory : text
Brand : text
Supplier : text
LeadTime : number
 
read "/sample/Lokad_Orders.tsv" as Orders expect [Id, Date] with
Id : text
Date : date
Quantity : number
 
read "/sample/Lokad_PurchaseOrders.tsv" as PO expect [Id, Date] with
Id : text
Date : date
DeliveryDate : date
Supplier : text
 
path = "/sample/"
 
// Forecasting lead time distribution with purchase orders history
Items.Leadtime = forecast.leadtime(
category: Items.Brand, Items.Category, Items.SubCategory
supplier: Items.Supplier
offset: 0
present: (max(Orders.Date) by 1) + 1
leadtimeDate: PO.Date
leadtimeValue: PO.DeliveryDate - PO.Date + 1
leadtimeSupplier: PO.Supplier)
 
// Forecasting demand using varying lead times and sales history
// (in practice, the ordering leadtime needs to be factored in as well)
Items.Demand = forecast.demand(
category: Items.Brand, Items.Category, Items.SubCategory
horizon: Items.Leadtime
offset: 0
present: (max(Orders.Date) by 1) + 1
demandDate: Orders.Date
demandValue: Orders.Quantity)
 
// Persisting the ranvars into a Ionic data file
show table "Ranvars" write:"\{path}Lokad_Ranvars.ion" with Id, Demand
 
//Extending the demand ranvar into a grid
table Grid = extend.ranvar(Items.Demand)
Grid.Probability = int(Items.Demand, Grid.Min, Grid.Max)
 
show table "Grid" with
Id
Grid.Min as "Min"
Grid.Max as "Max"
Grid.Probability as "Probability"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
User Contributed Notes
0 notes + add a note