<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 On this notebook the initial steps towards solving the capstone project will be taken. Some data gathering and others...
Step1:  Getting the data
Step2:  So, Google has a limit of 15 years of data on each query
Step3:  Keep dictionary or use multiindex?
<ASSISTANT_TASK:>
Python Code:
import yahoo_finance
import requests
import datetime
def print_unix_timestamp_date(timestamp):
    print(
        datetime.datetime.fromtimestamp(
            int(timestamp)
        ).strftime('%Y-%m-%d %H:%M:%S')
    )
print_unix_timestamp_date("1420077600")
print_unix_timestamp_date("1496113200")
EXAMPLE_QUERY = "http:/query1.finance.yahoo.com/v7/finance/download/AMZN?period1=1483585200&period2=1496113200&interval=1d&events=history&crumb=mFcCyf2I8jh"
import urllib2
response = urllib2.urlopen(EXAMPLE_QUERY)
html = response.read()
csv_values = requests.get(EXAMPLE_QUERY)
csv_values
import os
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import datetime as dt
import scipy.optimize as spo
import sys
%matplotlib inline
%load_ext autoreload
%autoreload 2
pd.__version__
Explanation: On this notebook the initial steps towards solving the capstone project will be taken. Some data gathering and others...
End of explanation
import pandas_datareader as pdr
pdr.__version__
from pandas_datareader import data, wb
SPY_CREATION_DATE = dt.datetime(1993,1,22)
start = SPY_CREATION_DATE
end = dt.datetime(1995,12,31)
#Let's try to get SPY
SPY_df = data.DataReader(name='SPY',data_source='google',start=start,
                       end=end)
print(SPY_df.shape)
SPY_df.head()
from yahoo_finance import Share
yahoo = Share('YHOO')
print(yahoo.get_price())
yahoo.get_historical('2005-01-01','2016-12-31')
import pandas_datareader.data as web
SPY_CREATION_DATE = dt.datetime(1993,1,22)
start = SPY_CREATION_DATE
end = dt.datetime(2016,12,31)
tickers = ['SPY','GOOG','AAPL','NVDA']
#Create the (empty) dataframe
dates = pd.date_range(start,end)
data_df = pd.DataFrame(index=dates)
#Let's try to get SPY
SPY_df = web.DataReader(name='SPY',data_source='google',start=start,
                       end=end)
print(SPY_df.shape)
SPY_df.head()
SPY_df['Close'].plot()
(SPY_df.index[-1]-SPY_df.index[0]).days / 365
Explanation: Getting the data
End of explanation
data_df
# This will add the data of one ticker
def add_ticker(data,ticker_df,ticker_name):
    for key in data.keys():
        column_df = pd.DataFrame(ticker_df[key]).rename(columns={key:ticker_name})
        data[key] = data[key].join(column_df, how='left')
    return data
def add_tickers(data, tickers, source):
    for name in tickers:
        if(not (name in data['Open'].columns)):
            ticker_df = web.DataReader(name=name,data_source=source,start=start,end=end)
            data = add_ticker_data(data,ticker_df,name)
            print('Added: '+name)
        else:
            print(name+' was already added')
    return data
Explanation: So, Google has a limit of 15 years of data on each query
End of explanation
iterables = [SPY_df.index, SPY_df.columns]
indexes = pd.MultiIndex.from_product(iterables, names=['date', 'feature'])
data_multi = pd.DataFrame(index=indexes)
print(data_multi.shape)
data_multi.head(20)
data_multi.xs('2001-02-08', level='date')
SPY_df.iloc[0]
SPY_df.head()
data_multi['sd'] = np.nan
data_multi.loc['2001-02-05','Open']['sd'] = SPY_df.loc['2001-02-05','Open']
data_multi
SPY_df.reset_index(inplace=True)
SPY_df.head()
SPY_df.set_index(['Date','Open'])
Explanation: Keep dictionary or use multiindex?
End of explanation
<END_TASK>