Forecasting for Fun and Profit š¤
For the remainder of the year, I will simulate the process of running the inventory replenishment decisions of a store. If work has taught me anything, itās that you look differently at your forecast model when it decides day after day how money is spentāand doesnāt just fill cells in Excel. Unfortunately, thatās not often the topic of academic research. But I have a bunch of loosely connected ideas about business forecasting that Iād like to bring to paper, and the worked example of a store and its replenishment decisions will serve as the connective tissue.
To make replenishment decisions, I will first of all need to simulate a store that sells products and replenishes them to keep them on stock. With shopr
, I have written a small package that models a simple world in which every day a store faces demand, sells products from inventory, and decides how many products to replenish. More on that below.
While you can run simulations with shopr
as fast as your computer letās you, I will simulate the replenishment decisions in real time: The iterations of the simulated world will be daily, from January 1 through December 31 of 2015. On the first day of every month I will publish a report that summarizes the profit and loss and cash flow achieved by the store in the previous month.1
Compared to simulating the entire year at once, proceeding in this step wise fashion will give me opportunity to make changes to the forecast method and inventory optimization and observe the changesā impact. The step wise approach is also closer to the real-world where performance is observed over time and period-over-period changes raise questions. That should spark some discussions.
I have published the first report earlier today, summarizing the month of January.
In it youāll find financials of a store called āFF&P Storeā. It sells 1,906 different emojis (some to be released in the future). Reading tables of top sellers and out-of-stock products becomes just so much easier when it comes with product imagery.2
Private Label | Sales Price | Purchase Price | Holding Cost | Delivery Days | |
---|---|---|---|---|---|
š no one under eighteen | no | $2.4 | $0.5 | $0.1 | 5 |
š¦ microbe | yes | $1.1 | $0.1 | $0.1 | 41 |
š¦š¶ flag Antarctica | no | $6.9 | $3.9 | $0.1 | 5 |
š see-no-evil monkey | no | $2.5 | $0.7 | $0.1 | 3 |
š¤ money-mouth face | no | $1.7 | $0.5 | $0.0 | 8 |
The storeās financials are an aggregation of productsā observed sales, productsā prices, and the costs for purchasing products and holding them on inventory. The prices, costs, and the demand underlying the sales are the input data to the simulation and can either be generated in shopr
or passed to it from existing tables.
For this simulation, I use some of the daily sales time series released in the M5 competition as historical sales and future demand, and the accompanying prices as sales prices. Thatās a useful set of data to demonstrate fairly common real-world scenarios. I extend the demand and sales prices by purchase prices and holding costs. Additionally, I generate starting levels of inventory and delivery lead times for each material.
With that data as input, the simulation proceeds as follows:
For each day from January 1 through January 31:
- Receive previously ordered shipments
- Update inventory
- Observe sales by comparing demand against inventory
- User: Derive forecasts from historical sales
- User: Optimize replenishment given forecasts and inventory
- Open orders given replenishment decisions
A nice feature of shopr
is that it stores the daily state of inventory, orders, and sales in partitioned parquet files. Using arrow
in the background, itās efficient to analyze the resulting data both during the iterations (e.g.Ā when comparing forecasts and inventory) as well as at the end when preparing the monthly report.
While forecasts and replenishment decisions motivate this whole exercise, the key determinant of the financial results is the storeās business model: How frequently can we order products? Do we need to buy different products at once? Are there minimum order quantities? What delivery lead times do we have with suppliers? For data scientists these tend to be fixed constraints provided by others, but when simulating we need to choose each one.
The current version of shopr
does take delivery lead times into account and the emoji store will replenish some products at shorter lead times and others, the private brands, at longer lead times. But shopr
does not yet constrain the frequency, size, and cost of orders in any way. Thatās unrealistic and I will adjust it in future iterations to make the optimization problem more interesting.
This then is also the final message: The work has only begun. Consider this a conversation starter and expect more to come soon.3
Like those Mastodon accounts posting what happened on the same day during World War II.ā©ļø
Credit where credit is due: The unicode-emoji-json project has come in handy as tabular overview of all emojis with basic metadata.ā©ļø
A bloggerās famous last words.ā©ļø