WTI Crude Oil Price Analysis

Sun, 23 Mar 2025 02:43:26 GMT
User

get monthly crude oil (WTI) prices from FRED for the longest possible history using pandas datareader. run a regression of the price on its lagged value as x_{t+1} = a + b x_t + error. Report the long-run mean a/(1-b).

Thu, 20 Mar 2025 18:43:27 GMT
J
Julius

I'll help you get WTI crude oil prices from FRED and run the regression analysis. Let's do this step by step.

Python

This code snippet retrieves historical WTI crude oil prices from the FRED database and displays the date range and first few observations of the data.
{
…
}1 Item

Python

This code snippet creates a lagged price series for oil prices, runs a linear regression to estimate the relationship between current and previous prices, and calculates the long-run mean, followed by plotting the results.
{
…
}2 Items

The analysis shows that WTI crude oil prices follow a highly persistent AR(1) process. The regression equation is:

xt+1=0.236+0.9943xt+ϵtx_{t+1} = 0.236 + 0.9943x_t + \epsilon_txt+1​=0.236+0.9943xt​+ϵt​

The coefficients show: 0.236 for the intercept (a) 0.9943 for the slope coefficient (b)

The long-run mean, calculated as a1−b\frac{a}{1-b}1−ba​, is approximately 41.0556 dollars per barrel.

The scatter plot shows the relationship between consecutive monthly prices:

Chart unavailable

The very high b coefficient (0.9943) indicates that oil prices are highly persistent, meaning that prices tend to stay close to their previous values. The positive intercept contributes to a long-run mean price of about $41.06 per barrel.

Thu, 20 Mar 2025 18:44:08 GMT
User

create a time series plot of the crude price

Thu, 20 Mar 2025 18:45:56 GMT
J
Julius

Python

This code generates a time series plot of WTI Crude Oil prices from 1946 to 2025, highlights the long-run mean, and displays summary statistics.
{
…
}2 Items
Chart unavailable

The time series plot shows the historical evolution of WTI crude oil prices from 1946 to present, with the long-run mean of $41.06 shown as a red dashed line. Some key features visible in the plot:

  • Prices were relatively stable and low (under $5) from 1946 until the early 1970s
  • Major price spikes occurred during the oil crises of the 1970s
  • Significant volatility since 2000, with notable peaks in 2008 and 2022
  • Current prices have returned closer to the long-run mean
WTISPLC
count
949
mean
28.23
std
29.46
min
1.17
25%
3
50%
18.53
75%
40.28
max
133.93

The summary statistics show considerable variation in prices over this period, with a minimum of $1.17 and a maximum of $133.93 per barrel. The median price ($18.53) is notably lower than the mean ($28.23), indicating a right-skewed distribution of prices.

Thu, 20 Mar 2025 18:46:19 GMT
User

get the CPI from FRED using pandas datareader and compute crude prices in today's dollars

Thu, 20 Mar 2025 18:49:11 GMT
J
Julius

Python

The code retrieved WTI crude oil prices and CPI data, calculated real prices adjusted for inflation, and plotted both nominal and real prices while providing summary statistics and the latest price values.
{
…
}2 Items
Chart unavailable

The plot shows both nominal (blue) and real (orange) oil prices from 1946 to 2025. When adjusted for inflation to 2025 dollars, we can see that:

  1. The 1970s oil crisis peak was actually higher in real terms than recent peaks
  2. The real price has been much more volatile than what nominal prices alone would suggest
  3. The lowest real prices were in the late 1940s, when oil was around $20-25 in today's dollars
Real_WTI
count
938
mean
61.07
std
34.83
min
20.67
25%
32.63
50%
48.82
75%
80
max
196.94

The current nominal price is 71.53 USD per barrel, which is the same as the real price since we're converting to current (2025) dollars. Historically, real prices have averaged about $61.07 per barrel, with a maximum of nearly $197 (in today's dollars) during the 1980 oil crisis.

The real price analysis gives us a better picture of oil's historical cost in terms of purchasing power, showing that recent prices, while high in nominal terms, are not unprecedented when accounting for inflation.

Thu, 20 Mar 2025 18:49:38 GMT
User

run the autoregression using real prices

Thu, 20 Mar 2025 18:49:57 GMT
J
Julius

Python

This code snippet creates a lagged series of real oil prices, fits a linear regression model to predict future prices based on past prices, and visualizes the results along with the R-squared value.
{
…
}2 Items

The regression for real oil prices shows:

xt+1=0.7569+0.9884xt+ϵtx_{t+1} = 0.7569 + 0.9884x_t + \epsilon_txt+1​=0.7569+0.9884xt​+ϵt​

Chart unavailable

Key findings:

  • The intercept (a) is 0.7569

  • The slope coefficient (b) is 0.9884 , indicating high persistence but slightly less than with nominal prices

  • The long-run mean is 65.4332 dollars per barrel in real (2025) terms

  • The R-squared is 0.9781 , showing that lagged prices explain about 98% of the variation in current prices

The regression shows that real oil prices are also highly persistent (b close to 1), but the persistence is slightly lower than in nominal terms. The long-run mean of about $65.43 in real terms gives us a better sense of the equilibrium price level after accounting for inflation. This is higher than the simple average of real prices we saw earlier because it accounts for the autoregressive dynamics of the series.

