hyperopt --min-trades parameter
This commit is contained in:
parent
e1acf0a94d
commit
e7b81e4d46
@ -325,6 +325,15 @@ class Arguments(object):
|
|||||||
type=Arguments.check_int_positive,
|
type=Arguments.check_int_positive,
|
||||||
metavar='INT',
|
metavar='INT',
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--min-trades',
|
||||||
|
help="Set minimal desired number of trades for evaluations in the hyperopt "
|
||||||
|
"optimization path (default: 1).",
|
||||||
|
dest='hyperopt_min_trades',
|
||||||
|
default=1,
|
||||||
|
type=Arguments.check_int_positive,
|
||||||
|
metavar='INT',
|
||||||
|
)
|
||||||
|
|
||||||
def _build_subcommands(self) -> None:
|
def _build_subcommands(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -312,6 +312,10 @@ class Configuration(object):
|
|||||||
|
|
||||||
self._args_to_config(config, argname='hyperopt_random_state',
|
self._args_to_config(config, argname='hyperopt_random_state',
|
||||||
logstring='Parameter --random-state detected: {}')
|
logstring='Parameter --random-state detected: {}')
|
||||||
|
|
||||||
|
self._args_to_config(config, argname='hyperopt_min_trades',
|
||||||
|
logstring='Parameter --min-trades detected: {}')
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def _validate_config_schema(self, conf: Dict[str, Any]) -> Dict[str, Any]:
|
def _validate_config_schema(self, conf: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
|
@ -204,7 +204,11 @@ class Hyperopt(Backtesting):
|
|||||||
trade_count = len(results.index)
|
trade_count = len(results.index)
|
||||||
trade_duration = results.trade_duration.mean()
|
trade_duration = results.trade_duration.mean()
|
||||||
|
|
||||||
if trade_count == 0:
|
# If this evaluation contains too short small amount of trades
|
||||||
|
# to be interesting -- consider it as 'bad' (assign max. loss value)
|
||||||
|
# in order to cast this hyperspace point away from optimization
|
||||||
|
# path. We do not want to optimize 'hodl' strategies.
|
||||||
|
if trade_count < self.config['hyperopt_min_trades']:
|
||||||
return {
|
return {
|
||||||
'loss': MAX_LOSS,
|
'loss': MAX_LOSS,
|
||||||
'params': params,
|
'params': params,
|
||||||
|
Loading…
Reference in New Issue
Block a user