Marginal abatement cost. Cutting emissions by ai (Mt) costs firm i the amount Ci = ½ ki ai², so the cost of the next tonne is MACi = ki ai (€/t). A firm facing an allowance price p abates until MAC equals p: ai = min(p/ki, Ei), and buys or sells the difference between its emissions and its allowances.
Market clearing. The cap Q fixes the total number of allowances. The price at which total emissions equal the cap satisfies Σ (Ei − ai(p)) = Q. Without corner cases this has the closed form p* = R / Σ(1/ki) with required reduction R = ΣEi − Q. The simulator moves the price by tâtonnement, dp/dt = κ (emissions − cap): excess demand raises the price, excess supply lowers it. A floor and ceiling clamp p, and if the ceiling binds the cap is breached.
Why trading is cheaper. Trading equalises marginal costs (the equimarginal principle), which minimises total cost for a given total reduction: Ctrade = ½ R² / Σ(1/ki). A uniform rule (every firm cuts the same percentage) leaves cheap abatement unused and costs more. Free allocation of allowances changes who pays and who receives money, not the total abatement (Coase-type invariance), which the checks confirm.
Honest simplifications. Quadratic cost curves, four representative sectors, perfect competition, no banking, no market power, no leakage or innovation. The numbers (baselines, k) are illustrative and not calibrated to any real scheme; real carbon markets also involve auctions, offsets and policy reserves.