Demand and Sales Forecasting: From History to a Plan
Train the model on history. Check against the standard. Link demand, sales and inventory.
Modelled engineering case. Developed by ITTECHE to analyze architecture and solutions. Company, educational data and calculations; the confirmed result of client implementation is not declared.
Build a demand forecast at the product and warehouse level, compare it with a simple standard, calculate the sales scenario in rubles and prepare a replenishment draft. Each recommendation requires data version, horizon, validation error, price, discount, availability, expected delivery, and reason for manual revision.
Go to demo
From the business task
to a verifiable solution.
In a model trading company, the buyer plans replenishment based on the sales of the last weeks. Some goods are growing, some are sold in rare large orders. Zeros could mean no demand, a closed store, or out of stock. The average sales rate alone confuses these situations and poorly explains the next purchase.
- weeks of synthetic history
- 24
- three checks for four weeks
- 3 × 4
- weeks of educational forecast
- 8
- different types of demand
- 2
- 01
Restore the observed process
Sales, returns, balances, availability and calendar are reduced to one week and units. Shortage periods are marked separately; lost demand is not guessed from zero sales.
- 02
Train and compare
Next to two simple methods, regression with regularization is trained. Based on the previous history, five coefficients are estimated: level, trend and three cycle corrections. The structure and penalty are fixed in advance.
- 03
Check for future periods
The story is cut off at several points. The model uses only information known at the forecast date; the result is compared with subsequent observations.
- 04
Convert volume to sales
The quantity forecast is linked to availability and selling price by product and channel. Promotions, discounts, returns and cancellations are set explicitly; the total in rubles is checked against the weekly lines.
- 05
Create a replenishment plan
The forecast for the protection period is compared with available stock, supplies and commitments. Batch, budget and warehouse restrictions are discussed separately with the buyer.
How are demand, sales and inventory related?
Two synthetic series of 24 weeks and three methods: loop repeat, loop with shift and trained ML regression. Each of the three checks builds a four-week forecast using only the previous history. The model is retrained on each slice.
Where AI fits in and what it learns
The ML model selects five coefficients based on the history of the selected product: a base level, a trend, and three adjustments for the phases of a four-week cycle. This is regression with regularization, one of the machine learning methods. The coefficients are calculated from the data; ready-made answers are not included in the page.
In each test, the model is trained on only weeks 1–12, 1–16, or 1–20 and predicts the next four weeks. For release in weeks 25–32, it is retrained on all 24 observations. Change the product - the trained coefficients, forecast and errors will change.
MAE ML: 1.25 pcs/week; standard: 3; cycle with shift: 1. ML is better than the standard, but inferior to the shift method. You need to choose a method based on verification.
What the model learned
Full release model shown: 24 weeks, five coefficients. Feature structure and penalty λ = 0.1 are set in advance and are not selected according to test weeks. A free member is not penalized. The forecast is rounded to integers and limited from below to zero before errors are calculated.
- Basic level
- 21.0987
- Trend · week index / 24
- 17.1895
- Second phase amendment
- 5.4323
- Third phase amendment
- 1.7769
- Phase Four Amendment
- 8.4495
Formula: base level + trend coefficient × week index / 24 + current phase correction. The index starts from zero; the first phase is the basic one. Training minimizes the sum of squared errors with a penalty on the coefficients.
This is a small ML training example on synthetic data. The four-week cycle is predetermined; no annual seasonality found. Prices, promotions, and demand response to discounts are not included in the model. The neural network and language model are not used here. The result does not confirm accuracy on the real catalog or on weeks 5–8 of the horizon.
| Method | MAE, pcs./week | WAPE | Displacement, pcs./week |
|---|---|---|---|
| Repeat cycle | 3 | 7.9% | -3 |
| Cycle + level shift | 1 | 2.6% | 0 |
| ML regression | 1.25 | 3.3% | -1.25 |
MAE—mean absolute error; less is better. The bias is calculated as the forecast minus the fact. WAPE is the sum of absolute errors divided by the sum of actual errors; it can be higher than 100%, but if the sum is zero, the fact is not determined.
| Week | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
|---|---|---|---|---|---|---|---|---|
| Forecast, pcs. | 38 | 44 | 41 | 49 | 41 | 47 | 44 | 52 |
Sales forecast: pieces → rubles
Training scenario: all forecast volume is available and sold at one price, returns and cancellations are zero. Set the price and discount for the next eight weeks. Sales amount = quantity × price after discount.
- Volume for 8 weeks
- 356 units
- Price after discount
- 1,000 ₽
- Sales in 8 weeks
- 356,000 ₽
| Week | Volume, pcs. | Price after discount, ₽ | Sales amount, ₽ |
|---|---|---|---|
| 25 | 38 | 1,000 | 38,000 |
| 26 | 44 | 1,000 | 44,000 |
| 27 | 41 | 1,000 | 41,000 |
| 28 | 49 | 1,000 | 49,000 |
| 29 | 41 | 1,000 | 41,000 |
| 30 | 47 | 1,000 | 47,000 |
| 31 | 44 | 1,000 | 44,000 |
| 32 | 52 | 1,000 | 52,000 |
| Total | 356 | — | 356,000 |
Changing the price or discount here only changes the monetary scenario. The response of demand to price is not modeled. This is a sales revenue scenario, not a profit or cash flow schedule: costs, expenses and payment terms are not specified. The calculation is carried out in kopecks; the price after the discount is rounded to the nearest penny before multiplying by volume. The historical audit above estimates quantities, revenue accuracy has not been separately verified.
From forecast to draft replenishment
Training conditions: 70 units in stock, 10 units reserved; safety stock is set manually - 12 pcs. The order is reviewed once a week. The plan covers delivery time plus one week until next review.
- Protection period
- 3 weeks
- Demand for the period
- 123 units
- Stock item
- 100 units
- Draft order
- 35 units
Target stock: 123 + 12 = 135 pcs. Stock item: 70 + 40 − 10 = 100 pcs. Order: max(0, target stock − position).
This is a calculation based on prepared data, without sending an order. The safety stock is not derived from the probability of shortage; receipt dates within a period, batches, transport and warehouse capacity require a separate model.
How the forecast was checked without access to the future
Release points: after weeks 12, 16 and 20. For each, only data up to and including the cutoff is used; forecast for the next four weeks. The four-week windows tested do not overlap. The future eight values are recalculated from all 24 observations; their error is still unknown.
| History up to a week | Check week | Forecast | Fact | Forecast - fact |
|---|---|---|---|---|
| 12 | 13 | 28 | 30 | -2 |
| 12 | 14 | 34 | 35 | -1 |
| 12 | 15 | 31 | 33 | -2 |
| 12 | 16 | 38 | 41 | -3 |
| 16 | 17 | 32 | 32 | 0 |
| 16 | 18 | 38 | 40 | -2 |
| 16 | 19 | 35 | 36 | -1 |
| 16 | 20 | 42 | 43 | -1 |
| 20 | 21 | 35 | 36 | -1 |
| 20 | 22 | 41 | 41 | 0 |
| 20 | 23 | 38 | 39 | -1 |
| 20 | 24 | 46 | 47 | -1 |
Testing in the demo is limited to a four-week horizon. For a real replenishment policy, the aggregate demand for its protection period is additionally checked; One week's MAE does not replace this test.
History and formulas of the two methods
All observations are synthetic, chosen to explain the behavior of the methods. The four-week cycle is predetermined and is not a found annual seasonality. The standard repeats the last four values. The second method adds the difference in the means of the last two four-week blocks to each subsequent forecast block; the result is rounded to integers and bounded below by zero.
Horizons 1–4 receive one shift, 5–8 two. There are no future observations in the formula. The parameters of safety stock and balances are specified separately; probability intervals are not calculated here.
| Week | Quantity, pcs. |
|---|---|
| 1 | 20 |
| 2 | 28 |
| 3 | 24 |
| 4 | 31 |
| 5 | 24 |
| 6 | 29 |
| 7 | 27 |
| 8 | 35 |
| 9 | 26 |
| 10 | 34 |
| 11 | 30 |
| 12 | 37 |
| 13 | 30 |
| 14 | 35 |
| 15 | 33 |
| 16 | 41 |
| 17 | 32 |
| 18 | 40 |
| 19 | 36 |
| 20 | 43 |
| 21 | 36 |
| 22 | 41 |
| 23 | 39 |
| 24 | 47 |
From measurement -
to an explicable action.
- 01
ERP and sales
History of SKU × warehouse × channel × week: quantities, prices, discounts, returns, cancellations, shortages and deliveries.
- 02
Features and versions
Prices, calendar and promotions in versions known at the date of calculation; logs and units without leakage of the future.
- 03
Training and Prediction
Retraining ML at each time slice, comparing with standards and saving coefficients. In the educational interactive, only the trend and the specified cycle are trained; prices and promotions are the tasks of the future pilot.
- 04
Inventory planner
Protection period, stock position, delivery terms and confirmation by the purchaser.
Infrastructure, storage and integration periods are clarified during the survey. The event's identifier, time, source data, model version, and decision are saved.
The difficulty lies in the conditions
errors and verification.
Sales don't always equal demand
It’s easy to mistake a week without a product for a week without demand and fix the error in the next plan.
- Solution
- Link a row to availability history. Exceptions and methods of handling deficits should be agreed upon separately; the unknown cannot be converted into a reliable estimate.
- How to check
- Control periods for lack of goods, warehouse closures and returns. Demand forecast and observed sales forecast are assessed as different problems.
Volume and cash sales are verified separately
An increase in price can increase the amount of sales for the same quantity, while shortages, discounts and returns can reduce it. Accuracy in units does not prove accuracy of revenue.
- Solution
- Count sales based on available volume and price after discount, coordinating the processing of returns and cancellations. For a working forecast, take into account channels and check price scenarios; elasticity of demand is assessed separately.
- How to check
- The weekly totals add up to the grand total. The price and discount in the educational interactive do not change the volume. In the pilot, quantity and ruble forecast errors are assessed separately; revenue does not replace profit.
Checking without knowing the future
Randomly shuffling weeks or using the final adjusted promotional plan improves the report, but not the working forecast.
- Solution
- Capture temporary snapshots and check several successive horizons. Signs and transformations are calculated only from the history available for the slice.
- How to check
- Future observation change test: A previously issued forecast should not change. The verification horizon must correspond to the replenishment task.
Machine learning must earn a place in the plan
The trained model may lose to a simple rule. The ML name alone does not confirm accuracy.
- Solution
- In the demo, regression coefficients are trained separately on each slice. Metrics from the three methods, full release coefficients, and JSON with slice models and test predictions are available side by side.
- How to check
- On a regular MAE series: standard 3, cycle with shift 1, ML 1.25 pcs./week. On rare orders, ML loses to the standard and is blocked. These are the results of a synthetic example only, with no promise of improvement on client data.
Different products - different models
A method that is useful for regular growth can create false sales in a long string of zeros.
- Solution
- Separate regular and intermittent demand. Compare the seasonal standard, statistical models and trait-based models on the same sections; evaluate new products separately.
- How to check
- MAE in units, aggregated error, bias and results by segment. Good company-wide results should not hide the failure of individual groups.
Forecast and order - different solutions
Even an accurate forecast does not specify the batch size: there is stock, supplies, reserves, delivery time and shortage price.
- Solution
- Separate demand calculation from inventory policy. For a working solution, check the error distribution over the protection period, vendor restrictions, and the selected service level.
- How to check
- Historical reproduction of the policy under the same conditions: availability, shortfalls, average inventory and turnover. The percentage of error is not reported as a percentage of savings.
What needs to be confirmed
on real data.
Input quality
Completeness of balances and sales, units of measurement, history of SKU changes and signs of shortage. For each exception, the reason and decision of the data owner is stored.
Forecast quality
Checking by time and horizons, comparison with the standard, offset and errors by segments. For a probabilistic forecast, the actual coverage of the intervals is additionally checked.
Sales forecast quality
Reconciliation of prices after discounts, available volume, returns and cancellations by channel. Separate time checking of errors in rubles and reconciliation of weeks with the total; the fact of the future price is not substituted into the past forecast.
Plan quality
The first pilot forms recommendations next to the existing process. The effect is assessed on comparable demand and restrictions; The final purchases are confirmed by an employee.
Path from survey to transmission
- 01
Data and Business Rules
Series granularity, definitions of demand and shortage, decision horizon and basic process.
- 02
Training and backtesting
Standard, model training on each slice, saving parameters, segments and candidate selection criteria.
- 03
Sales and replenishment
Price and discount scenarios, sales in units and rubles; inventory position, deliveries and exception review.
- 04
Pilot and observation
Reconciliation with the buyer, drift control, model revision regulations and process transfer.
This is a sequence of work, not a promise of a deadline or budget. The assessment comes after checking the source data and integrations.
Where a solution is required
a different approach.
- 24 school weeks do not confirm annual seasonality. A real object needs a history that covers important cycles and process changes.
- Promotions, new products, replacements and rare large orders require separate verification. Accuracy on prepared rows is not automatically transferred to the catalog.
- The training safety stock is manually set and does not meet the promised service level. Orders are not sent to the supplier from the page.
Let's start with the data
and acceptance criteria.
For the first discussion the following are useful:
- History of sales, returns, cancellations and availability by product, warehouse and channel.
- History of prices and discounts; future prices and promotions in versions known at the forecast date.
- Balances, reserves and expected deliveries with date and quantity.
- Delivery times, batch rules and those responsible for sales and purchasing.