The scatter plot shows a tight relationship between consecutive real prices, with some notable outliers during periods of high volatility.

We've analyzed both nominal and real oil prices since 1946, finding:

  • High persistence in both series (AR coefficients > 0.98)
  • Long-run means of $41.06 nominal and $65.43 real (2025 dollars)
  • Current price of $71.53 is above both long-run means
  • Real prices show slightly less persistence than nominal prices

What would you like to explore next? Some possibilities:

  • Test for unit roots/stationarity
  • Add more lags to capture richer dynamics
  • Analyze volatility patterns
  • Compare with other commodity prices
Thu, 20 Mar 2025 18:50:40 GMT
User

Drop all months prior to 1980 and repeat the autoregression of the real prices. Plot the real prices after 1980 with a horizontal line at the long-run mean.

Fri, 21 Mar 2025 13:21:44 GMT
J
Julius
Possibly forgot to define the variable 'df_real' before using it.

Python

The code filters WTI crude oil price data from 1980 onwards, runs a linear regression to estimate the relationship between lagged prices and current prices, and plots the results along with the long-run mean.
{
…
}1 Item
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[3], line 2
      1 # Filter data from 1980 onwards
----> 2 df_real_1980 = df_real[df_real.index >= '1980-01-01'].copy()
      4 # Run regression on post-1980 data
      5 X = df_real_1980['price_lag'].values.reshape(-1, 1)

NameError: name 'df_real' is not defined
Also, evaluate what went wrong and consider options for how to fix it. Break the execution up into cell blocks.

I apologize for the error. Let's recreate the analysis step by step:

Python

The code retrieves WTI and CPI data, calculates real WTI prices adjusted for inflation, and filters the dataset for entries from 1980 onwards.
{
…
}1 Item

Python

This code snippet creates a lagged series of real WTI crude oil prices, fits a linear regression model, calculates the coefficients and long-run mean, and plots the time series with the long-run mean indicated.
{
…
}2 Items

For the post-1980 period, the AR(1) regression shows:

xt+1=1.3546+0.981xt+ϵtx_{t+1} = 1.3546 + 0.981x_t + \epsilon_txt+1​=1.3546+0.981xt​+ϵt​

Chart unavailable

Key findings from the post-1980 analysis:

  • The intercept (a) is 1.3546

  • The slope coefficient (b) is 0.981 , showing slightly less persistence than the full sample

  • The long-run mean is 71.1844 dollars per barrel in real (2025) terms

  • The R-squared is 0.9668

The long-run mean for the post-1980 period ($71.18) is notably higher than the full-sample mean we found earlier ($65.43). This reflects the generally higher real oil prices in the modern era. The persistence coefficient (b) is slightly lower at 0.981 compared to 0.988 for the full sample, suggesting somewhat faster mean reversion in the more recent period.

The plot shows that current real prices are very close to the post-1980 long-run mean, suggesting that current oil prices are near their "normal" level for the modern era when accounting for inflation.

Fri, 21 Mar 2025 13:22:52 GMT
User

What is the half life of the shocks to the crude oil price given the estimates for the post 1980 period? Explain what "half life" means.

Sun, 23 Mar 2025 02:43:04 GMT
J
Julius

The half-life is the time it takes for half of a shock to dissipate in an AR(1) process. More precisely, it's the time needed for the deviation from the long-run mean to fall to half its initial size.

For an AR(1) process: xt+1−μ=b(xt−μ)+ϵtx_{t+1} - \mu = b(x_t - \mu) + \epsilon_txt+1​−μ=b(xt​−μ)+ϵt​ where μ\muμ is the long-run mean and bbb is the AR coefficient, the half-life is given by: half-life=ln⁡(0.5)ln⁡(b)\text{half-life} = \frac{\ln(0.5)}{\ln(b)}half-life=ln(b)ln(0.5)​

Using our estimated b=0.981b = 0.981b=0.981:

Python

This code snippet calculates the half-life of a substance based on its decay factor and outputs the result in both months and years.
{
…
}1 Item

The half-life of a shock in an AR(1) process is the time it takes for half of a shock's effect to dissipate. For our estimated model:

xt+1=1.3546+0.981xt+ϵtx_{t+1} = 1.3546 + 0.981x_t + \epsilon_txt+1​=1.3546+0.981xt​+ϵt​

The half-life can be calculated as:

half-life=ln⁡(0.5)ln⁡(b)\text{half-life} = \frac{\ln(0.5)}{\ln(b)}half-life=ln(b)ln(0.5)​

where b is the AR(1) coefficient (0.981 in our case).

Half-life = 36.1 months or 3.0 years

To interpret this: if oil prices receive a shock (say, jumping $50 above their long-run mean due to a crisis), it would take about 3 years for prices to return halfway back to their long-run mean. After another 3 years, they would move half of the remaining distance, and so on.

This relatively long half-life confirms the high persistence we observed in the AR coefficient. Shocks to oil prices tend to have long-lasting effects, taking several years to substantially dissipate. This persistence reflects both:

  • The physical nature of oil markets (long-term contracts, costly storage, inflexible production)
  • The economic structure of the market (OPEC's influence, long-term investment cycles in production capacity)

The high persistence means that short-term disruptions can have effects that last for years, making the oil market particularly sensitive to geopolitical events and supply disruptions.

Sun, 23 Mar 2025 02:43:35 GMT