Inspiration Retailers lose money twice: they markdown the wrong items, and stock sits in one store while another store in the same state stocks out. Most pricing tools either guess elasticity or ignore inventory entirely. MarginPulse connects the two — first it audits whether demand data can even be trusted, then it estimates price sensitivity properly, then it solves markdowns and transfers together as one optimization problem.

What it does MarginPulse is a full-stack retail operations platform built on the Walmart M5 schema (10 stores across CA, TX, WI; FOODS, HOBBIES, HOUSEHOLD; 12 SKUs x 10 stores = 120 series).

Stage 1 — Forensic audit: classifies every SKU-store series into Syntetos-Boylan regimes (Smooth / Erratic / Intermittent / Lumpy) using ADI and CV², detects zero-variance-price SKUs and locks them out of elasticity estimation, and flags stockout-censored runs so fake zero-demand days don't bias the model. On the built-in panel: 120 series, 100 estimable, 20 zero-variance, 70 stockout-censored, integrity score 74.2%.

Stage 2 — Elasticity: ridge-regularized log-log panel regression with store fixed effects, cross-SKU cannibalization, weekend and SNAP effects, and 100-iteration weekly block bootstrap for 95% confidence intervals. Validated on a 28-day temporal holdout: WRMSSE 0.606, MAE 6.01, 95% prediction-interval coverage 96.3%.

Stage 3 — Optimizer: multi-period MILP solved with scipy.optimize.milp (HiGHS branch-and-cut) — binary markdown tiers (0% / 10% / 20% / 30%), integer intra-state store-to-store transfers with exact flow conservation, markdown budget cap, and a service-level floor. Default run solves to proven global optimum (0.00% MIP gap) in ~1.2 seconds.

Results on the built-in panel, $4,500 markdown budget: net margin $75,014 to $90,989 (+$15,975, +21.3%), service level 91.65% to 98.49%, stockouts 3,186 to 593 units (2,593 prevented), 2,864 units rebalanced, budget used $4,404.44 of $4,500. A 7-point Pareto frontier shows the margin-vs-budget trade-off, so a manager can pick any budget and see the optimal plan for it.

How we built it Python + FastAPI backend with three engine modules (audit.py, elasticity.py, optimizer.py), a deterministic M5-schema panel generator in ingest.py (also supports loading real M5 CSVs), a single-file frontend (frontend_app.html) with audit, elasticity and optimizer views, and precomputed results in data/precomputed_state.json so the UI loads instantly. Tests in tests/test_engine.py verify audit counts, the zero-variance guard, MILP flow conservation, budget adherence, and intra-state transfer balance — both tests pass.

Challenges we ran into Censored demand was the hardest part — a zero-sales day can mean no demand or no stock, and treating them the same corrupts elasticity. The audit stage exists specifically to separate those cases before any regression runs. Zero-variance-price SKUs were the second trap: with no price variation there is nothing to estimate, so they are excluded rather than faked. Keeping the MILP exact (integer transfers, binary tiers, flow balance) while still solving in ~1 second took careful constraint design.

Accomplishments that we're proud of A provably optimal plan (0% MIP gap), not a heuristic; honest uncertainty (bootstrap CIs, holdout WRMSSE/MAE/coverage reported, not hidden); and a pipeline that refuses to fabricate elasticity where the data can't support it.

What we learned In retail data, the audit matters as much as the model. Most of the value came from deciding what not to estimate, and from solving pricing and inventory jointly instead of in sequence.

What's next for MarginPulse Deploy the FastAPI backend + frontend live, add real M5 CSV loading as the default path, add per-store markdown explanations, and extend the optimizer to cross-state transfers with transport costs.

Built With

Share this project:

Updates