From 4d58748ab86b06acb988eccfe2ce37d2f1ada691 Mon Sep 17 00:00:00 2001 From: zengbin93 Date: Wed, 4 Dec 2024 22:59:03 +0800 Subject: [PATCH] =?UTF-8?q?0.9.61=20=E6=96=B0=E5=A2=9E=20price=5Ftype=20?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E6=8E=A7=E5=88=B6=E5=9B=9E=E6=B5=8B=E4=BA=A4?= =?UTF-8?q?=E6=98=93=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- czsc/eda.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/czsc/eda.py b/czsc/eda.py index 6b3c08038..845ef1ba8 100644 --- a/czsc/eda.py +++ b/czsc/eda.py @@ -266,12 +266,15 @@ def cal_symbols_factor(dfk: pd.DataFrame, factor_function: Callable, **kwargs): - logger: loguru.logger, 默认为 loguru.logger - factor_params: dict, 因子计算参数 - min_klines: int, 最小K线数据量,默认为 300 + - price_type: str, 交易价格类型,默认为 close,可选值为 close 或 next_open :return: dff, pd.DataFrame, 计算后的因子数据 """ logger = kwargs.get("logger", loguru.logger) min_klines = kwargs.get("min_klines", 300) factor_params = kwargs.get("factor_params", {}) + price_type = kwargs.get("price_type", "close") + symbols = dfk["symbol"].unique().tolist() factor_name = factor_function.__name__ @@ -285,7 +288,13 @@ def cal_symbols_factor(dfk: pd.DataFrame, factor_function: Callable, **kwargs): continue df = factor_function(df, **factor_params) - df["price"] = df["close"] + if price_type == 'next_open': + df["price"] = df["open"].shift(-1).fillna(df["close"]) + elif price_type == 'close': + df["price"] = df["close"] + else: + raise ValueError("price_type 参数错误, 可选值为 close 或 next_open") + df["n1b"] = (df["price"].shift(-1) / df["price"] - 1).fillna(0) factor = [x for x in df.columns if x.startswith("F#")][0]