7
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pythonでQuandlAPIを使ってデータ取得した際の備忘録

Posted at

目的

pythonでQuandlAPIを使ってデータ取得した際の備忘録です。

準備

下記でQuandlをインストールします。

pip install quandl

下記からQuandlサイトへ登録してAPI keyを取得します。

Quandl API Documentation

コード

下記を参考にさせて頂きます。

pythonで東証から株価をAPI取得して、データをChartに表示させる
PythonでQuandlから金融データを取得する

また、TSEコード(東京証券取引所の証券コード)は下記を参照しています。

yahoo finance

実行コード

sample.py
import quandl
import pandas as pd
import  matplotlib.pyplot as plt

quandl.ApiConfig.api_key = 'xxxxxxx' # your API key

quandl_data = quandl.get("TSE/6902") # DENSO
quandl_data.to_csv('TSE_6902.csv')

stock = pd.read_csv('TSE_6902.csv')

stock['100MA'] = stock['Close'].rolling(window = 100, min_periods=0).mean()
stock['200MA'] = stock['Close'].rolling(window = 200, min_periods=0).mean()

fig = plt.figure()

axes = fig.add_axes([0.1, 0.1, 0.8, 0.8])

axes.plot(stock['Close'][-365:], 'black', lw = 1)
axes.plot(stock['100MA'][-365:])
axes.plot(stock['200MA'][-365:])
axes.set_xlabel('Time')
axes.set_ylabel('Price')
axes.set_title('TSE_6902_1_Year')
axes.legend()

plt.show()

実行結果

python sample.py

Figure_1.png

どのデータを使って何をするか考えることが一番難しい気がする。
日経平均株価も取れるみたいで、工夫すれば色々できそうに思います。

pythonで日経平均株価を取得してみた

参考

Quandl API Documentation
pythonで東証から株価をAPI取得して、データをChartに表示させる
PythonでQuandlから金融データを取得する
yahoo finance
日本株式のデータをスクレイピングなしで取得・リストにしたい
PythonでWebスクレイピングをしよう(株価)
pythonで日経平均株価を取得してみた

7
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?