Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to get optimal params from optimize method? #232

Answered by kernc
TomaszLakota asked this question in Q&A
Discussion options

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.

You must be logged in to vote

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

Comment options

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
You must be logged in to vote
2 replies
Comment options

Thanks, I used the method of transforming heatmap into a dataframe to get the best params

Comment options

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.

Answer selected by TomaszLakota
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /