The DataReader: Access financial data online

Importing and Managing Financial Data in Python

Stefan Jansen

Instructor

pandas_datareader

  • Easy access to various financial internet data sources
  • Little code needed to import into a pandas DataFrame
  • Available sources include:
    • IEX and Yahoo! Finance (including derivatives)
    • Federal Reserve
    • World Bank, OECD, Eurostat
    • OANDA
Importing and Managing Financial Data in Python

Stock prices: Yahoo! Finance

from pandas_datareader.data import DataReader
from datetime import date # Date & time functionality
start = date(2015, 1, 1) # Default: Jan 1, 2010
end = date(2016, 12, 31) # Default: today

ticker = 'GOOG' data_source = 'yahoo'
stock_data = DataReader(ticker, data_source, start, end)
Importing and Managing Financial Data in Python

Stock prices: Yahoo! Finance

stock_data.info()
DatetimeIndex: 504 entries, 2015-01-02 to 2016-12-30
Data columns (total 6 columns):
 #   Column  Non-Null Count  Dtype  
 --  ------     --------------  -----
 0   High       504 non-null    float64 # First price
 1   Low        504 non-null    float64 # Highest price
 2   Open       504 non-null    float64 # Lowest price
 3   Close      504 non-null    float64 # Last price
 4   Volume     504 non-null    float64 # No shares traded
 5   Adj Close  504 non-null    float64 # Adj. price
dtypes: float64(6)
memory usage: 27.6 KB
Importing and Managing Financial Data in Python

Stock prices: Yahoo! Finance

pd.concat([stock_data.head(3), stock_data.tail(3)])
             High    Low   Open  Close  Volume    Adj Close
Date
2015-01-02  26.49  26.13  26.38  26.17  28951268  26.17
2015-01-05  26.14  25.58  26.09  25.62  41196796  25.62
2015-01-06  25.74  24.98  25.68  25.03  57998800  25.03
2016-12-28  39.71  39.16  39.69  39.25  23076000  39.25
2016-12-29  39.30  38.95  39.17  39.14  14886000  39.14
2016-12-30  39.14  38.52  39.14  38.59  35400000  38.59
Importing and Managing Financial Data in Python

Stock prices: Visualization

import matplotlib.pyplot as plt

stock_data['Close'].plot(title=ticker) plt.show()

Visualization of GOOG

Importing and Managing Financial Data in Python

Let's practice!

Importing and Managing Financial Data in Python

Preparing Video For Download...