0
1

More than 3 years have passed since last update.

Pythonで株価取得

Last updated at Posted at 2020-09-12

Pythonの勉強をしていく中で面白そうなモジュールがあったので使ってみました

必要なもの

pandas_datareader

以下のコードでインストールできます
pip install pandas_datarader

本題

今回はGAFAと呼ばれている企業の株価を取得しました
ほかの銘柄はYahoo Financeで検索してください

read-stock
import pandas-datareader as web
import pandas as pd
import datetime
data=web.get_data_yahoo(['GOOG','AAPL','FB','AMZN'])['Adj Close']

print(data.pct_change().tail())

出力例


Symbols         GOOG      AAPL        FB      AMZN
Date
2020-09-04 -0.030941  0.000662 -0.028820 -0.021787
2020-09-08 -0.036863 -0.067295 -0.040922 -0.043944
2020-09-09  0.016034  0.039887  0.009441  0.037707
2020-09-10 -0.016018 -0.032646 -0.020568 -0.028605
2020-09-11 -0.007376 -0.013129 -0.005521 -0.018547

簡単な説明
data:各銘柄の調整後終値(Adj Close)
pct_change():変化量を求めるメソッド
tail():DataFrameの末5行を取得

datetime
#もし取得期間を決めたいなら
data=web,get_data_yahoo(['GOOG','AAPL','FB','AMZN'],
                        start=datetime.datetime(20xx,yy,zz),
                        end=datetime.datetime(20xx,yy,zz))['Adj Close']

ほかにも
Open:始値
Close:終値
High:高値
Low:安値
Voume:出来高
などもあるそうです

0
1
1

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
0
1