Skip to content

Commit

Permalink
0.9.57 新增 get_stk_strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
zengbin93 committed Jul 28, 2024
1 parent 4695f8f commit e6de220
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions czsc/connectors/cooperation.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,27 @@ def upload_strategy(df, meta, token=None, **kwargs):

logger.info(f"上传策略接口返回: {response.json()}")
return response.json()


def get_stk_strategy(name="STK_001", **kwargs):
"""获取 STK 系列子策略的持仓权重数据
:param name: str
子策略名称
:param kwargs: dict
sdt: str, optional
开始日期,默认为 "20170101"
edt: str, optional
结束日期,默认为当前日期
"""
dfw = dc.post_request(api_name=name, v=2, hist=1)
dfw["dt"] = pd.to_datetime(dfw["dt"])
sdt = kwargs.get("sdt", "20170101")
edt = pd.Timestamp.now().strftime("%Y%m%d")
edt = kwargs.get("edt", edt)
dfw = dfw[(dfw["dt"] >= pd.to_datetime(sdt)) & (dfw["dt"] <= pd.to_datetime(edt))].copy().reset_index(drop=True)

dfb = stocks_daily_klines(sdt=sdt, edt=edt, nxb=(1, 2))
dfw = pd.merge(dfw, dfb, on=["dt", "symbol"], how="left")
dfh = dfw[["dt", "symbol", "weight", "n1b"]].copy()
return dfh

0 comments on commit e6de220

Please sign in to comment.