⚡ Simulating the UK energy market

Following on from my earlier posts about energy storage, I wanted to build something more interactive — a simulation that lets you tweak the inputs and see what happens to electricity prices and reliability.

The result is an energy market simulator: a Streamlit dashboard where you define a base case representing today’s market, create a scenario with changes (more renewables, carbon pricing, demand response), and compare the two side by side.

Merit-order dispatch

The simulation models the actual mechanism used in real wholesale electricity markets: merit-order dispatch. Each hour:

  1. Every producer offers capacity at its marginal cost (with stochastic noise to model real-world variability)
  2. Offers are sorted cheapest-first
  3. Consumer demand is computed, with price elasticity feeding back from the previous hour
  4. Producers are dispatched in cost order until demand is met
  5. The last producer dispatched sets the market clearing price for everyone

If supply falls short, a scarcity price cap ($500/MWh) kicks in and unserved energy hours are tracked.

The fleet

The simulator models 10 producer types: Nuclear, Hydro, Wind, Solar, Geothermal, Biomass, Coal, Natural Gas, Oil, and Battery Storage. Each has realistic characteristics:

  • Solar follows a bell curve peaking at hour 13, with zero output at night
  • Wind uses an inverted sinusoidal pattern (stronger at night) plus random noise
  • Battery storage is price-arbitrage-driven — charges below 50/MWh, with 90% round-trip efficiency and 4-hour duration
  • Fossil fuels have CO2 emission rates that interact with the carbon price slider (Coal: 0.95 t/MWh, Gas: 0.45, Oil: 0.75)

Three consumer segments — Residential (evening peak), Commercial (midday peak), Industrial (nearly flat) — each with price elasticity and seasonal variation.

Glidepath mode

One feature I’m particularly pleased with is the glidepath mode. Instead of applying a scenario as a sudden change, it linearly interpolates all parameters across 12 steps over the simulation period. This models gradual policy transitions like “phase out coal over a year” — which is how real energy transitions actually work.

The dashboard

Five tabs: price comparison (base vs. scenario with delta), volatility analysis (rolling 24h standard deviation and price distribution histograms), dispatch stack (stacked area chart of which producers are running), consumer load breakdown, and detailed stats with 11 metrics including total system cost and unserved energy hours.

Tech: Python (Streamlit), NumPy, Pandas, Plotly. No database, no external APIs — everything runs in-memory. Simulations can run for 1 week (168h), 1 month (720h), or 1 year (8,760h).