Merit Order and Marginal Abatement Cost Curve in Python

Setting the wholesale electricity price and exploring decarbonisation opportunities

Himalaya Bir Shrestha
Towards Data Science

--

To achieve the global temperature limit goals of 1.5°C by the end of the century set by the Paris Agreement, different institutions have come up with different scenarios. There is a consensus among the mitigation scenarios that the share of low-carbon technologies such as renewable energy needs to increase, and fossil fuels need to decline steadily in the energy mix of tomorrow.

The deployment of mitigation technology options (such as renewable energy, Electric Vehicles (EVs), green hydrogen, etc.) come up with their own set of costs and benefits. The mix of renewable energy and fossil fuels in the electricity generation portfolio of a country not only determines the CO2 emissions but can also influence the electricity price. In this post, I am going to discuss how the electricity price is determined in a wholesale electricity market by merit order curve (based on the concept of marginal costs or production), and how the cost-effectiveness of decarbonisation opportunities in a country or region or an organisation could be assessed based on marginal abatement costs curve. I am going to use Python to construct these two curves, and discuss the implementation along the way.

Let’s get started!

Merit Order Curve

An electricity authority or a utility in a country could have competing power plants of different types in its portfolio to offer electricity output to retailers. This is known as a wholesale electricity market (also known as spot market). The cost of generating electricity differs according to the type of power plant. For example, there is zero or minimal cost of electricity generation from solar PV or wind turbines since they don’t require any fuels. On the other hand, power plants based on fossil fuels have higher running costs depending on the prices of fuels such as coal, oil, or gas that is combusted to generate electricity. In the language of economics, the cost of producing one additional unit of a product is called marginal cost of production.

In the power system, available power plants in the portfolio are scheduled to be online based on the ascending order of short-run marginal costs of production of electricity. This sequence is referred to as the merit order. The power plants with the lowest marginal costs are scheduled to meet demand first, followed by the power plants with higher marginal costs to optimise the electricity supply costs.

In this section, I am going to implement the different steps to construct the merit order curve in Python and discuss how the merit order sets the wholesale electricity price.

Implementation

Let’s consider that there are power plants of nine types in the electricity portfolio of a country as shown in the list power_plants. These power plants must be arranged in ascending order of marginal_costs. The data used in this example are based on my assumption and can be regarded as dummy datasets.

power_plants = ["Solar", "Wind", "Hydro", "Nuclear", "Biomass",
"Coal", "Gas", "Oil", "Diesel"]

marginal_costs = [0, 0, 5, 10, 40, 60, 80, 120, 130]

First, I convert this data into a dataframe with power_plants in index and marginal_cost in the column. Next, I iterate through the index of dataframe and ask the user to enter the available capacity of each power plant. The available capacity of each power plant is stored in an individual variable using the globals() method as shown below.

Asking user input for the available capacity of each power plant type using for-loop and the globals() method.

The total available capacity in the portfolio of country X sums to 1800 MW. Then, I create a new column called Cumulative capacity (MW), which is the cumulative sum of Available capacity (MW) .

Dataframe containing marginal cost and available capacity of each power plant type in country X.

I ask the user to enter the electricity demand in country X at a given timeframe.

demand = int(input(“Enter total demand (MW): “))

Let’s assume the demand is 1500 MW.

Now, the data is ready, I can start compiling the building blocks for the merit order curve. In a merit order curve, the power plant are ordered in ascending order of marginal costs of electricity generation in the form of bar plots. The width of bars represents the available capacity of each power plant type and the height represents the corresponding marginal cost. Since the widths of bars are not equal, they look quite different from the normal bar plots.

The position of ticks on the x-axis for the first bar (here Solar) is the same as half of its Available capacity (MW). For the other power plant type, the position is calculated as the sum of Cumulative capacity (MW) till the power plant type before it, and half of its Available capacity (MW). I have prepared a for-loop to get this position in xpos column of df as shown in the first part of the gist below.

Next, I analyse the position at which the demand lies on the x-axis. The position at which the power demand intersects with the cumulative power supply at the x-axis, determines cut_off_power_plant. In turn, the marginal cost of the cut_off_power_plant determines the clearing price of all power plants in the merit order before it, which participate in the wholesale market. The buyers of electricity in this wholesale market will all pay that same price.

For loop on the top determines the position of the bar of each power plant type on the x-axis. cut_off function on the bottom determines the power plant type that intersects with the power demand.

The code to generate the merit order curve is as shown.

Function to generate the merit order curve in the electricity market.

The resulting plot is as shown below.

