# 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 * # Specify monthly series of interest as ms list: ms = [ m4infl, m4zero10, m4spx, m4xau, m4usdrtb, m4homepx ] names = ['Infl', 'Zero10', 'SPX', 'XAU', 'USD', 'Homes'] # Download into a dictionary: msd = {} for i in ms: msd[i] = getfred(i) # Compute the YoY percentage change: msdc = {} for i in ms: msdc[i] = pcent( msd[i], 12 ) # Construct the mega YoY dataframe: mega = paste( [ msdc[i] for i in ms ] ) # Give names to the columns for mega: mega.columns = names # Start time given by t0 t0 = '1988' stats( mega[t0:] ) # Overlapping YoY percentage change, recently: boxplot(mega[t0:], 'Assets YoYm') # where the red dot represents the latest point. # Geometric mean returns, non-overlapping, annualized: for i in range(len(ms)): print names[i], georet(msd[ms[i]][t0:], 12) # 12-periods ahead forecasts use default alpha and beta values (robust update): for i in range(len(ms)): print names[i] print holtfred(msd[ ms[i]], h=12 ) # ^we use all available data to forecast print '------------------------------------' # Specify daily series of interest: ds = [ d4zero10, d4spx, d4xau, d4eurusd, d4usdjpy ] names = [ 'Zero10', 'SPX', 'XAU', 'EURUSD', 'USDJPY' ] # Download into a dictionary: dsd = {} for i in ds: dsd[i] = getfred(i) # Compute the YoY percentage change (overlaping): dsdc = {} for i in ds: dsdc[i] = pcent( dsd[i], 256 ) # Construct the YoY dataframe: dega = paste( [ dsdc[i] for i in ds ] ) # Give names to the columns for mega: dega.columns = names # Start from the recent: u0 = '2010-01-01' # Overlapping YoY percentage change, recently: boxplot( dega[u0:], 'Assets YoYd' ) # Geometric mean returns, non-overlapping, annualized: for i in range(len(ds)): print names[i], georet( dsd[ds[i]][u0:] ) # Show esp. correlations: stats( dega[u0:] )