yahoo finance 에서 기가막힌 api을 제공한다.
pip install yfinance, pandas, lxml
해주고
import yfinance as yf
import matplotlib.pyplot as plt
msft = yf.Ticker("066570.KS")
#msft.info
df =msft.history(start ='2018-01-01', end = '2020-03-04')
df =msft.history(period = '1y')
df =msft.history(period = 'max')
plt.plot(list(df['Open']))
Ticker에 들어갈것은 yfinance 의 검색 symbol
여기에서 원하는 기업을 검색하면
ex) LG electronics
해당하는 symbol을 알수 있다. 066570.KS
MSFT는 마이크로 소프트
history 함수는 아래 처럼 쓸수 있음
period: data period to download (Either Use period parameter or use start and end) Valid periods are: 1d, 5d, 1mo, 3mo, 6mo, 1y, 2y, 5y, 10y, ytd, max
interval: data interval (intraday data cannot extend last 60 days) Valid intervals are: 1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo, 3mo
start: If not using period - Download start date string (YYYY-MM-DD) or datetime.
end: If not using period - Download end date string (YYYY-MM-DD) or datetime.
prepost: Include Pre and Post market data in results? (Default is False)
auto_adjust: Adjust all OHLC automatically? (Default is True)
actions: Download stock dividends and stock splits events? (Default is True)