In [1]:
import quandl
import pandas as pd
In [2]:
# Specify tickers we want
tickers = ["fb aapl googl amzn nflx v ge tsla brk_b ko"]

# Make them all upper case, and individual items in a list
tickers = [tic.upper().split() for tic in tickers]

# Flatten the nested list
tickers = [tic for sublist in tickers for tic in sublist]

# Add "WIKI/" as a prefix and ".11" as a suffix to each ticker
tickers_quandl = ["WIKI/" + tic + '.11' for tic in tickers]
In [3]:
tickers_quandl
Out[3]:
['WIKI/FB.11',
 'WIKI/AAPL.11',
 'WIKI/GOOGL.11',
 'WIKI/AMZN.11',
 'WIKI/NFLX.11',
 'WIKI/V.11',
 'WIKI/GE.11',
 'WIKI/TSLA.11',
 'WIKI/BRK_B.11',
 'WIKI/KO.11']
In [4]:
# Extract Adj. Close data for all stocks
prices_df = quandl.get(tickers_quandl, start_date="2009-01-01")
In [5]:
prices_df.head()
Out[5]:
WIKI/FB - Adj. Close WIKI/AAPL - Adj. Close WIKI/GOOGL - Adj. Close WIKI/AMZN - Adj. Close WIKI/NFLX - Adj. Close WIKI/V - Adj. Close WIKI/GE - Adj. Close WIKI/TSLA - Adj. Close WIKI/BRK_B - Adj. Close WIKI/KO - Adj. Close
Date
2009-01-02 NaN 11.662640 161.157478 54.36 4.267143 12.529471 12.602981 NaN 66.46 17.550313
2009-01-05 NaN 12.154848 164.532897 54.06 4.562857 12.618565 12.278124 NaN 66.98 17.374427
2009-01-06 NaN 11.954366 167.547202 57.36 4.705714 13.507164 12.447935 NaN 66.66 17.095305
2009-01-07 NaN 11.696053 161.503546 56.20 4.672857 13.214090 11.894202 NaN 63.80 17.179424
2009-01-08 NaN 11.913242 163.098469 57.16 4.735714 13.073415 11.916351 NaN 65.34 17.297955
In [6]:
# Remove "WIKI/" and "Adj. Close" from each column
prices_df.rename(columns={col : col.split('/')[1].split()[0] for col in prices_df.columns},
                inplace=True)
In [7]:
prices_df.head()
Out[7]:
FB AAPL GOOGL AMZN NFLX V GE TSLA BRK_B KO
Date
2009-01-02 NaN 11.662640 161.157478 54.36 4.267143 12.529471 12.602981 NaN 66.46 17.550313
2009-01-05 NaN 12.154848 164.532897 54.06 4.562857 12.618565 12.278124 NaN 66.98 17.374427
2009-01-06 NaN 11.954366 167.547202 57.36 4.705714 13.507164 12.447935 NaN 66.66 17.095305
2009-01-07 NaN 11.696053 161.503546 56.20 4.672857 13.214090 11.894202 NaN 63.80 17.179424
2009-01-08 NaN 11.913242 163.098469 57.16 4.735714 13.073415 11.916351 NaN 65.34 17.297955