perform_optimisation#
API documentation for tradeexecutor.backtest.optimiser.perform_optimisation Python function.
- perform_optimisation(iterations, search_func, decide_trades, create_indicators, strategy_universe, parameters, max_workers=<function get_safe_max_workers_count>, trading_strategy_engine_version='0.5', data_retention=GridSearchDataRetention.metrics_only, execution_context=<ExecutionContext backtesting, unspecified engine version>, indicator_storage=None, result_path=None, min_batch_size=4, real_space_rounding=Decimal('0.01'), timeout=600, log_level=None, result_filter=<tradeexecutor.backtest.optimiser.MinTradeCountFilter object>, bad_result_value=0, draw_visualisation=False, ignore_wallet_errors=True, base_estimator='gp')[source]#
Search different strategy parameters using an optimiser.
Use scikit-optimize to find the optimal strategy parameters.
The results of previous runs are cached on a disk using the same cache as grid search, though the cache is not as effective as each optimise run walks randomly around.
Unlike in grid search, indicators are calculated in the child worker processes, because we do not know what indicator values we are going to search upfront. There might a race condition between different child workers to calculate and save indicator data series, but it should not matter as cache writes are atomic.
This will likely consume gigabytes of disk space
- Parameters:
iterations (int) – How many iteratiosn we will search
search_func (SearchFunction) –
The function that will rank the optimise iteration results.
See
optimise_profit()
andoptimise_sharpe()
, but can be any of your custom functions.parameters (StrategyParameters) –
Prepared search space and fixed parameters.
See
prepare_grid_combinations()
trading_strategy_engine_version (str) – Which version of engine we are using.
result_path (pathlib.Path | None) – Where to store the grid search results
real_space_rounding –
For search dimensions that are Real numbers, round to this accuracy.
We need to write float values as cache filename parameters and too high float accuracy causes too long strings breaking filenames.
min_batch_size –
How many points we ask for the batch processing from the scikit-optimiser once.
You generally do not need to care about this.
timeout (float) –
Maximum timeout for a joblib.Parallel for a single worker process for a single iteration.
Will interrupt hung child processes if a backtest takes forever.
Increase the number if you are getting issues.
log_level (int | None) –
Control for the diagnostics.
E.g. set to logging.INFO.
result_filter (ResultFilter) –
Filter bad strategies.
Try to avoid strategies that open too few trades or are otherwise not viable.
Strategies that do not pass may be still returned, but the result filtered flag is set on.
bad_result_value – What placeholder value we use for the optimiser when result_filter does not like the outcome.
draw_visualisation –
Draw and collect visualisation data during the backtest execution when optimising.
This will slow down optimisation: use this only if you really want to collect the data.
In decide_trades() function, input.is_visualisation_enabled() will return True.
ignore_wallet_errors –
Ignore OutOfBalance exceptions.
In the case if our backtest fails due to making trades for which we do not have money, instead of crashing the whole strategy run, mark down these backtest results as zero profit.
base_estimator –
The base estimator used by scikit-optimise.
”gp” for Gaussian process.
”rf” for Random Forest.
”et” for Extra Trees
”gbrt” for Gradient Boosting Regression Tree.
https://scikit-optimize.github.io/dev/modules/minimize_functions.html#minimize-functions
decide_trades (DecideTradesProtocol4) –
create_indicators (tradeexecutor.strategy.pandas_trader.indicator.CreateIndicatorsProtocolV1 | tradeexecutor.strategy.pandas_trader.indicator.CreateIndicatorsProtocolV2) –
strategy_universe (TradingStrategyUniverse) –
data_retention (GridSearchDataRetention) –
execution_context (ExecutionContext) –
indicator_storage (tradeexecutor.strategy.pandas_trader.indicator.DiskIndicatorStorage | None) –
- Returns:
Grid search results for different combinations.
- Return type: