Sample probabilistic forecasting with Envision

Sample probabilistic forecasting with Envision












Home » Resources » Here

The script below illustrates how probabilistic forecasts can be produced, first for leadtime, second for demand. The forecasts are persisted to a Ionic data file. The Ionic 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"
read "/sample/Lokad_PurchaseOrders.tsv" as PurchaseOrders
read "/sample/Lokad_Orders.tsv" as Orders

path:="/sample/"

// Forecasting lead time distribution with purchase orders history
LeadTime = call forecast.leadtime(
  category: Brand, Category, SubCategory
  supplier: Supplier
  offset: 0
  present: (max(Orders.Date) by 1) + 1
  leadtimeDate: PurchaseOrders.Date
  leadtimeValue: PurchaseOrders.DeliveryDate - PurchaseOrders.Date + 1
  leadtimeSupplier: PurchaseOrders.Supplier)

// Forecasting demand using varying lead times and sales history
// (in practice, the ordering leadtime needs to be factored in as well)
Demand = call forecast.demand(
  category: Brand, Category, SubCategory
  horizon: Leadtime
  offset: 0
  present: (max(Orders.Date) by 1) + 1
  demandDate: Orders.Date
  demandValue: Orders.Quantity)

// Persisting the distributions into a Ionic data file
show table "Distributions" export:"\{path}Lokad_Distrib.ion" with Id, Demand

//Extending the demand distribution into a grid
table Grid = extend.distrib(Demand)

show table "Grid" with
  Id
  Grid.Min as "Min"
  Grid.Max as "Max"
  Grid.Probability as "Probability"