In [1]:
import pandas as pd
import matplotlib.pyplot as plt
import datetime
import numpy as np
import pinkfish as pf
# format price data
pd.options.display.float_format = '{:0.2f}'.format
%matplotlib inline
In [2]:
# set size of inline plots
'''note: rcParams can't be in same cell as import matplotlib
or %matplotlib inline
%matplotlib notebook: will lead to interactive plots embedded within
the notebook, you can zoom and resize the figure
%matplotlib inline: only draw static images in the notebook
'''
plt.rcParams["figure.figsize"] = (10, 7)
In [3]:
#symbols = ['SPY', 'GLD', 'BOND', 'EEM', 'IYR',
# 'JNK', 'LQD', 'NLY', 'PFF', 'PGX',
# 'SLY', 'TIP', 'TLT', 'BSV', 'VNQ']
symbols = ['GLD', 'GDX']
#symbols = ['SPY', '^GSPC']
start = datetime.datetime(1900, 1, 1)
end = datetime.datetime.now()
In [4]:
# fetch timeseries
portfolio = pf.Portfolio()
ts = portfolio.fetch_timeseries(symbols, start, end, fields=['close'])
In [5]:
ts, start = portfolio.finalize_timeseries(ts, start)
In [6]:
corr_df = portfolio.correlation_map(ts)
corr_df
Out[6]: