Last Updated: Jan 22, 2026


Executive Summary

This algorithm executes a Hybrid Demand Forecasting Model. It combines a “Naive” historical average with a customized Holt’s Linear Trend method. The model de-seasonalizes historical data to identify underlying trends, projects those trends forward, and then re-applies seasonality, marketing events, and growth factors to generate a daily demand schedule for the next Lead Time + Coverage window.

INFO

Type: Deterministic / Time-Series Forecast
Core Method: Holt’s Linear Exponential Smoothing (with Damped Trend)


Inputs & Configuration

The algorithm requires a strict operational context to function.

Operational Data

  • History: Array of daily sales units (ordered by date).
  • StartDate: The anchor date for the simulation.

Configuration Object (options)

ParameterDefaultDescription
leadTimeDays90Days to wait before stock arrives (Gap Analysis start).
coverageDays60Target days of stock to hold after arrival.
seasonalityProfile{}Key-Value map of Month Index (0-11) to Weight (e.g., 1.2 = +20%).
accelerationPercent0.1Weight given to the “Algo” vs “Naive” forecast.
skuGrowthRateWeekly0Compounding weekly growth factor.

Core Logic: The “Gap Analysis”

The function calculateGapInventoryTarget performs the heavy lifting. It transforms raw history into a future purchase recommendation through five distinct mathematical phases.

flowchart TD
    Raw[Raw Daily History] --> Aggregate[Aggregate to Weekly]
    Aggregate --> Deseason[De-seasonalize Data]
    Deseason --> Holts[Holt's Linear Smoothing]
    Holts --> Clamp[Safety Clamp Trend]
    Clamp --> Project[Project Future Days]
    Project --> Factors{Apply Factors}
    
    Factors --> |Seasonality| Reseason[Re-seasonalized]
    Factors --> |Marketing| Marketing[Lift Multiplier]
    Factors --> |Growth| Growth[Compounding Growth]
    
    Reseason --> Sum[Sum 'Gap' Demand]
    Marketing --> Sum
    Growth --> Sum
    
    Sum --> Blend[Blend w/ Naive Avg]
    Blend --> Final[Final Stock Target]

Phase 1: Aggregation & De-seasonalization

Daily data is too noisy for trend detection. We first aggregate daily units into Weekly Buckets (working backwards from the most recent date).

To isolate the “true” organic trend, we must remove known seasonality effects.
If December usually has 2x sales (weight = 2.0), a raw sale of 100 units is treated as a “normalized” sale of 50 units.

Phase 2: Holt’s Linear Smoothing (The Training Phase)

We use a double exponential smoothing method to track two components:

  1. Level (): The baseline volume of sales at time.
  2. Trend (): The direction and magnitude of change (slope) at time.

Hyperparameters

  • Alpha (α): The Level Smoothing Factor.
    A lower value makes the level less reactive to short-term spikes.
  • Beta (β): The Trend Smoothing Factor.
    A very low value ensures we only react to sustained, long-term shifts in direction.
  • Phi (φ): The Damping Factor.
    This decays the trend over time, preventing the model from projecting infinite linear growth forever.

Recursive Equations

For each week in the history:

  1. Update Level:
    Logic: The new level is a blend of the actual data we just saw () and our previous prediction ().
  2. Update Trend:
    Logic: The new trend is a blend of the recent change () and the previous trend ().

Phase 3: The Safety Clamp

Before projecting the future, we strictly limit the (Final Trend) to prevent “hallucinations” caused by recent outliers.

We calculate the Implied Weekly Growth Rate:

We then apply hard limits:

  • Max Growth: +5% per week.
  • Min Growth: -10% per week.

If the rate exceeds these bounds, the trend is forcibly overwritten:

Phase 4: Daily Projection Loop

The algorithm iterates through every day of the future horizon ( to ).

1. Trend Damping

The trend does not stay constant; it decays daily (applied weekly in code) to represent uncertainty.

2. Base Daily Value

We convert the weekly projected level back to a daily average.

3. Factor Application

We now re-apply the external factors to generating the Final Daily Demand.

  • Seasonality: The weight for the projected month.
  • Compounding Growth:
  • Marketing Lift: Iterates through marketingEvents. If date falls in window:

Phase 5: The “Gap” Summation

We only care about demand that occurs after the lead time (when the stock arrives) and before the coverage period ends.

The sum expected demand for each day, starting from day , until reaches

Phase 6: Confidence Blending

To mitigate risk for new products with sparse data, we blend the complex “Algo” forecast with a simple “Naive” average.

Confidence Score ():

Interpretation: It takes 26 weeks (6 months) to reach 100% confidence in the Algo.

Weighting:

Final Target:


Weeks of Supply Calculation

*Function: calculateWeeksOfSupply*

This is a deterministic depletion simulator. It answers: “Given inventory, on what specific date do I run out?”

The Algorithm

  1. Initialize Remaining = Inventory.
  2. Iterate through the DailyProjections array (generated in Phase 4).
  3. For each day with demand :
  • If :
  • If (Stockout): We calculate the partial day covered: BREAK Loop.
  1. Final Output:

  • Usage: Used in the Generate Forecast Per SKU workflow.
  • Source: calculateGapInventoryTarget function in the “Run Forecast Algorithm” node.