LOADING
1526 字
8 分钟
vectorbt学习_52DMA之十二回顾小节

接上一篇文章《29DMA之七回顾小节》

DMA之八滑窗网格参数优选(止损,止盈)#

回测结果汇总

原始双均线#

参数

fast_windows = np.arange(10, 50,5)
slow_multis = np.arange(1.5, 5.5, 0.5)

最佳参数

in_best_index[:5]
MultiIndex([( 0, 35, 2.0),
( 1, 10, 4.5),
( 2, 10, 2.0),
( 3, 25, 3.5),
( 4, 40, 5.0),
( 5, 35, 5.0),
( 6, 10, 1.5),
( 7, 45, 3.0),
( 8, 40, 1.5),
( 9, 20, 1.5),
(10, 25, 1.5)],
names=['split_idx', 'dualma_fast_window', 'dualma_slow_multi'])

最佳参数样本内网sharp

最佳参数测试集回测表现

最佳参数验证集回测表现

简单说明:对于训练集合,其整体时间为2T,2倍于预测时间。 所以 01,训练集和验证集数据图上,即使同一种颜色也无太大比较意义
02,训练集绿色线高于蓝色线,说明参数优选效果(拟合效果,训练效果)较好。这也是合理,毕竟用训练的最优最结果又用来回测自身,效果当然也应当好嘛。 03,验证集绿色高于蓝色越多越好,说明相对简单持有具有超额收益。当然实际上有难度,尤其是行情好时。由于策略需要控制风险(追求高sharpe),所以时间维度难以持续满仓,所以牛市可能不如稳定持有,但是遇到大跌时,规避风险的优势就很明显了。

跟踪止损#

参数

sl_stops = [0.05,0.1,0.15,0.20]
sl_trail=True

最佳参数

MultiIndex([( 0, 35, 2.0, 0.1),
( 1, 15, 4.0, 0.05),
( 2, 10, 2.0, 0.05),
( 3, 10, 1.5, 0.1),
( 4, 40, 5.0, 0.2),
( 5, 35, 5.0, 0.2),
( 6, 10, 4.0, 0.1),
( 7, 45, 2.5, 0.2),
( 8, 40, 1.5, 0.2),
( 9, 20, 1.5, 0.1),
(10, 30, 1.5, 0.05)],
names=['split_idx', 'dualma_fast_window', 'dualma_slow_multi', 'sl_stop'])

最佳参数样本内网sharp

最佳参数测试集回测表现

最佳参数验证集回测表现

跟踪止损+np.inf#

参数

sl_stops = [np.inf,0.05,0.1,0.15,0.20]
sl_trail=True

最佳参数

merged_df[in_test_best_index_basic]
in_sharpe in_return out_sharpe out_return
split_idx dualma_fast_window dualma_slow_multi sl_stop
0 35 2.0 0.10 1.979770 0.319978 -2.876613 -0.124038
1 15 4.0 0.05 0.324361 0.016997 2.231171 0.195700
2 10 2.0 0.05 1.844657 0.303627 2.693463 0.161817
3 25 3.5 inf 3.374967 1.233830 3.996941 0.571024
4 40 5.0 inf 4.501923 2.451051 0.688785 0.053886
5 35 5.0 0.20 2.959891 1.144421 -2.467499 -0.193663
6 10 4.0 0.10 3.029320 0.727907 -1.060044 -0.073690
7 45 3.0 inf 2.296182 0.749108 inf 0.000000
8 40 1.5 inf 2.489317 0.692895 3.678357 0.449287
9 20 1.5 inf 2.926436 0.575073 2.364898 0.128734
10 30 1.5 0.05 2.402594 0.302466 -4.323912 -0.074724

最佳参数样本内网sharp

最佳参数测试集回测表现

最佳参数验证集回测表现

止损止盈#

sl_stops = [0.05,0.1,0.15,0.20]
sl_trails = [False, True]
tp_stops = [0.1, 0.2]

最佳参数

MultiIndex([( 0, 45, 2.0, 0.05, False, 0.1),
( 1, 15, 4.0, 0.05, False, 0.1),
( 2, 10, 2.0, 0.05, True, 0.2),
( 3, 10, 2.0, 0.05, True, 0.2),
( 4, 15, 1.5, 0.05, False, 0.2),
( 5, 40, 3.5, 0.2, False, 0.2),
( 6, 20, 4.0, 0.05, False, 0.2),
( 7, 25, 2.0, 0.05, False, 0.2),
( 8, 40, 1.5, 0.1, False, 0.2),
( 9, 30, 5.0, 0.1, False, 0.2),
(10, 30, 3.0, 0.05, False, 0.2)],
names=['split_idx', 'dualma_fast_window', 'dualma_slow_multi', 'sl_stop', 'sl_trail', 'tp_stop'])

最佳参数样本内网sharp

最佳参数训练集回测表现

最佳参数验证集回测表现

止损止盈+np.inf#

参数

sl_stops = [np.inf,0.05,0.1,0.15,0.20]
sl_trails = [False, True]
tp_stops = [np.inf,0.1, 0.2]

最佳参数

