# 对实盘BWB3做权重分配测试

By [KeepLearning](https://paragraph.com/@keeplearning-2) · 2024-01-15

---

实盘的时候有时候发现，涨了一根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%

看来效果不明显啊

---

*Originally published on [KeepLearning](https://paragraph.com/@keeplearning-2/bwb3-2)*
