How to calculate Economic Order Quantity in Python

Learn how to calculate the Economic Order Quantity or EOQ for a product to minimise holding costs, shortage costs, and order costs.

How to calculate Economic Order Quantity in Python
Picture by Chuttersnap, Unsplash.
1 minutes to read

The Economic Order Quantity or EOQ represents the optimum purchase quantity for a given product, while aiming to minimise holding costs, shortage costs, and order costs. It’s most commonly calculated using a model known as the Classical EOQ Model.

The Classical EOQ Model assumes that the demand rate is constant and that replenishment is instantaneous and there are no shortages, which arguably isn’t particularly realistic, but it’s still pretty decent for many types of product.

There are several derivatives of the Classical EOQ Model, including the EOQ with Price Breaks model, which includes specific order volumes that generate the retailer a discount (something common in many markets). Other variants can cope with multi-item orders and limitations on storage among other things.

How to calculate Economic Order Quantity

import math

def eoq(demand_in_units, 
        cost_of_ordering, 
        cost_of_carrying):
    """Return the Economic Order Quantity (EOQ) for a product.

    Args:
        demand_in_units (int): 
        cost_of_ordering (float): 
        cost_of_carrying (float): 

    Returns:
        float: Economic Order Quantity or EOQ based on Classical EOQ model. 
    """
    
    return math.sqrt(((demand_in_units * cost_of_ordering) * 2) / cost_of_carrying)    
print('EOQ:', eoq(demand_in_units=12000, cost_of_ordering=100, cost_of_carrying=16))
EOQ: 387.2983346207417

Matt Clarke, Friday, March 12, 2021

Matt Clarke Matt is a Digital Director who uses data science to help in his work. He has a Master's degree in Internet Retailing (plus two other Master's degrees in different fields) and specialises in the technical side of ecommerce and marketing.

Intermediate Python

Level up your data science skills by creating visualizations using Matplotlib and manipulating DataFrames with pandas.

Start course for FREE

Comments