Created
February 14, 2021 02:12
-
-
Save dharma6872/3ee40f9027c18384563565f5d4e58061 to your computer and use it in GitHub Desktop.
[주가 데이터 다운로드] #퀀트
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from pandas_datareader import data as pdr | |
import yfinance as yf | |
yf.pdr_override() | |
# 과거 주가 다운로드 함수 | |
# stock_no: 한국 주식 번호, 현재는 한국 주식만 다운로드 가능 | |
def get_stock_history_pdr(stock_no): | |
# 과거 주가 데이터, 기간은 3.5년으로 설정 | |
DT_DIFF = 365.25*3.5 | |
END_DT = datetime.datetime.now() | |
START_DT = END_DT+datetime.timedelta(days=-DT_DIFF) | |
STOCK_KS = stock_no+'.KS' | |
df = pdr.get_data_yahoo(STOCK_KS, start=START_DT.strftime("%Y-%m-%d"), end=END_DT.strftime("%Y-%m-%d")) | |
df.dropna(subset = ["Close"], inplace=True) | |
return df | |
import datetime | |
import yfinance as yf | |
# 과거 주가 다운로드 함수 | |
# stock_no: 한국 주식 번호, 현재는 한국 주식만 다운로드 가능 | |
def get_stock_history_yf(stock_no): | |
# 과거 주가 데이터, 기간은 3.5년으로 설정 | |
DT_DIFF = 365.25*3.5 | |
END_DT = datetime.datetime.now() | |
START_DT = END_DT+datetime.timedelta(days=-DT_DIFF) | |
STOCK_KS = stock_no+'.KS' | |
df = yf.Ticker(STOCK_KS).history(start=START_DT.strftime("%Y-%m-%d"), end=END_DT.strftime("%Y-%m-%d")) | |
df.dropna(subset = ["Close"], inplace=True) | |
return df | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment