#import the BTC price dataseries’ into a

#import osimport numpy as npimport pandas as pdimport pickleimport quandlfrom datetime import datetimeimport plotly.offline as pyimport plotly.graph_objs as goimport plotly.figure_factory as ffpy.init_notebook_mode(connected=True)def get_quandl_data(quandl_id):    ”’Download and cache Quandl dataseries”’    cache_path = ‘{}.pkl’.format(quandl_id).replace(‘/’,’-‘)    try:        f = open(cache_path, ‘rb’)        df = pickle.load(f)           print(‘Loaded {} from cache’.format(quandl_id))    except (OSError, IOError) as e:        print(‘Downloading {} from Quandl’.format(quandl_id))        df = quandl.get(quandl_id, returns=”pandas”)        df.to_pickle(cache_path)        print(‘Cached {} at {}’.format(quandl_id, cache_path))    return df# Pull Kraken BTC price exchange databtc_usd_price_kraken = get_quandl_data(‘BCHARTS/KRAKENUSD’)btc_usd_price_kraken.head()# Pull pricing data for 3 more BTC exchangesexchanges = ‘COINBASE’,’BITSTAMP’,’ITBIT’exchange_data = {}exchange_data’KRAKEN’ = btc_usd_price_krakenfor exchange in exchanges:    exchange_code = ‘BCHARTS/{}USD’.format(exchange)    btc_exchange_df = get_quandl_data(exchange_code)    exchange_dataexchange = btc_exchange_df    def merge_dfs_on_column(dataframes, labels, col):    ”’Merge a single column of each dataframe into a new combined dataframe”’    series_dict = {}    for index in range(len(dataframes)):        series_dictlabelsindex = dataframesindexcol            return pd.DataFrame(series_dict)# Merge the BTC price dataseries’ into a single dataframebtc_usd_datasets = merge_dfs_on_column(list(exchange_data.values()), list(exchange_data.keys()), ‘Weighted Price’)btc_usd_datasets.tail()def df_scatter(df, title, seperate_y_axis=False, y_axis_label=”, scale=’linear’, initial_hide=False):    ”’Generate a scatter plot of the entire dataframe”’    label_arr = list(df)    series_arr = list(map(lambda col: dfcol, label_arr))        layout = go.Layout(        title=title,        legend=dict(orientation=”h”),        xaxis=dict(type=’date’),        yaxis=dict(            title=y_axis_label,            showticklabels= not seperate_y_axis,            type=scale        )    )        y_axis_config = dict(        overlaying=’y’,        showticklabels=False,        type=scale )        visibility = ‘visible’    if initial_hide:        visibility = ‘legendonly’            # Form Trace For Each Series    trace_arr =     for index, series in enumerate(series_arr):        trace = go.Scatter(            x=series.index,             y=series,             name=label_arrindex,            visible=visibility        )                # Add seperate axis for the series        if seperate_y_axis:            trace’yaxis’ = ‘y{}’.format(index + 1)            layout’yaxis{}’.format(index + 1) = y_axis_config            trace_arr.append(trace)    fig = go.Figure(data=trace_arr, layout=layout)    py.iplot(fig)# Remove 0 valuesbtc_usd_datasets.replace(0, np.nan, inplace=True)# Calculate the average BTC price as a new columnbtc_usd_datasets’avg_btc_price_usd’ = btc_usd_datasets.mean(axis=1)def get_json_data(json_url, cache_path):    ”’Download and cache JSON data, return as a dataframe.”’    try:                f = open(cache_path, ‘rb’)        df = pickle.load(f)           print(‘Loaded {} from cache’.format(json_url))    except (OSError, IOError) as e:        print(‘Downloading {}’.format(json_url))        df = pd.read_json(json_url)        df.to_pickle(cache_path)        print(‘Cached {} at {}’.format(json_url, cache_path))    return dfbase_polo_url = ‘https://poloniex.com/public?command=returnChartData&currencyPair={}&start={}&end={}&period={}’start_date = datetime.strptime(‘2015-01-01’, ‘%Y-%m-%d’) # get data from the start of 2015end_date = datetime.now() # up until todaypediod = 86400 # pull daily data (86,400 seconds per day)def get_crypto_data(poloniex_pair):    ”’Retrieve cryptocurrency data from poloniex”’    json_url = base_polo_url.format(poloniex_pair, start_date.timestamp(), end_date.timestamp(), pediod)    data_df = get_json_data(json_url, poloniex_pair)    data_df = data_df.set_index(‘date’)    return data_dfaltcoins = ‘ETH’,’LTC’,’XRP’,’ETC’,’STR’,’DASH’,’SC’,’XMR’,’XEM’altcoin_data = {}for altcoin in altcoins:    coinpair = ‘BTC_{}’.format(altcoin)    crypto_price_df = get_crypto_data(coinpair)    altcoin_dataaltcoin = crypto_price_df    altcoin_data’ETH’.tail()# Calculate USD Price as a new column in each altcoin dataframefor altcoin in altcoin_data.keys():    altcoin_dataaltcoin’price_usd’ =  altcoin_dataaltcoin’weightedAverage’ * btc_usd_datasets’avg_btc_price_usd’    # Merge USD price of each altcoin into single dataframe combined_df = merge_dfs_on_column(list(altcoin_data.values()), list(altcoin_data.keys()), ‘price_usd’)# Add BTC price to the dataframecombined_df’BTC’ = btc_usd_datasets’avg_btc_price_usd’# Chart all of the altocoin pricesdf_scatter(combined_df, ‘Cryptocurrency Prices (USD)’, seperate_y_axis=False, y_axis_label=’Coin Value (USD)’, scale=’log’)