---
name: price-demand-optimization
description: >
  Optimizes unit prices, segmented pricing, non-linear pricing (two-part tariffs, bundling),
  dynamic markdowns, and capacity allocation (EMSR) for revenue management. Use when asked
  to: find the optimal price, model demand elasticity, design discount structures, plan
  markdown schedules for perishable inventory, allocate fare class capacity, or optimize
  bundle pricing. Also trigger when someone says "price optimization", "demand elasticity",
  "markdown schedule", "clearance sale pricing", "fare class allocation", "EMSR",
  "two-part tariff", "bundling strategy", "price segmentation", "willingness to pay",
  "revenue management", "dynamic pricing", "stockout price", or "Littlewood rule". Always
  renders inline HTML dashboard as primary output. Includes marketer NBA and benchmarks.
metadata:
  author: Axiom Nexar / Polanyi
  version: 1.0.0
  reference: Katsov, Introduction to Algorithmic Marketing, Ch. 6 §§6.4–6.8
---

# Price & Demand Optimization

Revenue optimization across five method families: demand modeling → unit price → segmentation
→ dynamic markdowns → capacity allocation (EMSR). Always outputs dashboard + marketer NBA.

---

## Plain Language: What This Does

```
"How should I price this product?"          → Unit price optimization (§6.5.1)
"Should I offer student/senior discounts?"  → Market segmentation (§6.5.2)
"Subscription + per-use fee?"               → Two-part tariff (§6.5.3)
"Bundle products A and B?"                  → Bundling optimization (§6.5.4)
"Plan a 4-week clearance sale?"             → Markdown LP (§6.7.2.2)
"How many business vs economy seats?"       → EMSR (§6.8)
```

**The core insight (Katsov §6.5.2):**
Every single price leaves money on the table — customers who would pay more, and customers
who won't buy at this price but would at a lower one. Segmentation captures both.

---

## Core Equations (Katsov Ch. 6)

### Demand Models (§6.4)
```python
# Linear demand (uniform WTP, eq. 6.11):
q(p) = Qmax * (1 - p/P)

# Constant-elasticity (eq. 6.13):
q(p) = C * p^{-ε}       # ε = price elasticity

# Logit demand (eq. 6.15):
q(p) = Qmax / (1 + exp(a + b*p))   # S-curve, max sensitivity at -a/b

# Elasticity definition (eq. 6.9):
ε = -(p/q) * dq/dp
```

### Unit Price Optimization (§6.5.1)
```python
# Optimal price, linear demand (eq. 6.24):
p_opt = (P + V) / 2         # average of max WTP and variable cost

# Optimal price, constant-elasticity (eq. 6.28):
p_opt = V * ε / (ε - 1)     # requires ε > 1

# Optimal profit (eq. 6.26):
G_opt = Qmax * (P - V)² / (4P)
```

### Market Segmentation — n Segments (§6.5.2)
```python
# Optimal price for segment i (eq. 6.34):
p_i* = [(n+1-i)*P + i*V] / (n+1)   # equally spaced between P and V

# Optimal segmented profit (eq. 6.35):
G_opt = Qmax * n*(P-V)² / [2*(n+1)*P]   # → Gmax as n → ∞
```

### Two-Part Tariff (§6.5.3)
```python
# Homogeneous demand — optimal metered price (eq. 6.40):
p_m* = V     # set metered price to marginal cost

# Entrance fee = consumer surplus under demand curve (eq. 6.37):
p_e* = Qmax * (P - p_m)² / (2P)

# Heterogeneous demand — adjusted metered price (eq. 6.44):
p_m* = V + P * (E[k] - 1)   # E[k] = weighted avg demand multiplier
```

### Markdown LP — Perishable Inventory (§6.7.2.2)
```
maximize    Σ_t Σ_i z_it * P_i * q(P_i, t)
subject to  Σ_t Σ_i z_it * q(P_i, t) ≤ C        [capacity]
            Σ_i z_it = 1   for each t              [one price per period]
            z_it ≥ 0
```

