forked from BOSUKE/stock_and_python_book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
execute_insert_to_raw_prices.py
34 lines (24 loc) · 1.09 KB
/
execute_insert_to_raw_prices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# pandas_datareader で株価データを取得し、raw_prices テーブルに登録する
import os
from datetime import datetime as dt, date, timedelta
from pandas_datareader import data as pdr
from dao.brands_dao import BrandsDAO
from dao.raw_prices_dao import RawPricesDAO
db_file_name = os.getcwd() + '/chapter2/stock.db'
brands_dao = BrandsDAO(db_file_name)
raw_prices_dao = RawPricesDAO(db_file_name)
code_list = brands_dao.get_brands_code_list()
for code in code_list:
if code == '7201':
latest_date_str = raw_prices_dao.get_latest_date_of_tick_code(code)
# print('code:%s, 最新日時: %s' % (code, latest_date_str))
# データ取得開始日
start='2000-01-01'
if latest_date_str != None:
latest_date = dt.strptime(latest_date_str, '%Y-%m-%d')
start = latest_date + timedelta(days = 1)
# データ取得終了日
end = '2021-06-15'
ticker_symbol = code + ".T"
pdr_df = pdr.get_data_yahoo(symbols=ticker_symbol, start=start, end=end, adjust_price=False)
raw_prices_dao.insert(code, pdr_df)