
In the retail industry, Inventory Management systems often employ a fixed, rule-driven approach to forecasting and replenishing stock.
Considering the demand distribution, the objective is to build a replenishment policy to minimize ordering, holding and shortage costs.
How do I use Python to optimize this policy?
In a previous article, we built a simulation model assuming a deterministic constant demand (Units/Day).
In this article, we will improve this model and introduce a simple methodology using a discrete simulation model built with Python.
The objective is to test several inventory management rules assuming a normal distribution of customer demand.
SUMMARY
I. Scenario
1. Problem Statement
As an Inventory Manager of a mid-size retail chain, you are in charge of setting the replenishment quantity in the ERP.
2. Limits of the deterministic model
What could be the results with a normally distributed demand?
II. Continuous Review Policy: Order Point, Order Quantity (s, Q)
1. Introduction of the Inventory Policy
2. Definition of the Safety Stock
3. How do you define k?
III. Example of replenishment policies
1. Target of CSL = 95%
2. Target of IFR = 99%
III. Conclusion
1. Move to Periodic Review Policies
To reduce the number of replenishments
2. Generative AI for Inventory Management
A smart agent to select the best inventory management rule
3. Product Segmentation with Python
Focus on items that bring turnover for your inventory rules
Scenario
Problem Statement
You are supporting the Inventory Manager of a mid-size retail chain.
She is in charge of setting the replenishment quantity in the ERP.
Based on the store manager’s feedback, you start to doubt that the ERP’s replenishment rules are the most optimal, especially for fast runners, because your stores are facing lost sales due to stock-outs.
How can you test these rules using Python?
For each SKU, you would like to build a simple simulation model to test several inventory rules and estimate the impact on:
Performance Metrics
- Cycle Service Level (CSL): probability to have a stock-out for each cycle (%)
- Item Fill Rate (IFR): percentage of customer demand met without 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
# Order Quantity
Q = 82 (units/order)
To simplify the comprehension, let’s introduce some notations

Limits of the deterministic model
In the previous article, we assumed demand to be constant and deterministic; to get closer to real demand, we’ll introduce randomness.

What could be the results with a normally distributed demand?

µ_D = 2000 (items/year)
σ_D = 50(items/year)

You need to improve your replenishment policy to compensate for the volatility of your demand.
Have you heard about the inventory turnover KPI? Learn more about it in this short clip,
Continuous Review Policy: Order Point, Order Quantity (s, Q)
Introduction of the Inventory Policy
To solve this issue of demand volatility, we’ll introduce a continuous review policy (s, Q)
- Continuous Review: the inventory level will be checked every day
- (s, Q) = If the inventory level ≤ s, your ERP will order Q
To simplify the comprehension, let’s introduce some notations:

Definition of the Safety Stock
The reorder point can be defined as the minimum inventory level you need to meet your customers’ demand during the lead time between your ordering and receiving.
The safety stock **** is a buffer to compensate for the volatility of the demand.
How do you define k?
The safety stock level will directly impact your performance metrics; the highest k is the best your performance will be:
- You fix your target for any of the two metrics (e.g, I want my CSL to be 95%)
- You calculate k to reach this target
- You fix your reorder point
Example of replenishment policies
Target of CSL = 95%
Based on the definition of the CSL, we have:

k = 1.64
Reoder point with CSL: 36 units

Comments
In this example, we can see that we do not face any stock and the minimum stock level is very close to zero.
Code
Target of IFR = 99%
In this previous example, our target was to have 95% of the replenishment cycles without stock-out.
In this example, we’ll focus more on our capacity to deliver products in full with an IFR target.
This formula uses the Unit Normal Loss Function (you can find more information about this function here: Link).


# G(k) = Q/sigma_ld * (1 - IFR)
IFR = 0.99
G_k = (Q/sigma_ld) * (1 - IFR) = 0.14
# Final value of k
k = 0.71
Reoder point with CSL: 31 units

Comments
To reach 99% of demand units fulfilled without stock-out you need a lower safety stock. (31 units vs. 32 units)
Code
You can find the full code in my GitHub repository 👇
GitHub – samirsaci/inventory-stochastic: Inventory Management for Retail – Stochastic Demand
Conclusion
This improved model brings better results by considering the demand variability in the safety stock sizing.
Let’s summarize the workflow.
Fix your performance metrics targets (IRF, CSL), then calculate your safety stock level using the k value.
The main issue with the continuous review policy is the high number of replenishments if you have many SKUs in your portfolio.
The store manager would prefer to fix the replenishment time with, for instance, two times per week.
What if we want to have periodic replenishment?
If you want to avoid investing energy in continuously reviewing your inventory level and control when you replenish, you should opt for the periodic review policies.
For more information,
Inventory Management for Retail – Periodic Review Policy
Have you heard about Generative AI?
Simulation Model with ChatGPT – "The Supply Chain Analyst"
Large Language Models like GPT can support the analysis of your inventory management rules and interact with users.
What is the optimal rule to minimize my ordering costs?
In this article, I introduce a custom GPT designed to automate supply chain analytics tasks.

This initial prototype is a proof of concept.
OpenAI’s GPTs can be used with advanced analytics models in Python scripts to create interactive analytics products.

We can imagine users uploading their sales and interacting with the agent to understand how to set an optimal rule.
For more details,
Create GPTs to Automate Supply Chain Analytics
Leveraging LLMs with LangChain for Supply Chain Analytics – A Control Tower Powered by GPT
What if you don’t have ressources to monitor all your products?
Product Segmentation for Retail with Python
The workload can quickly become unmanageable for a large retailer with 10k+ unique active references and multiple stores.
What is your focus?
You want to ensure that important items with high turnover do not face any stock-out.

This is why you can get support from Product Segmentation methodologies.
The objective is to focus on essential products with unstable demand to design advanced inventory management rules.
For more details on how to implement this methodology,
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