GridSearchResult#
API documentation for tradeexecutor.backtest.grid_search.GridSearchResult Python class in Trading Strategy framework.
- class GridSearchResult[source]#
Bases:
object
Result for one grid combination.
Result for one grid search combination
Calculate various statistics and curves ready in a multiprocess worker
Results can be cached on a disk, as a pickle
Some of the data might not be available or discarded as per
GridSearchDataRetention
- __init__(combination, state, summary, metrics, equity_curve, returns, universe_options, cached=False, process_id=None, initial_cash=None)#
- Parameters:
combination (GridCombination) –
state (tradeexecutor.state.state.State | None) –
summary (TradeSummary) –
metrics (DataFrame) –
equity_curve (Series) –
returns (Series) –
universe_options (UniverseOptions) –
cached (bool) –
- Return type:
None
Methods
__init__
(combination, state, summary, ...[, ...])get_cagr
()Get name for this result for charts.
get_max_drawdown
()get_metric
(name)Get a performance metric from quantstats.
get_parameter
(name)Get a combination parameter value used to produce this search.
Get the Sharpe ratio of this grid search result.
How many trades this strategy made.
has_result
(combination)load
(combination)Deserialised from the cached Python pickle.
save
()Serialise as Python pickle.
Attributes
For which grid combination this result is
The full back test state
Calculated trade summary
Performance metrics
Needed for visualisations
Needed for visualisations
What backtest data range we used
Was this result read from the earlier run save
Child process that created this result.
Initial cash from the state.
- combination: GridCombination#
For which grid combination this result is
- state: tradeexecutor.state.state.State | None#
The full back test state
By the default, grid search execution drops these, as saving and loading them takes extra time, space, and state is not used to compare grid search results.
- summary: TradeSummary#
Calculated trade summary
Internal stats calculated about trades
- metrics: DataFrame#
Performance metrics
Use QuantStats lib to calculate these stats.
- universe_options: UniverseOptions#
What backtest data range we used
- initial_cash: float | None#
Initial cash from the state.
Copied here from the state, as it is needed to draw equity curves. Not available in legacy data.
- get_label()[source]#
Get name for this result for charts.
Label is grid search parameter key values
Includes only searched parameters as label
- Return type:
- get_metric(name)[source]#
Get a performance metric from quantstats.
A shortcut method.
Example:
grid_search_results = perform_grid_search( decide_trades, strategy_universe, combinations, max_workers=8, trading_strategy_engine_version="0.4", multiprocess=True, ) print("Sharpe of the first result", grid_search_results[0].get_metric("Sharpe")
- get_sharpe()[source]#
Get the Sharpe ratio of this grid search result.
- Returns:
0 if not available (the strategy made no trades).
- Return type:
- get_parameter(name)[source]#
Get a combination parameter value used to produce this search.
Useful in filtering.
filtered_results = [r for r in grid_search_results if r.combination.get_parameter("regime_filter_ma_length") is None] print(f"Grid search results without regime filter: {len(filtered_resutls)}")
- Parameters:
name – Parameter name
- Raises:
ValueError – If parameter is missing.
- Return type:
- static load(combination)[source]#
Deserialised from the cached Python pickle.
- Parameters:
combination (GridCombination) –
- __init__(combination, state, summary, metrics, equity_curve, returns, universe_options, cached=False, process_id=None, initial_cash=None)#
- Parameters:
combination (GridCombination) –
state (tradeexecutor.state.state.State | None) –
summary (TradeSummary) –
metrics (DataFrame) –
equity_curve (Series) –
returns (Series) –
universe_options (UniverseOptions) –
cached (bool) –
- Return type:
None