### EMSR Heuristics (§6.8.4)
```python
# Littlewood's rule — two classes (eq. 6.104):
y_opt = F1_inv(1 - p2/p1)    # protect y units for class 1

# EMSRa (eq. 6.112–6.113):
y_j = Σ_{k=1}^{j} y_{j+1}^(k)    # sum of pairwise Littlewood levels

# EMSRb (eq. 6.114–6.116):
Q_j_agg = Σ_{k=1}^{j} Q_k        # aggregate demand
p_j_agg = Σ p_k*E[Q_k] / Σ E[Q_k]  # weighted avg price
y_j from: p_{j+1} = p_j_agg * Pr(Q_j_agg ≥ y_j)
```

---

## Algorithm Selection

| Scenario | Method | Script |
|---|---|---|
| Single price, estimate P and V | Unit price optimizer | `price_unit_optimizer.py` |
| Multiple customer segments | Segmented pricing | `price_segmentation.py` |
| Subscription + per-unit billing | Two-part tariff | `two_part_tariff.py` |
| Bundle two+ products | Bundle optimizer | `bundling_optimization.py` |
| Clearance / seasonal markdown | Markdown LP | `markdown_linear_program.py` |
| Airline/hotel fare classes | EMSR-a & EMSR-b | `emsra.py` / `emsrb.py` |
| Competing products | Joint pricing | `competing_products_optim.py` |
| Fit demand curve to data | Demand model fitting | `demand_logit.py` |

---

## Workflow

### Step 1 — Fit Demand Model
```bash
python scripts/demand_logit.py \
    --price-data data/price_volume.csv \
    --output results/demand_params.json
```
Output: fitted Qmax, a, b (logit) or P, elasticity (linear/const-elasticity).

### Step 2 — Run Price Optimizer
```bash
# Unit price
python scripts/price_unit_optimizer.py \
    --P 100 --V 10 --Qmax 1000 --output results/unit_price.json

# Segmented (n=3 segments)
python scripts/price_segmentation.py \
    --P 100 --V 10 --Qmax 1000 --n-segments 3 \
    --output results/segmented_price.json
```

### Step 3 — Markdown Schedule (perishable inventory)
```bash
python scripts/markdown_linear_program.py \
    --demand-params results/demand_params.json \
    --capacity 700 \
    --price-levels "89,79,69,59,49" \
    --weeks 4 \
    --output results/markdown_schedule.json
```

### Step 4 — EMSR (airline/hotel)
```bash
python scripts/emsrb.py \
    --fares "300,200,100" \
    --demand-means "8,12,20" \
    --demand-stds "2,3,5" \
    --capacity 20 \
    --output results/emsr_protection_levels.json
```

### Step 5 — Render Dashboard + Insights
```bash
python scripts/export_price_dashboard_json.py \
    --optimizer-type markdown \
    --results results/markdown_schedule.json \
    --output dashboard_data.json
```

**Output sequence:**
```
1. [bash_tool] Fit demand + run optimizer
2. [web_search] Industry pricing benchmarks (elasticity, markdown lift, ARPU)
3. [bash_tool] export_price_dashboard_json.py → JSON
4. [show_widget] Dashboard: demand curve, price vs profit, markdown schedule, EMSR levels
5. [text] CMO/marketer insights + NBA (Next Best Actions)
6. [text] Caveats: elasticity uncertainty, segmentation leakage, EMSR assumptions
```

---

## Output Format — Visualization First

**Primary output: inline HTML dashboard. Always render before text.**

Dashboard panels (see `references/price_dashboard_template.html`):
1. **KPI bar** — optimal price, expected profit, % improvement vs current price, targeting depth
2. **Demand curve** — q(p) with optimal price marked + profit rectangle
3. **Segment price ladder** — bar chart of n segment prices P_1..P_n
4. **Profit vs price** — parabola showing G(p) with p_opt annotated
5. **Markdown schedule** — weekly price plan with capacity pacing
6. **EMSR protection levels** — stacked bar of fare class allocations

---

## Marketer Insights Layer (MANDATORY)

### Search before benchmarking
```
web_search: "price elasticity [industry/category] benchmark [country] [year]"
web_search: "markdown optimization retail lift revenue [year]"
web_search: "revenue management hotel airline EMSR improvement [year]"
```

