Dynamic PricingClickHouse Workshops
Dynamic pricingDynamic pricing · Reference

Prepared demand model

Understand the demand assumptions without training a model during the workshop.

Votre ordinateur
Terminal macOS : Exécutez les commandes de l’atelier dans le Terminal avec zsh ou bash.

Production scope

A production team can build training datasets from ClickHouse transaction history and additional features such as prices, promotions, availability, calendars, store/product attributes, and weather. Appropriate ML tools train and validate the chosen demand or revenue model. This workshop supplies its model; production feature engineering, algorithm selection, training, deployment, and retraining are outside the exercises.

Training and validation

The prepared model uses independent synthetic calibration observations with randomized permitted prices and ample stock. A constrained Poisson fit estimates demand by SKU and store group with nonpositive price elasticity and calendar/exposure offsets. Censored observations are excluded. Chronological train, validation and test periods prevent a random split from mixing later outcomes into training.

The release artifact records parameter coverage, calibration metrics, and markdown/keep-price checks. The workshop installs that versioned artifact; learners inspect its assumptions and run SQL rather than train it.

SQL inference

Historical sales with complete availability provide a reference selling rate. Recent observed sales adjust that rate within bounded factors. The fitted elasticity adjusts demand for each permitted price. ClickHouse expands the price grid across weighted demand scenarios, caps every scenario at stock, then sums expected units, receipts, waste, and recovery.

The unchanged price is always included. With ample excess stock, a markdown can improve modeled recovery. With little stock, the unchanged price can win because a discount cannot sell more than the available units. The stock-20/stock-4 SQL example in Module 03 demonstrates both cases.

Observed synthetic outcomes

The unapproved-product feed allocates a configured transaction budget across stocked store/SKU pairs using reference popularity, the district demand multiplier, and a fixed price-response weight. These weights are normalized across the available products. Reducing one district's demand shifts its share of that workload; it does not automatically halve the whole chain's configured transaction rate.

After approval, the selected store/SKU leaves that ordinary feed and uses paired generation. The generator reuses the baseline demand captured with the approval inputs, scales it to each batch's share of remaining time before expiry, and uses a known elasticity of −2, rather than the prepared model's fitted elasticity:

old-price mean for this batch = captured baseline × batch duration / captured time until expiry
approved-price mean = old-price mean × (approved price / old price)^−2

A shared uniform random draw is converted into a Poisson count for each mean. Each count is capped by its own stock balance. Every sold unit becomes a stored synthetic transaction row, with a branch and receipt ID. Applied rows update operational stock; unchanged-price rows update only the separate comparison balance. A fixed seed makes the draws repeatable for the same seed and sequence.

ClickHouse stores these generated rows and computes the observed series. The prepared forecast and generated events are distinct outputs, but they share captured baseline inputs, so this is not an independent validation of predictive accuracy. Remaining units become waste only at expiry.

Limits

Synthetic calibration validates the teaching scenario, not elasticity in a real retailer. Scenario weights are sensitivity assumptions, not confidence intervals. Real deployments need demand support, stockout handling, price experiments, cost validation, monitoring, and business review. The highest modeled permitted price is not a guarantee of optimal real-world profit.

See pricing/model-card.md and the installed retail artifact's validation metrics for the preparation details.

Sur cette page

FR