Refining margins over the years. How have crude processing and refined... | by Ranganath Venkataraman | Towards Data Science

In my last post, we saw that the Gulf Coast is largely responsible for refinery processing in the United States. So, why do refineries process crude into refined products? To recognize profits between products and crude.
As always, note that all data used in visualizations below is publicly available from the U.S. Energy Information Administration.
A refinery’s gross profit tracks the ‘crack spread’, which is the difference between the price of refined products and the price of crude oil. Let’s define the oft-used 3–2–1 spread as ( (2*price of gasoline) + (1*price of diesel) — (3*price of crude)) / 3
The code below calculates the crack spread and then creates a scatterplot over time, along with a calculated average — see graph after code
# Calculate 3-2-1 spread, using Conventional Gas, ULSD, and West Texas Intermediate crude pricesPost2006['3-2-1, WTI-base'] = (2*Post2006['Conv Gas, $/gal']*42 + Post2006['ULSD, $/gal']*42 - (3*Post2006['WTI mo. avg, $/bbl'])) / 3# Plot spread and average over timeplt.figure(figsize=(10,10))plt.scatter(Post2006['Date'],Post2006['3-2-1, WTI-base'], c='b', marker='x', label='3-2-1 spread, $/bbl')y_mean = [np.mean(Post2006['3-2-1, WTI-base'])]*len(Post2006['Date'])plt.plot(Post2006['Date'],y_mean, c='black, marker='x', label='Avg')plt.legend(loc='upper left', fontsize=12)plt.xticks(np.arange(0, 100, step=12), rotation=80, fontsize=12)plt.yticks(fontsize=12)plt.show()
What does the chart above tell us? Refining 3 barrels of crude oil to produce and sell 2 barrels of gasoline and 1 barrel of diesel nets profit averaging $17.50 per barrel of crude oil.
What is it about crude oil that allows refineries to make fuel? Crude can be thought of as a mixture of light and heavy chemical components — at the extremes, light components end up as LPG that fires up our BBQ and heavy components end up as asphalt in road tar.
In the middle between extremes, heavy and light components are blended to make motor fuels such as gasoline, diesel, and jet fuel.
The more that the crude oil mixture is made up of light components, the ‘lighter’ the crude is. The lighter the crude, the higher its API gravity. Likewise: the more that the crude oil is composed of heavy components, the lower the API gravity.
How has API gravity of crude feeding U.S. refineries changed over the years? Code below was used to produce the following graph
# 1st, create two separate scatter plots on two separate axesAPI = pg.Scatter(x=crudesulfurandAPI['Date'], y=crudesulfurandAPI['Crude sulfur, %'], name = 'Sulfur, %')Sulfur = pg.Scatter(x=crudesulfurandAPI['Date'], y=crudesulfurandAPI['API'],                        # Specify axis                        yaxis='y2', name = 'API, deg F')# 2nd, define layout with axis titles, figure title, and image dimensions.layout = pg.Layout(height=500, width=900,                   title='Crude sulfur and API since 1985',                   # Same x and first y                   xaxis=dict(title='Date'),                   yaxis=dict(title='Sulfur, %', color='blue'),                   # Add a second yaxis to the right of the plot                   yaxis2=dict(title='API, deg F', color='red',                               overlaying='y', side='right'),                   )# Last, attribute layout to figure and add annotationfig = pg.Figure(data=[API, Sulfur], layout=layout)fig.add_annotation(            x=200,            y=1.45,    font=dict(            family="Courier New, monospace",            size=18,            color="black",            ),            text="29.78 API, 1.48% Sulfur")# Finally, update location of legendfig.update_layout(legend=dict(x=0.15, y=0.9), title=dict(x=0.15, y=0.9))
The red API gravity of crude feeding U.S. refineries has declined from the mid-80s through mid-2008, when it troughed at 29.8. At that point, U.S. refineries start seeing an influx of high API gravity, light crude from the Bakken shale oil fields in North Dakota.
You’ll observe the blue trend of sulfur. We’ll focus on this in a separate post, but for now — high sulfur in crude means more sulfur to be removed in an oil refinery in order to minimize the harmful release of toxins. Generally, heavier and sour crudes are cheaper than light and sweet crudes.
The 3–2–1 crack spread depends on crude prices and refined product prices. For our purposes, let’s consider the refined products: gasoline, jet fuel, and ultra low sulfur diesel (ULSD). Trending these prices going back to 2006 against the price of crude oil yields the following pair plot.
That’s quite an eyeful! Bottom-lines:
Gasoline, jet fuel, and ULSD prices all demonstrate a strong linear correlation with crude oil prices. They also linearly correlate with each other i.e. all fuel prices generally trend together.
The histograms of gasoline, ULSD, and jet fuel all indicate two peaks — suggesting two commonly observed peaks of occurrence. These are the price points of summer (mid-April through August) and winter (every other month).
One note before continuing: WTI, or West Texas Intermediate, is one of two major price markers of crude — the other is Brent. A little more on this, at the end of this article.
From everything that we’ve learnt above, could the API of processed crude be predicted by gasoline prices? After all, lighter crude — i.e. higher API — helps make more gasoline. Therefore, wouldn’t higher gas prices lead refiners to process more high-API crude? If we trend data going back to 2006, what do we find?
Woah... no correlation there. This suggests that refineries are capable of handling diverse types of crude feed to maintain their target gas, diesel, and jet production. In the next post, let’s further evaluate refinery configurations using data visualizations.
Before I leave you, here’s a plot of WTI crude prices vs. Brent crude prices, going back to the mid-80s. Key point for your understanding now: these have historically read close to each other, so I’m currently not preoccupied with which marker to use in analysis.
Here’s a point of interest; you’ll notice prices diverging above, as marked, starting in 2011. What’s going on here? As shale crude flooded the market — remember how crude API started trending upwards in the trends above — the U.S. price marker for crude dipped below the international benchmark, Brent.
Why didn’t Brent dip as well? Shouldn’t all crude prices fall in response to oversupply? No, because markets other than the U.S. were initially not allowed to access U.S. crude until the exports embargo was repealed in 2014.
Here is the link to the full repo.
See you in the next post! Any feedback is welcome, as always.