Level Up Coding
Published in

Level Up Coding

R for Industrial Engineers

Safety Stock and Reorder Point with R

Exploring the “SCperf” R package

Image by Flex available at Flex Website

Safety Stock

Safety stock is an additional quantity of an item or product held by a company to reduce stockouts risks caused by variability and uncertainty on the demand and supply. The safety stock is considered as a buffer in case the demand exceeds the forecasted sales and/or for when the company’s suppliers are unbale to deliver additional units at the expected time.

Having a safety stock involves additional holding costs. However, in order to justify it, its associated holding costs should be lower than the costs of not satisfying the demand, the costs for not delivering a customer’s order on time, and/or the production costs related with stoppages. The formula for calculating the safety stock can be expressed as:


  • md: mean demand
  • sd: demand’s standard deviation
  • SL: service level
  • L: lead time

Note: to get the F-1(SL) value, look up for its corresponding z value in the Standard Normal Distribution Function Table.

Reorder Point

The reorder point is the quantity of units in inventory that will trigger an order to purchase additional items — it can be considered as a threshold that companies should not go below. The reorder point indicates when to place a replenishment order. An ideal reorder point ensures that the company will not dip below the safety stock level. The formula for its calculation can be expressed as:

However, how can the optimum number of units per order be determined? By following the economic order quantity principle, companies can obtain the optimum number of items to be ordered that will minimize the holding and ordering costs while being able to satisfy the demand requirements.

The SCperf package from R contains specific functions for calculating the safety stock level and reorder point. For the following example, let’s consider the following values for obtaining the safety stock and reorder point: md= 10 units, sd= 2 units, SL = 0.95, and L = 5 days, respectively.

Let’s take look at the R code!


Now that the safety stock and reorder point unit values have been obtained, it would be interesting to plot the inventory depletion (assuming it is normally depleted) over time. For the following exercise, an initial inventory of 300 units will be considered.


As observed in the graph above, it can be stated that the safety stock and reorder point were correctly calculated since the inventory did not stock out, allowing the company to satisfy the demand at all time.

Concluding Thoughts

Inventory planning and managing represent a critical task for every organization and business on today’s highly competitive and fast changing world, which should be used as a competitive advantage to achieve optimum ordering and/or production levels while satisfying the demand.

The SCperf R package includes specific functions for calculating appropriate safety stock levels and reorder points based on the inventory depletion, and thus, the demand rate. Failing to calculate an appropriate safety stock level could lead to unsatisfied clients, economic losses and negative effects on the product’s brand and the company’s reputation. On the other hand, having an excessive safety stock level could lead to unnecessary risks and holding costs related with inventory managing. For this reason, studying — and understanding — the demand rate (i.e. its seasonality and trend) represents a critical task for supply chain analysts to be able to comply with the company’s goals and objectives.

While there are other inventory planning and managing software available, R represents a great tool for obtaining relevant information for simple inventory planning and managing tasks. Having stored a safety stock and reorder point calculation R code in your personal code library could save you a significant amount of time by just having to input the initial values of their corresponding variables.

— —

If you found this article useful, feel welcome to download my personal codes on GitHub. You can also email me directly at rsalaza4@binghamton.edu and find me on LinkedIn. Interested in learning more about data analytics, data science and machine learning applications in the engineering field? Explore my previous articles by visiting my Medium profile. Thanks for reading.

- Robert



Coding tutorials and news. The developer homepage gitconnected.com && skilled.dev && levelup.dev

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store