# 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('') 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' 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 ) ) # Since the slope uses daily data, we annualize it: 0.0014023 * 256 # 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 ) stats( oil ) tmin = '1998-12-10' georet( oil[tmin:] ) oiltrend = trend( oil[tmin:] ) plotfred( oiltrend ) plotfred( detrendpc(oil[tmin:]) ) # So discount 40% off the trend, # to illustrate statistical downside: tailvalue( oiltrend ) * 0.60 # We change the sampling frequency to match inflation data: oilmth = monthly( oil ) defl = getfred( m4defl ) oildefl = todf( oilmth * defl ) plotfred( oildefl ) # 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 # Do the regression: stat2( bow['Y'], oil['Y'] )