-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
How to get optimal params from optimize method? #232
-
Hi, how do I get optimal params from optimize method? It's not specified in docs. I'd like to know optimal params, so I can use them live or to test them on different dataset (train-test split). I know there's a walkaround using method = 'skopt'
and return_optimization = True
, but I want to do exhaustive search.
Edit: I'm using heatmaps to find optimal parameters, but I'd like to automatize it for testing.
Beta Was this translation helpful? Give feedback.
All reactions
You can pass Backtest.optimize(..., return_heatmap=True)
to get back a series of all tried parameter combinations with their result values. See how to handle it in #101.
Alternatively, as the tutorial briefly mentions, you can access the best parameters as set on the strategy instance:
stats = bt.optimize(...) my_param1 = stats._strategy.my_param1 ... all_params: dict = stats._strategy._params # This is private API, may change
Replies: 1 comment 2 replies
-
You can pass Backtest.optimize(..., return_heatmap=True)
to get back a series of all tried parameter combinations with their result values. See how to handle it in #101.
Alternatively, as the tutorial briefly mentions, you can access the best parameters as set on the strategy instance:
stats = bt.optimize(...) my_param1 = stats._strategy.my_param1 ... all_params: dict = stats._strategy._params # This is private API, may change
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks, I used the method of transforming heatmap into a dataframe to get the best params
Beta Was this translation helpful? Give feedback.
All reactions
-
after returning stats and heatmap from the optimizer, you can use the heatmap to extract the parameters.
best_params = optiheatmap.idxmax()
var1 = best_params[0]
var2 = best_params[1]
var3= best_params[2]
You can then either pass these on to update your strategyclass, or just pass them to the backtest as parameters as kernc have explained how to in other threads.
Beta Was this translation helpful? Give feedback.