
For most retailers, Inventory Management systems take a fixed, rule-based approach to forecast and replenishment order management.
Can we use python to define these rules?
The objective is to build a replenishment policy to minimize your ordering, holding and shortage costs.
- Ordering Costs: fixed cost to place an order due to administrative costs, system maintenance or manufacturing costs in (Euros/Order)
- Holding Costs: all the costs required to hold your inventory ** (storage, insurance, and capital costs) in (Euros/unit x time**)
- Shortage/Stock-out Costs: the costs of not having enough inventory to meet the customer demand (Lost Sales, Penalty) in (Euros/Unit)
In this article, we will present a simple methodology using a discrete simulation model built with Python to test several inventory management rules based on the assumption:
- Deterministic Constant Demand: D (Units/Year)
- Lead Time between ordering and replenishment (Days)
- Cost of shortage and storage (Euros/Unit)
SUMMARY
I. Scenario
Problem Statement
As an Inventory Manager of a mid-size Retail chain, you are in charge of setting the replenishment quantity in the ERP.
Objective
II. Build your Model
Economic Order Quantity (EOQ)
What is the best compromise between ordering and holding costs?
1. Visualize the current rule
2. Economic Order Quantity: Q = Q*
3. Include replenishment lead time
4. Real-Time visualization of Cost of Goods Sold (COGS)
III. Conclusion & Next Steps
1. Other inventory management rules assuming a stochastic demand
Continuous or periodic review policies in the cast that the demand is not deterministic
2. Machine Learning for Retail Sales Forecasting
How to use external demand drivers to better forecast the demand?
3. Product Segmentation for Retail using Python
Should we design advanced inventory rules for all references? No.
Scenario
Problem Statement
As an Inventory Manager of a mid-size retail chain, you set the replenishment quantity in the ERP.
Based on store managers’ feedback, you might wonder if the ERP’s replenishment rules are the most optimal.
Can we improve our store replenishment policies with Python?
Especially for fast runners, as your stores face lost sales due to stock-outs.
For each SKU, you would like to build a simple simulation model to test several inventory rules and estimate the impact on:
- Total Costs: How much does receiving and storing this product cost?
- Shortages: what is the % of lost sales due to stock-out?
In this article, we will build this model for,
# Total Demand (units/year)
D = 2000
# Number of days of sales per year (days)
T_total = 365
# Customer demand per day (unit/day)
D_day = D/T_total
# Purchase cost of the product (Euros/unit)
c = 50
# Cost of placing an order (/order)
c_t = 500
# Holding Cost (% unit cost per year)
h = .25
c_e = h * c
# Selling Price (Euros/unit)
p = 75
# Lead Time between ordering and receiving
LD
# Cost of shortage (Euros/unit)
c_s = 12
To simplify the comprehension, let’s introduce some notations

What do we want to achieve?
Objective
In this article, we will
- Visualize the current rule used by the store’s manager
- Calculate the Economic Order Quantity and simulate the impact
- Visualize the impact of lead time between ordering and receiving
- Real-Time Visualization of COGS for each rule
Let’s have a look at the model now.
Build Model
Economic Order Quantity (EOQ)
The theory behind the Economic Order Quantity (EOQ) used by many Inventory Optimization models is to find the optimal order quantity Q* that will be the best compromise between ordering costs and holding costs.
- A low order quantity will give you high ordering costs (increase the number of replenishment orders: D/Q) but will reduce your holding cost (reduce the average inventory level: (Q/2))
- The inverse for a high-order quantity

Comments
The chart above shows that the Total Relevant Cost (TRC) (total cost without the purchase cost cD) is minimum for *Q=400 units/order**.
TRC(Q*) = 5,000 Euros
Visualize the current rule.
The current rule is to order every 10 days the exact quantity needed to absorb the demand for 10 days.
This quantity is way lower than Q*, so we can easily understand that the TRC will be way higher than its optimal value:
TRC(10) = 100,062 Euros
To understand why let’s simulate the rule for a range of 365 days:

CommentsVery short replenishment cycles that multiply the number of replenishment orders.
Economic Order Quantity: Q = Q*
For each replenishment cycle, you order Q* = 400 orders, and you reorder when the inventory level is zero.

CommentsLonger replenishment cycles that reduce the number of orders by 7 times => lower TRC
Include replenishment lead time
What would the stock-out level be if we had a replenishment lead time of LD = N Days?

Comments With 25 days lead time between ordering and receiving we reach 140 units of stock-out quantity per replenishment cycle.
Real-time visualization of Cost of Goods Sold (COGS)
You need to speak their languages to convince your commercial team and the store managers.
You can prepare a simple visualization of the potential turnover with the COGS (here, we’ll exclude purchase costs COGS = TRC) to understand the impacts along the year.
Initial Rule

Comments COGS is mainly driven by the ordering costs because of the high frequency of reordering due to the low replenishment quantity.
EOQ Rule

_CommentsW_e see here that the Economic Order Quantity is providing a compromise between ordering costs and holding costs that drastically reduce the total COGS.
You can find the complete code in this GitHub repository
GitHub – samirsaci/inventory-deterministic: Inventory Management for Retail – Deterministic Demand
Conclusion
This simple modelisation inspired the design of a basic simulation model that shows the impact of customer demand on key performance metrics.
It gives you visibility on your ordering frequency, inventory level and the impact of lead times in your Supply Chain.
However, the initial assumption of constant deterministic demand is very optimistic.
In the following article, we’ll explore advanced inventory rules assuming a stochastic distribution of your demand.
- We will first implement a continuous review policy.
- We will then explore periodic review policies to limit the number of replenishments.
Inventory Management for Retail – Periodic Review Policy
How can we reduce the stock-outs when the demand is highly unstable? Improve forecasts
Machine Learning for Retail Sales Forecasting
Based on the last Makridakis Forecasting Competitions feedback, machine learning models can reduce forecasting errors by 20% to 60% compared to benchmark statistical models.
Discover the power of Machine Learning for retail sales forecasting combined with Inventory Management Rules.

A complete end-to-end approach would be to
- Combine the inventory rules discovered in this article with a powerful ML-based forecasting model.
- Find the optimal set of parameters to reduce future stock-outs and inventory costs.

Machine Learning will usually be your current model, especially if you have external demand drivers on hand.
For more information,
Machine Learning for Retail Demand Forecasting
Do you need to apply these advanced rules to your entire product portfolio?
Product Segmentation for Retail with Python
The answer is no. You can segment your products based on their importance.
Product segmentation refers to the activity of grouping products that have similar characteristics and serve a similar market.
In Logistics, attention is mainly focused on sales volume distribution, demand variability and **** delivery lead time.
As a Data Scientist for a Retail company, how can you automate this analysis with Python?

In another article, discover how you can use Python to segment your products based on
- Importance: how much turnover do they bring?
- Demand variability: how stable is their demand?
The idea is to focus on essential references with unstable demand to develop your forecasting and inventory tools.
For more details, have a look at this article
About Me
Let’s connect on Linkedin and Twitter. I am a Supply Chain Engineer who uses data analytics to improve logistics operations and reduce costs.
For consulting or advice on analytics and sustainable supply chain transformation, feel free to contact me via Logigreen Consulting.
If you are interested in Data Analytics and Supply Chain, look at my website.
💌 New articles straight in your inbox for free: Newsletter 📘 Your complete guide for Supply Chain Analytics: Analytics Cheat Sheet
References
- Supply Chain Science, Wallace J. Hopp