In [2]:
import pandas as pd
import pandas.io.data as web
import datetime


/home/harish/anaconda2/lib/python2.7/site-packages/pandas/io/data.py:35: FutureWarning: 
The pandas.io.data module is moved to a separate package (pandas-datareader) and will be removed from pandas in a future version.
After installing the pandas-datareader package (https://github.com/pydata/pandas-datareader), you can change the import ``from pandas.io import data, wb`` to ``from pandas_datareader import data, wb``.
  FutureWarning)

In [3]:
start = datetime.datetime(2016,1,1)
end = datetime.date.today()

In [4]:
google = web.DataReader("GOOGL", "yahoo", start, end)

In [5]:
type(google)


Out[5]:
pandas.core.frame.DataFrame

In [6]:
google.head()


Out[6]:
Open High Low Close Volume Adj Close
Date
2016-01-04 762.200012 762.200012 747.539978 759.440002 3369100 759.440002
2016-01-05 764.099976 769.200012 755.650024 761.530029 2260800 761.530029
2016-01-06 750.369995 765.729980 748.000000 759.330017 2410300 759.330017
2016-01-07 746.489990 755.309998 735.280029 741.000000 3156600 741.000000
2016-01-08 747.799988 750.119995 728.919983 730.909973 2375300 730.909973

In [7]:
import matplotlib.pyplot as plt
%matplotlib inline
%pylab inline
pylab.rcParams['figure.figsize'] = (15, 9)


Populating the interactive namespace from numpy and matplotlib

In [8]:
google["Adj Close"].plot(grid = True)


Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fee98738850>

In [9]:
amazon = web.DataReader("AMZN", "yahoo", start, end)
facebook = web.DataReader("FB", "yahoo", start, end)

In [10]:
stocks = pd.DataFrame({"GOOGL": google["Adj Close"],
                      "AMZN": amazon["Adj Close"],
                      "FB": facebook["Adj Close"]})

In [11]:
stocks.head()


Out[11]:
AMZN FB GOOGL
Date
2016-01-04 636.989990 102.220001 759.440002
2016-01-05 633.789978 102.730003 761.530029
2016-01-06 632.650024 102.970001 759.330017
2016-01-07 607.940002 97.919998 741.000000
2016-01-08 607.049988 97.330002 730.909973

In [12]:
stocks.plot(grid = True)


Out[12]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fee963aa350>

In [13]:
stocks.plot(secondary_y = ["FB"], grid = True)


Out[13]:
<matplotlib.axes._subplots.AxesSubplot at 0x7fee9625d590>

In [14]:
stocks_return = stocks.apply(lambda x: x / x[0])
stocks_return.head()


Out[14]:
AMZN FB GOOGL
Date
2016-01-04 1.000000 1.000000 1.000000
2016-01-05 0.994976 1.004989 1.002752
2016-01-06 0.993187 1.007337 0.999855
2016-01-07 0.954395 0.957934 0.975719
2016-01-08 0.952998 0.952162 0.962433

In [15]:
stocks_return.plot(grid = True).axhline(y = 1, color="black", lw=2)


Out[15]:
<matplotlib.lines.Line2D at 0x7fee96064c90>

In [20]:
# BHARTIARTL.NS
airtel = web.DataReader("BHARTIARTL.NS", "yahoo", start, end)

In [21]:
airtel.head()


Out[21]:
Open High Low Close Volume Adj Close
Date
2016-01-01 339.95 344.00 337.65 340.50 1250200 339.163
2016-01-04 338.00 338.95 321.00 326.80 3152700 325.517
2016-01-05 327.00 328.75 321.00 323.45 2118900 322.180
2016-01-06 325.90 332.50 319.65 322.20 2414100 320.935
2016-01-07 320.90 325.80 316.60 322.35 2825700 321.085

In [ ]: