Skip to content

Commit

Permalink
0.9.60 新增几个 EDA 工具函数
Browse files Browse the repository at this point in the history
  • Loading branch information
zengbin93 committed Oct 31, 2024
1 parent 0ecac40 commit 5be062f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions czsc/eda.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,26 +467,28 @@ def tsf_type(df: pd.DataFrame, factor, n=5, **kwargs):
tsf 是 time series factor 的缩写,时序因子的类型定性分析,是指对某个时序因子进行分层,然后计算每个分层的平均收益,
:param df: pd.DataFrame, 必须包含 dt, symbol, factor, price 列,其中 dt 为日期,symbol 为标的代码,factor 为因子值
:param df: pd.DataFrame, 必须包含 dt, symbol, factor 列,其中 dt 为日期,symbol 为标的代码,factor 为因子值
:param factor: str, 因子列名
:param n: int, 分层数量
:param kwargs:
- window: int, 窗口大小,默认为600
- min_periods: int, 最小样本数量,默认为300
- target: str, 目标列名,默认为 n1b
:return: str, 返回分层收益排序(从大到小)结果,例如:第01层->第02层->第03层->第04层->第05层
"""
window = kwargs.get("window", 600)
min_periods = kwargs.get("min_periods", 300)
target = kwargs.get("target", "n1b")
assert target in df.columns, f"数据中不存在 {target} 列"
assert factor in df.columns, f"数据中不存在 {factor} 列"

if target == 'n1b' and 'n1b' not in df.columns:
from czsc.utils.trade import update_nxb
df = update_nxb(df, nseq=(1,))

assert target in df.columns, f"数据中不存在 {target} 列"
assert factor in df.columns, f"数据中不存在 {factor} 列"

rows = []
for symbol, dfg in df.groupby("symbol"):
dfg = dfg.copy().reset_index(drop=True)
Expand Down

0 comments on commit 5be062f

Please sign in to comment.