Back to Portfolio
Data Analytics · Time Series

Oil Iran Shock: Crude Inventories vs. Pump Prices

How quickly are changes in crude oil inventories passed on to pump prices? A short data analytics case study using the U.S. Energy Information Administration (EIA) API, focused on the period right after the Iran conflict began on February 28, 2026.

EIA API Python Correlation Time Series Econometrics
~5%Crude Inventories
~37%Gasoline Prices
0.98Correlation

Why this analysis was done

This case study follows the STAR framework — Situation, Task, Action, Result — to explain not just what was found, but why the analysis was carried out in the first place.

Situation

The geopolitical context that triggered the question

On February 28, 2026, a major conflict began involving Iran — a key player in global crude supply. Energy markets reacted immediately. As an economist and business analyst, the natural question was: "How quickly do changes in crude oil inventories actually reach the pump price consumers pay?" In calm conditions the answer is textbook, but in a shock episode it is uncertain whether that logic still holds.

Task

The analytical objective

Quantify the relationship between weekly U.S. commercial crude inventories and retail gasoline prices in the weeks right after the conflict began, using real public data rather than assumptions.

Result

What the data showed

Between Feb 28 and Apr 13, 2026, inventories rose ~5% while pump prices jumped ~37%, with a Pearson correlation of 0.98 — the opposite of the textbook supply story.

Action — How

The analysis pipeline

Wrote a Python script using requests to pull weekly EIA data from two endpoints, merged both series with pandas, computed the Pearson correlation with scipy/pandas, and rendered the time series and scatter plots with matplotlib + seaborn.

Action — Why

The interpretation behind the numbers

The co-movement is a classic case of confounding: inventories and prices both react to the same driver — geopolitical risk — rather than one causing the other. Isolating the true inventory effect would require controlling for an index of geopolitical uncertainty (e.g., the Caldara & Iacoviello GPR index).

Time series & correlation

Weekly EIA series for national commercial crude inventories (thousand bbl) and regular gasoline pump prices (USD/gallon), with the post-conflict window shaded.

Dual-panel time series of crude inventories and gasoline prices
Dual-panel time series — crude inventories (top) vs. retail gasoline prices (bottom). Source: U.S. EIA (series stoc/wstk and pri/gnd).
Scatter plot of inventories vs gasoline price
Correlation scatter — the tight upward pattern (Pearson r ≈ 0.98) reflects a shared geopolitical driver, not causation.

The numbers behind the story

Metric Feb 28, 2026 Apr 13, 2026 Change
Commercial crude inventory 443,103 kbbl 465,729 kbbl +5.1%
Regular gasoline price $3.02/gal $4.12/gal +36.7%
Pearson correlation 0.98

From API to insight

  1. Fetched weekly commercial crude oil stocks via the EIA endpoint /v2/petroleum/stoc/wstk/data/ (facet EPC0, U.S. national duoarea=NUS).
  2. Fetched weekly retail gasoline prices via /v2/petroleum/pri/gnd/data/ (facet EPMR).
  3. Built a paginated helper to handle multi-page responses from the EIA API.
  4. Merged both series on week using an inner join.
  5. Computed percentage changes and the Pearson correlation over the post-conflict window.
  6. Rendered a dual-panel time series and a correlation scatter, then exported the merged dataset to CSV.

Stack: Python 3.12 · requests · pandas · matplotlib · seaborn · python-dotenv (Jupyter notebook).

A classic case of confounding

During a geopolitical shock, the simple supply-and-demand relationship between inventories and prices breaks down. Refineries stockpile crude as a precaution, while traders price in a risk premium that flows from futures to the pump. Both effects move in the same direction at the same time — a textbook case of confounding rather than causation.

To isolate the true effect of inventories on prices, the analysis would need to control for a measure of geopolitical uncertainty — for example, the Caldara & Iacoviello Geopolitical Risk Index.

Don't confuse co-movement with cause

When analyzing business and economic data, a strong correlation is only a starting point. Identifying the common underlying driver — and separating signal from shared shocks — is what turns a number into a defensible decision.

Explore the project