IMPORTING & MANAGING FINANCIAL DATA IN PYTHON

[Pages:34]IMPORTING & MANAGING FINANCIAL DATA IN PYTHON

The DataReader: Access financial data

online

Importing & Managing Financial Data in Python

pandas_datareader

Easy access to various financial Internet data sources Li le code needed to import into a pandas DataFrame Available sources include:

Yahoo! and Google Finance (including derivatives) Federal Reserve World Bank, OECD, Eurostat OANDA

Importing & Managing Financial Data in Python

Stock prices: Google Finance

In [1]: from pandas_datareader.data import DataReader In [2]: from datetime import date # Date & time functionality In [3]: start = date(2015, 1, 1) # Default: Jan 1, 2010 In [4]: end = date(2016, 12, 31) # Default: today In [5]: ticker = 'GOOG' In [6]: data_source = 'google' In [7]: stock_data = DataReader(ticker, data_source, start, end)

Importing & Managing Financial Data in Python

Stock prices: Google Finance (2)

In [8]: stock_()

DatetimeIndex: 504 entries, 2015-01-02 to 2016-12-30

Data columns (total 6 columns):

Open

504 non-null float64 # First price

High

504 non-null float64 # Highest price

Low

504 non-null float64 # Lowest price

Close

504 non-null float64 # Last price

Volume

504 non-null int64 # Number of shares traded

dtypes: float64(6), int64(1)

memory usage: 32.3 KB

Importing & Managing Financial Data in Python

Stock prices: Google Finance (3)

In [10]: pd.concat([stock_data.head(3), stock_data.tail(3)])

Out[10]:

Date 2015-01-02 2015-01-05 2015-01-06 2016-12-28 2016-12-29 2016-12-30

Open

529.01 523.26 515.00 793.70 783.33 782.75

High

531.27 524.33 516.18 794.23 785.93 782.78

Low

524.10 513.06 501.05 783.20 778.92 770.41

Close

524.81 513.87 501.96 785.05 782.79 771.82

Volume

1446662 2054238 2891950 1153824

744272 1769950

Importing & Managing Financial Data in Python

Stock prices: Visualization

In [11]: import matplotlib.pyplot as plt In [12]: stock_data['Close'].plot(title=ticker) In [13]: plt.show()

IMPORTING & MANAGING FINANCIAL DATA IN PYTHON

Let's practice!

IMPORTING & MANAGING FINANCIAL DATA IN PYTHON

Economic data from the Federal Reserve

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download