merged_df[in_test_best_index_basic]
in_sharpe in_return out_sharpe out_return
split_idx dualma_fast_window dualma_slow_multi sl_stop sl_trail tp_stop
0 45 2.0 inf False 0.1 3.158667 0.237753 -0.929956 -0.064111
1 15 4.0 inf False 0.1 0.664945 0.034948 2.563318 0.145963
2 10 3.0 0.05 False inf 1.978273 0.408342 1.451395 0.064199
3 25 3.5 inf False inf 3.374967 1.233830 3.996941 0.571024
4 15 1.5 inf False 0.2 5.245280 1.127771 2.858175 0.239233
5 35 5.0 0.20 True inf 2.959891 1.144421 -2.467499 -0.193663
6 20 4.0 inf False 0.2 4.039079 0.462475 1.890751 0.207220
7 45 3.0 inf False inf 2.296182 0.749108 inf 0.000000
8 40 1.5 inf False 0.2 2.665200 0.492175 2.449875 0.239941
9 30 5.0 inf False 0.2 3.738112 0.507262 -0.434888 -0.063484
10 30 3.0 inf False 0.2 2.943695 0.258812 -3.877240 -0.075374

最佳参数样本内网sharp

最佳参数测试集回测表现

最佳参数验证集回测表现

DMA之九滑窗网格参数优选(4种参数优选)#

回测结果汇总

参数
4种优选方法 训练集夏普sharp ratio
4种优选方法 验证集夏普sharp ratio 4种优选方法 最佳参数测试集回测表现 4种优选方法 最佳参数验证集回测表现

跟踪止损#

参数

fast_windows = np.arange(10, 50,5)
slow_multis = np.arange(1.5, 5.5, 0.5)
sl_stops = [0.05,0.1,0.15,0.20]
sl_trails = True
无止盈

4种优选方法 训练集夏普sharp ratio
svg

4种优选方法 验证集夏普sharp ratio

svg

4种优选方法 最佳参数测试集回测表现 svg

4种优选方法 最佳参数验证集回测表现
svg

非跟踪止损#

参数

fast_windows = np.arange(10, 50,5)
slow_multis = np.arange(1.5, 5.5, 0.5)
sl_stops = [0.05,0.1,0.15,0.20]
sl_trails = False
无止盈

4种优选方法 训练集夏普sharp ratio

4种优选方法 验证集夏普sharp ratio

4种优选方法 最佳参数测试集回测表现
4种优选方法 最佳参数验证集回测表现

跟踪止损+止盈#

参数

fast_windows = np.arange(10, 50,5)
slow_multis = np.arange(1.5, 5.5, 0.5)
sl_stops = [0.05,0.1,0.15,0.20]
sl_trails = True
tp_stops = [0.1, 0.2]

参数
4种优选方法 训练集夏普sharp ratio

4种优选方法 验证集夏普sharp ratio
4种优选方法 最佳参数测试集回测表现
4种优选方法 最佳参数验证集回测表现

非跟踪止损+止盈#

参数

fast_windows = np.arange(10, 50,5)
slow_multis = np.arange(1.5, 5.5, 0.5)
sl_stops = [0.05,0.1,0.15,0.20]
sl_trails = False
tp_stops = [0.1, 0.2]

4种优选方法 训练集夏普sharp ratio

4种优选方法 验证集夏普sharp ratio
4种优选方法 最佳参数测试集回测表现
4种优选方法 最佳参数验证集回测表现

DMA之十滑窗网格参数优选(过滤器)#

std_indicator#

过滤器规则:

std_close_wbuf = ohlcv_wbuf['Close'].rolling(window=20).std()
std_close_ma_wbuf = std_close_wbuf.rolling(window=20).mean()
std_close=std_close_wbuf[wobuf_mask]
std_close_ma=std_close_ma_wbuf[wobuf_mask]
std_indicator = (std_close > std_close_ma )

4种优选方法的训练集夏普sharp ratio
svg

4种优选方法的验证集夏普sharp ratio
svg 样本内滚动收益
svg

样本外滚动收益 svg

diff_indicator#

过滤器规则:

diff_close_wbuf = ohlcv_wbuf['Close'] - ohlcv_wbuf['Close'].rolling(window=int(20/5)).mean().shift(20)
diff_close_ma_wbuf = diff_close_wbuf.rolling(window=20).mean()
diff_close=diff_close_wbuf[wobuf_mask]
diff_close_ma=diff_close_ma_wbuf[wobuf_mask]
diff_indicator = ((diff_close > diff_close_ma )&(diff_close_ma>200*0.0025*20))

4种优选方法的训练集夏普sharp ratio
4种优选方法的验证集夏普sharp ratio

样本内滚动收益

样本外滚动收益

小节#

过滤器优化后,相比原始的:DMA之九滑窗网格参数优选(4种参数优选)
其sharpe和收益曲线均未见明显改善,但过滤后可视化角度看,的确过滤掉部分低波动行情。

vectorbt学习_52DMA之十二回顾小节
/posts/quant/9e2ab3fc/
作者
思想的巨人
发布于
2024-07-27
许可协议
CC BY-NC-SA 4.0

部分信息可能已经过时