Computational Lab: From Economic Dispatch to Market Design¶
Course: Y1-02 Energy Economics and Market Fundamentals (optional extension; bridges to Y1-03 and Y2-04)
Model class: One convex clearing LP, extended one feature at a time
Data: Synthetic fleet, load shapes, demand bids and market parameters
Dependencies: Python 3.10+, NumPy, SciPy (HiGHS)
Status: Teaching model. It is not a production-cost model, a settlement engine, or a model of any real RTO or market rule.
Research question¶
The merit-order dispatch lab answers "who runs and what is the marginal price?" for one hour. This lab asks what has to be added to that LP before it says anything about market design: how carbon prices pass through, how demand response should be paid, why scarcity pricing exists, what storage does to the prices it was valued at, and why prices become locational. Each step adds exactly one feature to the same LP and states its economic interpretation, so every change in the results can be traced to one modeling choice.
The clearing model¶
For hours (t = 1..T) (one-hour intervals, so MW = MWh), zones (z), generators (i) in zone (z(i)):
[ \min \sum_t \Big[\sum_i (c_i + \tau e_i)\,p_{it} + \sum_z S\, s_{zt} - \sum_b v_b\, q_{bt} - \sum_k w_k\, x_{kt}\Big] ]
subject to, for every (z) and (t),
[ \sum_{i:z(i)=z} p_{it} + s_{zt} + \big(d_t - c_t\big)\mathbb{1}[z = z_{sto}] \pm f_t \;=\; L_{zt} + \sum_b q_{bt}\,\mathbb{1}[z = z_{bid}] \qquad (\pi_{zt}) ]
[ 0 \le p_{it} \le K_i, \quad 0 \le s_{zt} \le L_{zt}, \quad 0 \le q_{bt} \le Q_b, \quad -F \le f_t \le F, ]
and, when the feature is switched on,
[ p_{it} + r_{it} \le K_i, \qquad \sum_k x_{kt} \le \sum_i r_{it} \quad (\rho_t), \qquad 0 \le x_{kt} \le X_k, ]
[ E_t = E_{t-1} + \eta_c c_t - d_t/\eta_d, \quad E_0 = E_T = 0, \quad 0 \le E_t \le \bar E, \quad 0 \le c_t, d_t \le \bar P. ]
| Symbol | Meaning | Units |
|---|---|---|
| (c_i, e_i, K_i) | energy offer, emissions rate, capacity | USD/MWh, tCO2/MWh, MW |
| (\tau) | carbon price | USD/tCO2 |
| (L_{zt}, s_{zt}, S) | fixed load, involuntary shedding, shed price (VOLL or an offer cap) | MW, MW, USD/MWh |
| (q_{bt}, v_b, Q_b) | served flexible-demand block, its value, its size | MW, USD/MWh, MW |
| (r_{it}, x_{kt}, w_k) | reserve held, reserve-demand block cleared, block value | MW, MW, USD/MW-h |
| (c_t, d_t, E_t) | storage charge, discharge, state of charge | MW, MW, MWh |
| (f_t, F) | interzonal flow (positive from the first zone listed to the second), limit | MW |
Minimizing this objective maximizes modeled welfare: value of served flexible demand plus value of reserve held, minus production and carbon cost, minus VOLL on shed load. Everything is convex and perfectly competitive (offers equal cost).
Sign conventions¶
- Energy price (LMP). (\pi_{zt} = \partial(\text{objective})/\partial L_{zt}), the HiGHS equality marginal. Positive when more load costs more. Every step's tests confirm this by re-solving with load (\pm 0.01) MW (
finite_difference_price). - Reserve price. (\rho_t = -\partial(\text{objective})/\partial(\text{reserve supply})), reported as a nonnegative USD/MW-h.
- Line shadow price. The value of one more MW of transfer limit, reported nonnegative; the tests check it equals (|\pi_{East} - \pi_{West}|).
- Revenue. A unit's operating margin is (\sum_t(\pi_{zt} - c_i - \tau e_i)p_{it} + \rho_t r_{it}). Carbon payments are a transfer to the government and are not netted out of consumer payments.
- Degenerate points. Where two offers tie exactly (a carbon switching price, a DR bid equal to the clearing price) the dual is not unique. Outputs flag those rows (
at_switching_price,degenerate_tie) instead of reporting an arbitrary choice as a result.
Run¶
python -m pip install -r requirements.txt
python run.py # all steps; CSVs go to outputs/
python run.py --output-dir /tmp/mds
python -m unittest discover -s . -p "test_*.py" -v
run.py imports the merit-order-dispatch and storage-arbitrage labs' own code and data (Steps 0 and 4); nothing from those labs is copied. All inputs are in data/ and are synthetic: fleet.csv (four units; Unit A in West, B to D in East, with fixed costs for Step 3), day_types.csv (shoulder, summer and peak 24-hour shapes weighted 245/112/8 days), demand_bids.csv (four 100 MW flexible blocks), and parameters.json.
Step 0: the benchmark stays the benchmark¶
The merit-order lab's LP has a demand-reduction variable (0 \le d \le d_{max}) at cost (k). Here the same thing is a demand bid of (d_{max}) MW at value (k) on top of (D - d_{max}) MW of fixed load: serving the block is not reducing. The objectives differ by the constant (k\,d_{max}). run.py solves the four cases in that lab's README with that lab's code and with this clearing:
| Case | Price (USD/MWh) | Objective (USD/h) | Emissions (t/h) | DR (MW) | Largest difference |
|---|---|---|---|---|---|
| 1000 MW | 60 | 30,000 | 680 | 0 | 0 |
| + 100 USD/t | 110 | 90,000 | 520 | 0 | 0 |
| + 200 MW DR at 50 | 50 | 29,000 | 670 | 100 | 0 |
| + 100 USD/t and 200 MW DR at 80 | 110 | 84,000 | 340 | 200 | 0 |
Every later step is a strict generalization of this LP, so if a later number looks wrong the benchmark rules out the core formulation first.
Step 1: carbon price (benchmark fleet, one hour)¶
Feature. The offer becomes (c_i + \tau e_i). Units (i) and (j) swap merit-order position at (\tau^* = (c_j - c_i)/(e_i - e_j)).
Results. Switching prices are 42.86 (A/B), 50.00 (A/C) and 55.56 (B/C) USD/t. At 1000 MW only the A/C switch changes dispatch, because A and B are both fully loaded on either side of 42.86. Emissions fall from 680 to 520 t/h at 50 USD/t. Pass-through (\partial\pi/\partial\tau) equals the marginal unit's emissions rate: 0.10 USD/MWh per USD/t below 50 (Unit C on the margin), 0.90 above (Unit A).
Interpretation. Carbon pass-through is not the average emissions rate, and it can jump as the price crosses a switching point. Inframarginal rents move in opposite directions for clean and dirty units; step1_carbon_sweep_1000mw.csv reconciles rents plus costs to consumer payment, and step1_carbon_load_grid.csv repeats the sweep at 600, 800, 950 and 1100 MW to show that the marginal unit, and so the pass-through, depends on load.
Step 2: demand response inside the clearing¶
Feature. Four flexible blocks (100 MW each at 200, 90, 55, 40 USD/MWh) bid into the clearing on top of 900 MW of fixed load. The benchmark fleet has 1200 MW.
| Case | Effective bid | Price | Reduction | Welfare loss vs efficient |
|---|---|---|---|---|
| No price response | blocks are fixed load | 5,000 (100 MW shed at VOLL) | 0 | 496,500 USD/h |
| Efficient | (v) | 60 | 200 MW | 0 |
| Paid full LMP, flat retail rate (r = 45) | (v - r) | 60 | 300 MW | 3,000 USD/h |
| Paid LMP minus retail rate | (v) if (v \ge r), else (v - r) | 60 | 200 MW | 0 |
Interpretation. A customer on a flat retail rate who is paid the full energy price for reducing collects both the bill saving (r) and the payment (\pi), so it reduces whenever (\pi > v - r). The 90 USD/MWh block drops out although it values energy above the 60 USD/MWh cost of serving it: a loss of exactly (90 - 60) x 100 = 3,000 USD/h, and the program pays 18,000 USD/h instead of 3,000. Paying (\max(\pi - r, 0)) makes the total incentive (\pi) again. This is the economic content of the debate around FERC Order No. 745 (2011), which required full-LMP payment subject to a net-benefits test. step2_retail_rate_sensitivity.csv sweeps (r) from 0 to 80: full-LMP payment is harmless until (v - r) for some block falls below the clearing price (between 25 and 35 here; the row at 30 is a flagged tie). Welfare in the no-response row charges shed MW at VOLL, a convention, since the clearing cannot know whose load is shed.
Step 3: scarcity pricing and revenue adequacy (four-unit fleet, 365 days)¶
Feature. Reserve is co-optimized with energy against a reserve demand curve, and each representative day is cleared chronologically. Four designs are compared:
| Design | Shortage treatment |
|---|---|
energy_only_capped |
No reserve product; shortage priced at a 1,000 USD/MWh offer cap |
energy_only_voll |
No reserve product; shortage priced at VOLL (5,000 USD/MWh) |
fixed_reserve_penalty |
Vertical 100 MW requirement with an 850 USD/MW-h shortage penalty |
ordc |
Operating-reserve demand curve, 25 MW steps to 300 MW |
ORDC. Block (k) (midpoint (x_k)) is worth ((VOLL - \lambda_{ref})\,\mathrm{LOLP}(x_k)) with (\mathrm{LOLP}(x) = P(\text{loss} > x)) for a Normal(30 MW, 25 MW) loss of supply. Holding the marginal MW back avoids shedding a MW (worth VOLL) with probability LOLP; if deployed it costs (\lambda) to produce. This is Hogan's form, as used in ERCOT with (\lambda) the system energy price. Because (\lambda) is endogenous here, the highest offer (120 USD/MWh) stands in for it, which keeps (\pi \le) VOLL. The first block is worth 4,880 x 0.758 = 3,699 USD/MW-h. The code refuses a curve whose top block is worth more than (S - \max_i(c_i + \tau e_i)), because the LP would then shed load to hold reserve.
KKT reading. Reserve has no offer cost, so a unit providing both products is indifferent: (\pi_t - c_i = \rho_t). And (\rho_t > 0) only when every unit is at (p_{it} + r_{it} = K_i); otherwise spare capacity would supply reserve for free. Both identities are tested.
Results (base loads, no shedding in any design).
| Design | Peaker (Unit D) net revenue, USD/MW-yr | Missing money vs 80,000 fixed cost | Scarcity hours | Max price |
|---|---|---|---|---|
| Energy-only, capped | 0 | 80,000 | 0 | 120 |
| Energy-only, VOLL | 0 | 80,000 | 0 | 120 |
| Fixed requirement | 47,600 | 32,400 | 56 | 970 |
| ORDC | 67,837 | 12,163 | 56 | 3,819 |
The fixed-requirement number can be checked by hand: reserve is short whenever load exceeds 1300 MW, which happens in 7 hours of each of 8 peak days, and each of those 56 hours pays every MW of capacity 850, so 56 x 850 = 47,600.
Revenue equivalence. Consumers pay 556.66 MUSD/yr under every design once a capacity price equal to the peaker's missing money is paid on all 1400 MW, and production cost (236.68 MUSD/yr) is identical too. This is not a coincidence. In an hour with (\rho_t > 0) every unit is full, so with (\lambda_t = \pi_t - \rho_t) consumers pay
[ \pi_t L_t + \rho_t R_t = \lambda_t L_t + \rho_t (L_t + R_t) = \lambda_t L_t + \rho_t K, ]
and every MW of capacity, the peaker's included, earns the same scarcity rent (\rho_t). Scarcity pricing and a capacity payment are the same money routed differently. The equivalence needs no shedding, a capacity price that exactly closes the gap and is paid to all MW, no demand or storage response to the adder, and risk-neutral investors. step3_sensitivity.csv breaks it on purpose: at VOLL 9,000 the ORDC over-recovers the peaker's cost (123,442 USD/MW-yr), and with peak-day load scaled up 2% or 4% load is shed in every design (109 and 784 MWh/yr); the 1,000 USD/MWh offer cap then still leaves 44,800 to 58,880 USD/MW-yr unrecovered, while VOLL pricing over-recovers the peaker's cost from 24 to 40 shortage hours.
Step 4: storage inside the clearing¶
Feature. A 100 MW / 400 MWh battery (92% each way, empty at start and end of each day) enters the ORDC clearing. Three valuations are compared: the storage-arbitrage lab's price-taker schedule valued at no-storage prices (estimate), the same schedule forced into the clearing and valued at the prices it causes (executed), and storage co-optimized by the clearing (cleared).
| Day | Estimate | Executed | Cleared | System saving | Peak price without / with |
|---|---|---|---|---|---|
| Shoulder | 6,863 | -637 | 6,863 | 6,863 | 60 / 60 |
| Summer | 28,955 | -4,007 | 0 | 16,291 | 120.04 / 70.89 |
| Peak | 793,036 | 18,478 | 18,941 | 247,039 | 3,819 / 122 |
Interpretation. On the peak day the battery erases the scarcity it was valued against, so the price-taker estimate overstates its revenue about 42-fold. On the summer day it earns nothing yet saves 16,291 USD: it is the marginal resource at both ends, so the peak price falls to exactly (60/(0.92 \times 0.92) = 70.89) and the spread just covers losses. A competitive store earns only the shadow value of its own binding power and energy limits. The price-taker schedule loses money when executed on two days because it ignores its own price effect. step4_battery_size_sensitivity.csv shows cleared peak-day revenue rising to 95,956 USD at 50 MW and falling to 18,941 at 100 MW, while system saving keeps rising: the welfare value and the merchant value of storage diverge, which matters directly for Step 3's equivalence (scarcity revenue rewards whoever removes scarcity, and the removal destroys it).
Step 5: two zones¶
Feature. Unit A (cheap, dirty) is alone in West (200 MW load); B, C, D are in East (800 MW load), joined by a 250 MW line.
Results. At 0 USD/t the line binds: West 20, East 60 USD/MWh, congestion rent (60 - 20) x 250 = 10,000 USD/h, line shadow price 40. Carbon pass-through is now locational: at 25 USD/t West rises by 0.90 per USD/t and East by 0.10, so the spread and the rent halve to 5,000 USD/h. The line stops binding between 45 and 55 USD/t (A and C tie at 50), after which flow drops to 100 MW and both zones price at A's offer. The constrained case also emits less (640 vs 680 t/h) because the line keeps some of Unit A out. step5_line_limit_grid.csv varies the limit from 0 to 600 MW: at 400 MW and above the line never binds in this case and the result equals the single-zone clearing (tested).
Interpretation. Congestion rent is the price spread times the flow, collected by whoever holds the transmission rights. A carbon price that reorders the merit order can relieve congestion and collapse that rent. This is a radial two-zone transfer limit; loop flows and shift factors are the subject of the three-bus DC-OPF lab, and the basic two-node case is in two-node congestion.
Written comparison: energy-only, capacity, and ancillary-service revenue¶
- Energy-only markets pay generators the energy price in every hour. With offers at marginal cost, the units that set the price earn nothing above cost, so a peaker can recover its fixed cost only from hours priced above its offer: shortage hours. In Step 3 that is zero hours at base load (no shortage) and the full 80,000 USD/MW-yr is missing. Whether the price can rise high enough in the few shortage hours depends on the cap (capped vs VOLL rows of the sensitivity) and on regulators letting it. Revenue is concentrated in rare hours, so it is volatile and exposed to political intervention.
- Ancillary-service (reserve) revenue prices the capacity held back for reliability. Co-optimization means the reserve price also appears in the energy price ((\pi = \lambda + \rho)), so a well-designed reserve demand curve is the mechanism through which an energy-only market reaches scarcity prices before load is shed. The ORDC raises the price gradually as reserve falls, at the expected cost of the outage the reserve avoids, instead of jumping to an administrative penalty; in Step 3 it recovers more of the peaker's cost than the fixed requirement in the same 56 hours, with a peak price (3,819) below VOLL. Most of the peaker's reserve-design revenue arrives as energy margin, not reserve payments (59,028 vs 8,809 USD/MW-yr under the ORDC), because of that coupling.
- Capacity markets pay a price per MW of availability, set administratively or by auction to close the residual "missing money". In the model, the capacity price that retains the peaker is 80,000 (energy only), 32,400 (fixed requirement) or 12,163 USD/MW-yr (ORDC). Consumers' total is the same in all three under the stated assumptions; what differs is when payments arrive, how risky they are for investors, how much the design depends on an administrative demand curve or reliability standard, and whether flexible resources (Steps 2 and 4) that reduce scarcity are rewarded for doing so.
Nonconvexities and market-design limitations¶
The LP is convex, so its duals are clearing prices that support the dispatch and every unit is happy with its schedule. Real markets are not convex:
- Commitment. Start-up costs, no-load costs and minimum output are discrete. Marginal prices then may not cover a committed unit's costs, and uplift (make-whole) payments or convex-hull pricing are needed. See the unit-commitment lab for the integrality gap and LP-relaxation prices.
- Reserve deliverability. Every MW of headroom counts as reserve here, including offline units, with no ramp rate, commitment or zonal deliverability. Spinning reserve requires commitment (nonconvex). The energy-reserve co-optimization lab treats reserve offers and a fixed requirement on its own.
- Lumpy investment. Plants come in discrete sizes and are built ahead of need; Step 3 is a static revenue test with no entry or exit, so it measures missing money but does not find an equilibrium fleet.
- Storage complementarity. Charging and discharging at once is ruled out only because prices are nonnegative (losses make it unprofitable). With negative prices the LP would need a binary or complementarity constraint, which is why the storage-arbitrage lab rejects negative prices. Representative days are cleared separately, with perfect foresight and an empty battery at midnight.
- Demand response. DR is curtailment against an assumed baseline; baseline manipulation, rebound and load shifting are not modeled. Retail rates are flat; see the non-exporting BTM storage lab for tariff-driven behavior and the utility regulatory economics lab for how retail rates are set.
- Shedding is continuous. Real rotating outages are blocks of feeders, another nonconvexity.
- Market power and risk. All offers equal cost. Scarcity pricing gives withholding a high payoff, which is why real designs pair it with offer mitigation; investors are assumed risk-neutral, which is what makes the Step 3 equivalence exact.
- Network. Two zones and one lossless line; no loop flow, losses, or N-1 security.
- Parameters. VOLL, the loss distribution, the offer cap, fixed costs, retail rate and battery size are synthetic. Every headline number depends on them; the sensitivity CSVs exist so that no single number is read as a finding about a real market.
Outputs¶
| File | Content |
|---|---|
step0_benchmark.csv |
Merit-order lab cases, both formulations side by side |
step1_switching_prices.csv, step1_carbon_sweep_1000mw.csv, step1_carbon_load_grid.csv |
Carbon switching prices, sweep 0 to 150 USD/t, load grid |
step2_dr_cases.csv, step2_retail_rate_sensitivity.csv |
DR compensation cases; retail-rate sweep with tie flags |
step3_ordc_curve.csv, step3_revenue_by_unit.csv, step3_design_totals.csv, step3_sensitivity.csv |
ORDC, revenue by unit and design, consumer totals, VOLL x peak-load sensitivity |
step4_storage_summary.csv, step4_storage_hourly.csv, step4_battery_size_sensitivity.csv |
Storage valuations, hourly prices, battery-size sweep |
step5_two_zone_carbon_sweep.csv, step5_line_limit_grid.csv |
Zonal prices, flow, shadow price and rent vs carbon price and line limit |
Tests¶
test_market_design.py (47 tests) checks: the four benchmark cases against the merit-order lab; hand-worked prices, dispatch and emissions; LMP = finite difference of the objective in single-hour, ORDC, storage and two-zone cases; switching prices and pass-through; DR welfare loss and payments by hand, tie flags and nonnegative net payments; the ORDC first block, the KKT identity (\pi - c = \rho), the hand-checked fixed-requirement revenue, revenue reconciliation and equivalence; storage feasibility, no simultaneous charge and discharge, the zero-profit summer price (60/0.92^2); and the zonal shadow price equal to the price spread.
Required interpretation¶
- Derive the pass-through result in Step 1 from the LP's dual and explain why it is the marginal, not the average, emissions rate.
- Show algebraically why full-LMP DR payment with a flat retail rate acts as a bid at (v - r), and when it causes no loss.
- Using the KKT conditions, explain why (\rho_t > 0) implies every unit is at capacity and why that makes the Step 3 consumer totals equal. Then name the assumption whose failure breaks the equivalence in each sensitivity row with nonzero shedding or over-recovery.
- Explain why the competitive battery earns zero on the summer day yet adds welfare, and what that implies for financing storage from scarcity revenue alone.
- Explain why a carbon price can reduce congestion rent in Step 5, and who would gain or lose from that with financial transmission rights.
- Pick one nonconvexity above and describe how the duals reported here would stop being supporting prices if it were added.
Related material¶
- Y1-02 course guide and PS3 on carbon pricing and flexible demand.
- Y1-03 Problem Set 5: scarcity and resource adequacy.
- Stoft, Power System Economics (2002), on price spikes, reliability and the missing-money problem; Hogan, "Electricity Scarcity Pricing Through Operating Reserves," Economics of Energy & Environmental Policy 2(2), 2013.