# NOTEBOOK settings and system details: [00-tpl v14.09.28] # 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 will disable autoreload. # Generate plots inside notebook: %matplotlib inline # DISPLAY options from IPython.display import Image # e.g. Image(filename='holt-winters-equations.png', embed=True) from IPython.display import YouTubeVideo # e.g. YouTubeVideo('1j_HxD4iLn8') 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_fred import * from yi_plot import * # Get various inflation and bond statistics: ts = {} for i in ml_infl + ml_long: ts[i] = getfred(i) # Collection of inflation levels tsinf = [ ts[i] for i in ml_infl ] # Make a dataframe consists of those inf levels: inf_levels = paste( tsinf ) # Label the column names: inf_levels.columns = ['CPI', 'CPIc', 'PCE', 'PCEc'] # We are interested in year-over-year inflation rates, expressed in percent: inf = pcent( inf_levels, 12 ).dropna() boxplot( inf, 'Inflation' ) stats(inf) inf_av = todf(( inf['CPI'] + inf['CPIc'] + inf['PCE'] + inf['PCEc'] ) / 4 ) stats( inf_av ) # The shortest of our time series under consideration, m4tips10, # starts at 2003-01-01, so let start = '2003-01-01' plotdf( inf_av[start:], 'Inflation mean' ) bei = todf( ts[m4bond10] - ts[m4tips10] ) plotdf(bei[start:], 'Inflation BEI') tail(bei) bei_inf_av = todf((bei + inf_av) / 2) plotdf(bei_inf_av[start:], 'Inflation BEI av') tail(bei_inf_av) gold_daily = getfred( d4xau ) gold = monthly(gold_daily) # Monthly gold data since 1968-04-01 # Compute annualized returns: gold_ret = pcent(gold, 12) plotdf( gold_ret[start:] ) # Conversions to dataframe with label before paste: dfa = todf( inf_av, 'Iav') dfb = todf( bei, 'BEI' ) dfc = todf( bei_inf_av, 'BEI_Iav') dfd = todf( gold_ret, 'Gold' ) # Mother of all annualized inflation rates: infall = paste( [inf, dfa, dfb, dfc, dfd] ) # Correlation matrix going back to 2003-01-01 (start of BEI) cormatrix(infall) # Most recent values: tail(infall) # Let's see if our two different methods agree: infl = getfred(m4infl) inflrate = pcent(infl, 12) stat2( dfa['Iav'], inflrate['Y'] ) # Let's forecast 12 periods ahead: holtfred( infl, 12 )