출처 : 금융 데이터 분석을 위한 파이썬 판다스
예제파일
import pykrx
print(pykrx.__version__)
from pykrx import stock
from datetime import datetime
today = datetime.today().strftime("%Y%m%d")
#특정일자 종목code list / name 반환
tickers = stock.get_market_ticker_list(today)
L = []
for code in tickers:
name =stock.get_market_ticker_name(code)
L.append([code,name])
print(L)
# kosdaq 업종code list 반환
tickers = stock.get_market_ticker_list(market="KOSDAQ")
L = []
for code in tickers:
name =stock.get_market_ticker_name(code)
L.append([code,name])
print(L)
# 업종분류코드
tickers = stock.get_index_ticker_list(today)
L = []
for code in tickers:
name =stock.get_index_ticker_name(code)
L.append([code,name])
print(L)
from pykrx import stock
from datetime import datetime
today = datetime.today().strftime("%Y%m%d")
start = datetime(2020,1,1).strftime("%Y%m%d")
code = "002290"
period = 'm'
#종목 ohlcv dataframe 반환
df = stock.get_market_ohlcv(start,today,code)
print(df)
#종목 ohlcv dataframe 반환(월단위)
df = stock.get_market_ohlcv(start,today,code,period)
print(df)
#종목 ohlcv dataframe 반환(비수정주가)
df = stock.get_market_ohlcv(start,today,code,adjusted=False)
print(df)
#특정일 종목 ohlcv dataframe 반환
# 조회 일자가 휴일이라면 기본적으로 다음 영업일을 탐색합니다.
df = stock.get_market_ohlcv(today,prev=True)
import pandas as pd
from pykrx import stock
from datetime import datetime
today = datetime.today().strftime("%Y%m%d")
start = datetime(2020,1,1).strftime("%Y%m%d")
minus = pd.Timedelta(days=1)
today1 = (datetime.today()-minus).strftime("%Y%m%d")
code = "002290"
period = 'm'
# 특정일자 전종목 fundamental 반환
df = stock.get_market_fundamental(today,prev=True)
print(df)
df = stock.get_market_fundamental(start,today,code)
print(df)
import pandas as pd
from pykrx import stock
from datetime import datetime
today = datetime.today().strftime("%Y%m%d")
start = datetime(2020,1,1).strftime("%Y%m%d")
minus = pd.Timedelta(days=1)
today1 = (datetime.today()-minus).strftime("%Y%m%d")
code = "002290"
period = 'm'
# 가격 등락폭
df = stock.get_market_price_change(start, "20220412",market='KOSDAQ')
print(df)
value = df.loc[code,'등락률']
print(value)
# 시가총액을 조회
df = stock.get_market_cap(today1)
print(df)
# 시가총액을 조회
df = stock.get_market_cap(today1)
print(df)
import pandas as pd
from pykrx import stock
from datetime import datetime
df = stock.get_market_cap("20000104")
s0 = df['시가총액'].sort_values(ascending=False).iloc[:5]
df = stock.get_market_cap("20190102")
s1 = df['시가총액'].sort_values(ascending=False).iloc[:5]
data = [s0.reset_index(), s1.reset_index()]
df = pd.concat(data, keys=["2000년도", "2019년도"], axis=1)
print(df)
2000년도 2019년도
티커 시가총액 티커 시가총액
0 030200 52761742371000 005930 231329073812500
1 005930 45775746373500 000660 44116943319000
2 032390 32953692333000 068270 26910340528500
3 017670 31675945000000 005935 26003219720000
4 015760 23036081220000 207940 24745710000000
'DataFrame' 카테고리의 다른 글
Data 관리 Main (0) | 2022.04.14 |
---|---|
finance-datareader (0) | 2022.04.13 |
plot (0) | 2022.04.12 |
데이터 샘플링 (0) | 2022.04.09 |
컬럼 shift (0) | 2022.04.09 |
댓글