We examine the history of oil prices, and their spreads. Real prices give additional insight, along with some of the statistical characteristics used in financial economics.
[Unless otherwise noted, the price per barrel is in U.S. dollars. Near the conclusion, we use USD index units.]
Dependencies:
- Linux, bash [not crucial, cross-platform prefered]
- Python: matplotlib, pandas [recommend Anaconda distribution]
- Modules: yi_1tools, yi_plot, yi_timeseries, yi_fred
CHANGE LOG
2015-05-26 Code review and revision.
2014-10-09 First version for oil, using 2014-09-28 Template.
# NOTEBOOK settings and system details: [00-tpl v14.12.21]
# Assume that the backend is LINUX (our particular distro is Ubuntu, running bash shell):
print '\n :: TIMESTAMP of last notebook execution:'
!date
print '\n :: IPython version:'
!ipython --version
# Automatically reload modified modules:
%load_ext autoreload
%autoreload 2
# 0 disables autoreload.
# Generate plots inside notebook:
%matplotlib inline
# DISPLAY options
from IPython.display import Image
# e.g. Image(filename='holt-winters-equations.png', embed=True) # url= also works
from IPython.display import YouTubeVideo
# e.g. YouTubeVideo('1j_HxD4iLn8', start='43', width=600, height=400)
from IPython.display import HTML # useful for snippets
# e.g. HTML('<iframe src=http://en.mobile.wikipedia.org/?useformat=mobile width=700 height=350></iframe>')
import pandas as pd
print '\n :: pandas version:'
print pd.__version__
# pandas DataFrames are represented as text by default; enable HTML representation:
# [Deprecated: pd.core.format.set_printoptions( notebook_repr_html=True ) ]
pd.set_option( 'display.notebook_repr_html', False )
# MATH display, use %%latex, rather than the following:
# from IPython.display import Math
# from IPython.display import Latex
print '\n :: Working directory (set as $workd):'
workd, = !pwd
print workd + '\n'
:: TIMESTAMP of last notebook execution: Tue May 26 10:26:40 PDT 2015 :: IPython version: 2.3.0 :: pandas version: 0.15.0 :: Working directory (set as $workd): /home/yaya/Dropbox/ipy/fecon235/nb
from yi_1tools import *
from yi_plot import *
from yi_timeseries import *
from yi_fred import *
# Retreive daily data:
brent = getfred( d4brent )
wti = getfred( d4wti )
# BoW: Brent over WTI spread:
bow = todf( brent - wti )
plotfred( bow )
# Let's look at BoW trend since 1999:
plotfred( trend( bow ) )
:: regresstime slope = 0.00140233726321
# Since the slope uses daily data, we annualize it:
0.0014023 * 256
0.3589888
Over the long haul, we can anticipate BoW to increase $0.36 annually per barrel, though there will be very large deviations around the expected $6 spread. Note that the composition of Brent oil benchmark no longer really represents Brent as an location.
# Set wtbrent, the primary weight for OIL:
wtbrent = 0.50
# 0.50 represents the mean
# ==================================
wtwti = 1 - wtbrent
oil = todf( (wtbrent * brent) + (wtwti * wti) )
plotfred( oil )
The Great Recession plunge from $140 to $40 is extraordinary.
[At equal weights, we have created two convenience series called d4oil and m4oil.]
stats( oil )
Y count 7304.000000 mean 44.469187 std 32.819087 min 9.960000 25% 18.948750 50% 27.170000 75% 68.925000 max 144.630000 :: Index on min: Y 1998-12-10 dtype: datetime64[ns] :: Index on max: Y 2008-07-03 dtype: datetime64[ns] :: Head: Y T 1987-05-20 19.190 1987-05-21 19.200 1987-05-22 19.115 1987-05-25 19.140 1987-05-26 18.990 1987-05-27 18.990 1987-05-28 18.940 :: Tail: Y T 2015-05-08 61.615 2015-05-11 61.025 2015-05-12 62.905 2015-05-13 63.415 2015-05-14 62.735 2015-05-15 62.210 2015-05-18 62.295 :: Correlation matrix: Y Y 1
tmin = '1998-12-10'
georet( oil[tmin:] )
[10.97, 16.3, 32.66, 256]
May 2015: The geometric return since tmin is around 11% with volatility of 33% -- both very high relative to traditional assets.
The technical support for the 1998 uptrend on the chart is currently $45.40 (on 2015-01-29).
oiltrend = trend( oil[tmin:] )
plotfred( oiltrend )
:: regresstime slope = 0.0221070094873
plotfred( detrendpc(oil[tmin:]) )
:: regresstime slope = 0.0221070094873
From the +100% deviation on 2008-07-03, we see that our record HIGH of $144.63 was an one-time explosive blow-off.
# So discount 40% off the trend,
# to illustrate statistical downside:
tailvalue( oiltrend ) * 0.60
65.95000820390936
# We change the sampling frequency to match inflation data:
oilmth = monthly( oil )
defl = getfred( m4defl )
oildefl = todf( oilmth * defl )
plotfred( oildefl )
Here the supportive 1998 uptrend is broken by the recent crash in prices. The level support from the 1990's is around $20 in real terms.
Here we are interested in how oil prices appear outside the United States. A basket of trade-weighted currencies against USD helps our foreign exchange viewpoint.
# rtb is the real trade-weighted USD index,
# computed monthly by the Federal Reserve.
rtb = getfred( m4usdrtb )
oilrtb = todf( oil / rtb )
# cf. "oil" in dollars
plotfred( oilrtb )
# ^in index units
No big suprises here. Oil from world-ex-USD perspective looks very similar to the dollar-only perspective.
# Do the regression:
stat2( bow['Y'], oil['Y'] )
:: FIRST variable: count 7304.00000 mean 0.71444 std 5.75087 min -22.18000 25% -1.88000 50% -1.25000 75% -0.02750 max 29.59000 Name: Y, dtype: float64 :: SECOND variable: count 7304.000000 mean 44.469187 std 32.819087 min 9.960000 25% 18.948750 50% 27.170000 75% 68.925000 max 144.630000 Name: Y, dtype: float64 :: CORRELATION 0.627241758244 -------------------------Summary of Regression Analysis------------------------- Formula: Y ~ <x> + <intercept> Number of Observations: 7304 Number of Degrees of Freedom: 2 R-squared: 0.3934 Adj R-squared: 0.3933 Rmse: 4.4792 F-stat (1, 7302): 4736.2260, p-value: 0.0000 Degrees of Freedom: model 1, resid 7302 -----------------------Summary of Estimated Coefficients------------------------ Variable Coef Std Err t-stat p-value CI 2.5% CI 97.5% -------------------------------------------------------------------------------- x 0.1099 0.0016 68.82 0.0000 0.1068 0.1130 intercept -4.1732 0.0883 -47.28 0.0000 -4.3462 -4.0002 ---------------------------------End of Summary---------------------------------
Does the price of oil influence the BoW spread? Not much, the correlation is about 63%. And linear regression does not show anything reliable. Maybe: take 10% of the oil price and subtract $4 to roughly guess at BoW.
The bottom of the barrel is in the region of $45.40 to $66 with respect to our weighted oil series. The lower range derives from the technical uptrend dating back to 1998, which is also the year of our record low. The upper range is an estimate derived from statistical trend deviation.
A definitive break of the $45.40 mark would look downward at the $20 support in real dollars.
Before taking a position in oil, carefully evaluate the premium of Brent over WTI.
A complete analysis would include the impact of shale oil.
If ISIS becomes dominate over oil fields, expect some minor supply at half the market price.