### Translate Metrics to Business Language

| Technical output | Business meaning |
|---|---|
| p_opt = $X | "Charge $X to maximize profit — not the lowest price, not the highest" |
| n=3 segments: $74, $62, $50 | "3-tier pricing captures 75% of max possible profit vs 67% with one price" |
| Markdown wk1=$89, wk4=$49 | "Start high, end low — early buyers pay premium, clearance buyers get deal" |
| EMSR y1=7, y2=13 | "Hold 7 first-class and 13 economy seats, release discount only when 1st fills" |
| ε=2.3 | "10% price cut → 23% demand increase. Elastic market — discounts work" |
| ε=0.4 | "Even 50% price cut barely moves demand. Inelastic — don't discount" |

### NBA — Next Best Actions for Marketers/CMOs

Always produce 5–6 specific, actionable recommendations:

**Template (adapt to context):**
- **Elasticity first:** "Measure your true price elasticity before optimizing — a 0.5 error in ε leads to prices ranging $21–$110 for the same product (Katsov Table 6.2)"
- **Segment fences:** "Perfect segmentation requires impermeable fences. Check for leakage (Table 6.3): 500 high-value customers buying the discounted tier erases all gains"
- **Markdown timing:** "For perishable inventory: start at stockout price, decrease evenly to variable cost (eq. 6.87). Never discount before week 2 if demand is high"
- **Two-part tariff:** "If you have heterogeneous usage levels, metered price > marginal cost (eq. 6.44). Subscription + overage charges beat flat pricing"
- **Bundle test:** "Bundling only outperforms individual pricing when WTP is negatively correlated across products (Fig. 6.13). Test with segmentation data first"
- **EMSR lead time:** "Open discount fares early (booking in advance = low-fare), protect high-fare capacity for late buyers. EMSR closes discounts automatically"

### Connect to Business Objectives (Katsov §3.2)

| Pricing strategy | Business objective | When to use |
|---|---|---|
| Unit price optimization | Maximization — extract margin | Established product, stable demand |
| Market segmentation | Acquisition + Maximization | Heterogeneous market, strong fences |
| Dynamic markdown | Retention (clear inventory, keep loyalty) | Seasonal, fashion, perishable goods |
| Two-part tariff | Maximization — usage-based capture | SaaS, utilities, amusement parks |
| EMSR | Maximization — capacity revenue | Airlines, hotels, event tickets |

---

## Key Caveats

- **Elasticity estimation uncertainty:** Small errors in ε produce huge price swings (Table 6.2). Always report confidence intervals on ε.
- **Demand cannibalization:** Imperfect segmentation fences leak high-value customers to lower tiers (Table 6.3). Model leakage K before committing to segmented prices.
- **Markdown irreversibility:** Prospect theory (§6.3.2) — customers anchor to the first price they see. Don't discount too early; it permanently lowers the reference point.
- **EMSR independence assumption:** EMSR assumes independent demand across fare classes. In reality, rejected low-fare customers upgrade. This inflates protection levels.
- **LP relaxation:** Markdown LP allows fractional prices (z_it ∈ [0,1]). Round to nearest practical price point.
- **Bundling requires negative correlation:** If WTP for A and B are positively correlated, bundling does not help (Fig. 6.12 vs 6.13).

---

## Integration with Agency Growth OS

| Skill | Handoff |
|---|---|
| `audience-segmentation-brief` | Segment willingness-to-pay distribution → p_i* per segment |
| `response-uplift-modeling` | Personalized discount depth via uplift × price sensitivity |
| `measurement-incrementality` | Price test A/B → causal estimate of elasticity |
| `margin-simulation` | p_opt + G_opt feed P&L model |
| `crm-journey-architect` | Markdown schedule → trigger CRM messages per pricing phase |

---

## Reference Files

- `references/katsov_price_excerpts.md` — Key equations §6.4–6.8 + numerical examples
- `references/model_selection_price.md` — Which optimizer for which business scenario
- `references/industry_benchmarks_price.md` — Elasticity ranges + markdown lift benchmarks
- `references/price_dashboard_template.html` — HTML dashboard; inject `SKILL_DATA_JSON`
