Skip to content

Commit 115d2f2

Browse files
committed
feat: update ETF portfolio deposit file structure and tests for new columns
1 parent 7870bea commit 115d2f2

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

pykrx/website/krx/etx/wrap.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,18 @@ def get_etf_portfolio_deposit_file(date: str, ticker: str) -> DataFrame:
210210
211211
Returns:
212212
DataFrame:
213-
계약수 금액 비중
214-
티커
215-
005930 8175.0 694875000 16.531250
216-
000660 972.0 126360000 2.949219
217-
051910 80.0 77120000 1.849609
218-
035420 219.0 65809500 1.570312
213+
구성종목명 계약수 금액 시가총액 비중
214+
티커
215+
0724F1 ADOBE SYSTEMS INC 12.22 0 0 0.0
216+
2079K3 ALPHABET INC-CL A 61.55 0 0 0.0
217+
2079K1 ALPHABET INC-CL C 57.21 0 0 0.0
218+
255371 AMERICAN ELECTRIC POWER 15.61 0 0 0.0
219219
"""
220220

221221
isin = get_etx_isin(ticker)
222222
df = PDF().fetch(date, isin)
223-
df = df[["COMPST_ISU_CD", "COMPST_ISU_CU1_SHRS", "VALU_AMT", "COMPST_RTO"]]
224-
df.columns = ["티커", "계약수", "금액", "비중"]
223+
df = df[["COMPST_ISU_CD", "COMPST_ISU_NM","COMPST_ISU_CU1_SHRS", "VALU_AMT", "COMPST_AMT","COMPST_RTO"]]
224+
df.columns = ["티커", "구성종목명", "계약수", "금액", "시가총액", "비중"]
225225

226226
# NOTE: 웹 서버가 COMPST_ISU_CD에 ISIN과 축향형을 혼합해서 반환한다. Why?
227227
df["티커"] = df["티커"].apply(lambda x: x[3:9] if len(x) > 6 else x)
@@ -231,7 +231,7 @@ def get_etf_portfolio_deposit_file(date: str, ticker: str) -> DataFrame:
231231
# - empty string은 int, float로 형변환 불가
232232
# -> 이 문제를 해결하기 위해 '-' 문자는 0으로 치환
233233
df = df.replace(r"\-$", "0", regex=True)
234-
df = df.astype({"계약수": np.float64, "금액": np.int64, "비중": np.float32})
234+
df = df.astype({"계약수": np.float64, "금액": np.int64, "시가총액": np.int64, "비중": np.float32})
235235
df = df[(df.T != 0).any()]
236236
return df
237237

tests/integration/test_etf_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,13 @@ class TestEtfPdf:
148148
@pytest.mark.vcr
149149
def test_with_business_day(self):
150150
df = stock.get_etf_portfolio_deposit_file("152100", "20210402")
151-
temp = df.iloc[0:5, 0] == np.array([8140.0, 968.0, 218.0, 79.0, 89.0])
151+
temp = df.iloc[0:5, 1] == np.array([8140.0, 968.0, 218.0, 79.0, 89.0])
152152
assert temp.sum() == 5
153153

154154
@pytest.mark.vcr
155155
def test_with_negative_value(self):
156156
df = stock.get_etf_portfolio_deposit_file("114800", "20210402")
157-
assert df.iloc[1, 0] == pytest.approx(-3.58)
157+
assert df.iloc[1, 1] == pytest.approx(-3.58)
158158

159159

160160
class TestEtfTradingvolumeValue:

0 commit comments

Comments
 (0)