基于vectorbt的基础双均线策略
01,基础配置信息
1 | #conda envs:vectorbt_env |
02,行情获取和可视化
a,时间交易参数配置
1 | # Enter your parameters here |
b,获取行情和行情mask
1 | # Download data with time buffer |
origin ohlcv_wbuf size: (978, 5)
Index(['Open', 'High', 'Low', 'Close', 'Volume'], dtype='object')
wobuf_mask ohlcv size: (728, 5)

03,指标计算和可视化
1 | # fig.show_svg() |
(978,)
(978,)
(728,)
(728,)

04,信号计算,可视化
1 | # 信号计算 |


Start 2020-01-02 00:00:00+00:00
End 2022-12-30 00:00:00+00:00
Period 728
Total 6
Rate [%] 0.824176
Total Overlapping 0
Overlapping Rate [%] 0.0
First Index 2020-01-08 00:00:00+00:00
Last Index 2022-12-16 00:00:00+00:00
Norm Avg Index [-1, 1] -0.002751
Distance -> Other: Min 7.0
Distance -> Other: Max 200.0
Distance -> Other: Mean 76.333333
Distance -> Other: Std 66.503133
Total Partitions 6
Partition Rate [%] 100.0
Partition Length: Min 1.0
Partition Length: Max 1.0
Partition Length: Mean 1.0
Partition Length: Std 0.0
Partition Distance: Min 90.0
Partition Distance: Max 252.0
Partition Distance: Mean 142.6
Partition Distance: Std 65.305436
dtype: object
05,交易统计
a,基准比对
1 | dmac_pf = vbt.Portfolio.from_signals(ohlcv['Close'], dmac_entries, dmac_exits) |
Start 2020-01-02 00:00:00+00:00
End 2022-12-30 00:00:00+00:00
Period 728
Start Value 10000.0
End Value 56343.449364
Total Return [%] 463.434494
Benchmark Return [%] 433.464812
Max Gross Exposure [%] 100.0
Total Fees Paid 1154.406013
Max Drawdown [%] 37.462162
Max Drawdown Duration 319.0
Total Trades 6
Total Closed Trades 6
Total Open Trades 0
Open Trade PnL 0.0
Win Rate [%] 66.666667
Best Trade [%] 192.432267
Worst Trade [%] -14.196623
Avg Winning Trade [%] 72.994385
Avg Losing Trade [%] -9.136247
Avg Winning Trade Duration 104.0
Avg Losing Trade Duration 21.0
Profit Factor 5.95588
Expectancy 7723.908227
dtype: object

b,交易详情和可视化
1 | # Plot trades |
id col size entry_idx entry_price entry_fees exit_idx exit_price exit_fees pnl return direction status parent_id
0 0 0 210.452345 4 47.398200 24.937656 66 57.775200 30.397316 2128.529014 0.213385 0 1 0
1 1 0 210.612793 94 57.443250 30.245708 294 168.547575 88.745689 23281.000774 1.924323 0 1 1
2 2 0 174.421504 346 202.505000 88.303067 430 282.621675 123.238244 13762.529659 0.389639 0 1 2
3 3 0 157.697151 448 311.035650 122.623590 483 268.327500 105.786206 -6963.363374 -0.141966 0 1 3
4 4 0 179.995892 566 233.913325 105.258594 636 327.110175 147.196219 16522.595293 0.392429 0 1 4