Merit order curve of the given electricity market. X-axis represents the available capacity of power plants. Y-axis represents the marginal cost of each power plant. The vertical red dashed line represents the demand which is intersects with gas. The horizontal dashed red line represents the marginal cost of electricity generation from gas, which sets the market clearing price. Image by Author.

In the resulting plot, the power demand of 1500 MW is represented by the vertical dashed red line. This coincides with the power supply from gas when all the power plants are arranged in ascending order by marginal cost. Hence, the marginal cost of electricity generation from gas i.e. 80 $/MWh is the market clearing price. This implies all the power plants on and before the vertical dashed red line on the X-axis i.e. solar, wind, hydro, nuclear, biomass, coal, and gas need to deliver power to meet the demand. And all of them receive the price set by the marginal cost of production from gas.

Merit Order Effect

When the demand level changes in the power system, the wholesale electricity price also reacts accordingly. This is demonstrated in the GIF image below. To get the animation in Python, I have used the interact function from ipywidgets as shown below. I have also used IntSlider widget to set thedemand as the user-defined parameter to interact with. To avoid flickering while dragging along the slider, I have set continuous_update to False.

from ipywidgets import *demand = widgets.IntSlider(
value = 100,
min = 0,
max = df[“Available capacity (MW)”].sum(),
step = 10,
description = “Demand”,
continuous_update = False #False to avoid flickering
)
interactive_plot = interact(merit_order_curve, demand = demand)
Animation showing the change in cut off power plant and wholesale electricity price as the demand changes. Image by Author.

As shown in the GIF image above, when the demand increases, more power plants towards the right of the merit order need to be dispatched, which increases the clearing price and vice versa. If there is a more available capacity of renewable power plants in the portfolio, more share of the demand is met by renewable sources. This tends to lower the electricity price, which is known as the merit order effect.

Marginal Abatement Cost Curve

The abatement cost is a cost borne by firms for removing or reducing the externalities (negative byproducts) created during production. And the marginal abatement cost measures the cost of reducing one additional unit of externalities, e.g. CO2 emissions. While the merit order curve is based on ordering technologies by marginal costs of production, the marginal abatement costs (MAC) curve is based on ordering different mitigation opportunities in the ascending order of marginal abatement costs.

In a MAC curve, the width of the bar represents the greenhouse gas (GHG) emissions reduction potential of any technology or option. And the height of the bar represents the cost of reducing one additional unit of GHG emissions with the given opportunity.

Dataframe containing mitigation potential and marginal abatement costs of different opportunities. Data is based on the author’s assumption.

The data for this example is based on my assumption and can be regarded as a dummy dataset. The implementation of the MAC curve in Python is similar to that of the merit order curve.

MAC curve for a certain year for country X. The width of the bar represents the annual GHG emissions reduction potential of the mitigation opportunity. The height of the bar represents the estimated costs in a given year to reduce emissions by 1 tCO2e. Image by Author.

As shown in the plot above, replacing old lights with LED lights is the most cost-effective measure for decarbonisation. The negative marginal abatement costs for certain opportunities imply that there are net cost savings (or profit) when those measures are implemented. As we move towards the right end of the X-axis in a MAC curve, it becomes more expensive to abate one unit of GHG emissions. The widest bar on the MAC curve, reforestation has the highest overall potential of GHG emissions reductions.

Thus, the MAC curve allows measures from various sectors (here power, transport, buildings, forestry, and waste) to be compared on equivalent terms. While the MAC curve provides a key initial assessment on the potential and cost-effectiveness of various mitigation opportunities, combining this assessment with insights from other modelling tools provides a strong base for formulating policies and investment decisions.

Conclusion

As we are traversing through the global energy transition, burning more fossil fuels to meet our energy needs would lead to soon exceeding the emissions budget that we need to respect to meet the global climate objectives. There are already technically proven and economically feasible opportunities in place, that can significantly reduce GHG emissions from both energy and non-energy sectors. Moreover, with economies of scale, the proven mitigation technologies (e.g. wind and solar) are getting cheaper every year.

It is important to harness the proven mitigation technology options to cut down on the emissions significantly. The mitigation options come up with their own set of costs and benefits. In this post, I discussed how the share of renewable energy and fossil fuels in the power system portfolio of a country influences the wholesale electricity prices with the concept of merit order curve (based on marginal costs of production). And I presented how the emissions reduction potential and cost-effectiveness of mitigation opportunities in a country could be assessed based on the marginal abatement cost curve. The implementation of these curves in Python is available in this GitHub repository.

--

--

I write about the intersection of data science with sustainability in simple words. Views reflected are of my own, and don’t reflect that of my employer.