Introduction to Reordering Point (ROP) Calculation in R
In this article, we will explore the concept of Reordering Point (ROP) calculation and how it can be implemented in R. The Rounding Point is a critical component in inventory management systems, as it helps businesses determine when to restock or reorder their products.
What is Reordering Point (ROP)?
The Reordering Point (ROP) is the quantity of an item that should be reordered before a business runs out of stock. It is calculated based on various factors such as lead time, order cost, holding costs, and demand uncertainty. The ROP calculation helps businesses balance the need to hold enough inventory to meet customer demand with the risk of overstocking and unnecessary costs.
Factors Affecting Reordering Point (ROP)
There are several factors that affect the Reordering Point calculation:
- Lead Time: The time it takes for an order to arrive at the store.
- Order Cost: The cost associated with placing an order, such as shipping or handling fees.
- Holding Costs: The cost of holding inventory in stock.
- Demand Uncertainty: The uncertainty surrounding customer demand.
Calculating Reordering Point (ROP) in R
In this article, we will use the example provided by Stack Overflow to calculate the Reordering Point using R. We will follow these steps:
- Prepare the data
- Create a data.table
- Calculate forecast sum for each delivery date
- Create a vector of ordering dates
- Calculate result for each ordering date
Step 1: Prepare the Data
To begin, we need to prepare our data in R. We will create vectors for the ordering dates, delivery dates, and forecasts.
# Set seed for reproducibility
set.seed(1)
# Define variables
sim_days <- 30
start_Date <- as.Date("2022-01-01")
seq_days <- seq.Date(start_Date, start_Date + sim_days, by = "days")
OD <- c(0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1)
DD <- c(0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0)
Forecast <- c(100, 230, 300, 417, 170, 414, 430, 331, 320, 121, 172, 161, 340, 234, 369, 274, 351, 447, 233, 372, 427, 174, 328, 143, 193, 235, 104, 233, 404, 219, 268)
Expected_Result <- c("","", "1014", "", "1202", "", "293", "907", "", "877", "","","", "1032", "","","", "572", "","","")
Step 2: Create a Data.table
Next, we will create a data.table in R to store our data.
# Create a data.table
df <- data.table(
date = seq_days,
OD = OD,
DD = DD,
Forecast = Forecast
)
Step 3: Calculate Forecast Sum for Each Delivery Date
Now, we will calculate the forecast sum for each delivery date. This involves adding up the forecast values from the current delivery date to the next delivery date.
# Add forecast sum for each delivery date
df[, ind := cumsum(DD)]
df[, fsum := sum(Forecast), ind]
df[, fsum := fifelse(ind != shift(ind, -1), fsum + shift(Forecast, -1), fsum)]
df[, fsum := max(fsum, na.rm = T), ind]
Step 4: Create a Vector of Ordering Dates
We will create a vector of ordering dates using the data.table.
# Create a vector of ordering dates
od <- df[OD == 1, date]
Step 5: Calculate Result for Each Ordering Date
Finally, we will calculate the result for each ordering date by taking the forecast sum from the current delivery date where DD == 1 and OD != 1.
# Calculate result for each ordering date
df[OD == 1, result := lapply(od, function(o) df[DD == 1 & date > o, fsum][1])]
Conclusion
In this article, we have explored the concept of Reordering Point (ROP) calculation and implemented it in R using a data.table. We covered various steps involved in calculating ROP, including preparing data, creating a data.table, calculating forecast sum for each delivery date, creating a vector of ordering dates, and calculating result for each ordering date.
References
- “Reordering Point” - Wikipedia
- “Inventory Management” - Investopedia
Last modified on 2024-05-10