Skip to content

Commit

Permalink
0.9.45 update
Browse files Browse the repository at this point in the history
  • Loading branch information
zengbin93 committed Mar 16, 2024
1 parent 63724e2 commit e3a60de
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions czsc/traders/weight_backtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,10 @@ def backtest(self, n_jobs=1):
pairs_stats = {k: v for k, v in pairs_stats.items() if k in ['单笔收益', '持仓K线数', '交易胜率', '持仓天数']}
stats.update(pairs_stats)

dfw = self.dfw.copy()
long_rate = dfw[dfw['weight'] > 0].shape[0] / dfw.shape[0]
stats.update({"多头占比": long_rate})

res['绩效评价'] = stats
return res

Expand Down
6 changes: 3 additions & 3 deletions czsc/utils/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def normalize_ts_feature(df, x_col, n=10, **kwargs):
else:
raise ValueError("method 必须为 expanding 或 rolling")

# 对于缺失值,获取原始值,然后进行标准化
na_x = df[df[f"{x_col}_norm"].isna()][x_col].values
df.loc[df[f"{x_col}_norm"].isna(), f"{x_col}_norm"] = na_x - na_x.mean() / na_x.std()
# # 对于缺失值,获取原始值,然后进行标准化
# na_x = df[df[f"{x_col}_norm"].isna()][x_col].values
# df.loc[df[f"{x_col}_norm"].isna(), f"{x_col}_norm"] = na_x - na_x.mean() / na_x.std()

if f"{x_col}_qcut" not in df.columns:
if method == "expanding":
Expand Down
6 changes: 4 additions & 2 deletions czsc/utils/st_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,17 @@ def show_weight_backtest(dfw, **kwargs):
stat = wb.results['绩效评价']

st.divider()
c1, c2, c3, c4, c5, c6, c7, c8 = st.columns([1, 1, 1, 1, 1, 1, 1, 1])
c1, c2, c3, c4, c5, c6, c7, c8, c9, c10 = st.columns([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
c1.metric("盈亏平衡点", f"{stat['盈亏平衡点']:.2%}")
c2.metric("单笔收益", f"{stat['单笔收益']} BP")
c2.metric("单笔收益(BP)", f"{stat['单笔收益']}")
c3.metric("交易胜率", f"{stat['交易胜率']:.2%}")
c4.metric("持仓K线数", f"{stat['持仓K线数']}")
c5.metric("最大回撤", f"{stat['最大回撤']:.2%}")
c6.metric("年化收益率", f"{stat['年化']:.2%}")
c7.metric("夏普比率", f"{stat['夏普']:.2f}")
c8.metric("卡玛比率", f"{stat['卡玛']:.2f}")
c9.metric("年化波动率", f"{stat['年化波动率']:.2%}")
c10.metric("多头占比", f"{stat['多头占比']:.2%}")
st.divider()

dret = wb.results['品种等权日收益']
Expand Down

0 comments on commit e3a60de

Please sign in to comment.