#這邊會將均線參數從2~240去跑跑看這239個參數中哪一個能讓最後帳戶總淨值最高
stats = bt.optimize(n1=range(2, 241, 1),maximize='Equity Final [$]')
stats
Out:
---------------------------------------------
Start 2020-01-02 00:00:00
End 2021-09-22 00:00:00
Duration 629 days 00:00:00
Exposure [%] 56.915739
Equity Final [$] 16862.610291
Equity Peak [$] 22388.556221
Return [%] 68.626103
Buy & Hold Return [%] 72.861357
Max. Drawdown [%] -24.682011
Avg. Drawdown [%] -4.579849
Max. Drawdown Duration 244 days 00:00:00
Avg. Drawdown Duration 29 days 00:00:00
# Trades 9
Win Rate [%] 22.222222
Best Trade [%] 93.488372
Worst Trade [%] -3.02392
Avg. Trade [%] 9.078804
Max. Trade Duration 296 days 00:00:00
Avg. Trade Duration 40 days 00:00:00
Expectancy [%] 11.798029
SQN 0.744065
Sharpe Ratio 0.28662
Sortino Ratio 8.522299
Calmar Ratio 0.367831
_strategy OneMA(n1=76)
dtype: object
從圖中可以發現:(紅色框部分)
期末帳戶總淨值:從15061->16862,
總報酬率:從50.6%->68.6%,
Sharpe Ratio和Sortino Ratio也都有成長,
但綠色框的勝率變低了,這也是上面提的,參數僅會根據你的目標做最佳化,未必所有數據都變好。
#這邊會將均線參數從2~240去跑跑看這239個參數中哪一個能讓最後帳戶總淨值最高
stats = bt.optimize(n1=range(2, 241, 1),maximize='Win Rate [%]')
stats
Out:
---------------------------------------------
Start 2020-01-02 00:00:00
End 2021-09-22 00:00:00
Duration 629 days 00:00:00
Exposure [%] 52.941176
Equity Final [$] 12581.739697
Equity Peak [$] 14826.858424
Return [%] 25.817397
Buy & Hold Return [%] 72.861357
Max. Drawdown [%] -18.72214
Avg. Drawdown [%] -5.958689
Max. Drawdown Duration 244 days 00:00:00
Avg. Drawdown Duration 50 days 00:00:00
# Trades 1
Win Rate [%] 100.0
Best Trade [%] 28.560535
Worst Trade [%] 28.560535
Avg. Trade [%] 28.560535
Max. Trade Duration 333 days 00:00:00
Avg. Trade Duration 333 days 00:00:00
Expectancy [%] NaN
SQN NaN
Sharpe Ratio NaN
Sortino Ratio NaN
Calmar Ratio 1.525495
_strategy OneMA(n1=171)
dtype: object
從上面的數據可以發現: