# 对实盘BWB3做权重分配测试 **Published by:** [KeepLearning](https://paragraph.com/@keeplearning-2/) **Published on:** 2024-01-15 **URL:** https://paragraph.com/@keeplearning-2/bwb3-2 ## Content 实盘的时候有时候发现,涨了一根K线后直接就卖出了,导致后面K线的涨幅吃不到。所以就想着是否需要提高历史数据的权重,降低当前K线的权重,这样就不会对当前K线的变化很敏感,可能可以多持有几个小时K。 def custom_weights(length): weights = np.arange(1, length + 1) reversed_weights = weights[::-1] # 反转权重顺序 return reversed_weights / sum(reversed_weights) df[factor_name] = df['流动溢价'].rolling(window=n, min_periods=1).apply(lambda x: np.dot(x, custom_weights(n)),raw=True) start_date = '2020-04-01' # 回测开始时间 end_date = '2024-01-14' # 回测结束时间 参数还是168,测试结果如下 累积净值 18.64 年化收益 116.42% 最大回撤 -13.62% 用std然后再apply试试 df['流动溢价std'] = df['流动溢价'].rolling(n, min_periods=2).std() df[factor_name] = df['流动溢价std'].rolling(window=n, min_periods=1).apply(lambda x: np.dot(x, custom_weights(n)),raw=True) 累积净值 30.07 年化收益 145.52% 最大回撤 -13.75% 不做反转: def custom_weights(length): weights = np.arange(1, length + 1) return weights / sum(weights) df['流动溢价std'] = df['流动溢价'].rolling(n, min_periods=2).std() df[factor_name] = df['流动溢价std'].rolling(window=n, min_periods=1).apply(lambda x: np.dot(x, custom_weights(n)),raw=True) 累积净值 45.74 年化收益 174.28% 最大回撤 -13.78% 默认策略是多少来着? 累积净值 51.35 年化收益 182.78% 最大回撤 -12.51% 看来效果不明显啊 ## Publication Information - [KeepLearning](https://paragraph.com/@keeplearning-2/): Publication homepage - [All Posts](https://paragraph.com/@keeplearning-2/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@keeplearning-2): Subscribe to updates