IT Guy

IT、AI / Machine Learning、IoT、Project Management、プログラミング、ITIL等々

Pythonサンプルコード - Quandl

概要

  • Quandlから株価情報などの金融情報を取得

Quandl

  • 世界の金融情報、統計情報をAPIで提供するサイト
  • Quandl
  • APIを利用するためには、Quandlサイトからユーザー登録(無料利用も可能)によって、APIキーを取得する(これをコードの中に設定)必要がある。

Python3からの利用方法

  • 下記のようにpipでquandlモジュールをインストール
$ pip3 install quandl

サンプルコード

import quandl
quandl.ApiConfig.api_key = 'XXXXXXXXXXXXXXXXXXXX'    # Quandlから取得した自分のAPIキー   

# get the table for daily stock prices and,
# filter the table for selected tickers, columns within a time range
# set paginate to True because Quandl limits tables API to 10,000 rows per call

data = quandl.get_table('WIKI/PRICES', ticker = ['AAPL', 'MSFT', 'WMT'],
                        qopts = { 'columns': ['ticker', 'date', 'adj_close'] },
                        date = { 'gte': '2015-12-31', 'lte': '2016-12-31' },
                        paginate=True)
print(data.head())