make args available for optimizer and use them instead of guessing from params
This commit is contained in:
parent
ec8bf82695
commit
bf72b5bc37
@ -403,24 +403,27 @@ def buy_strategy_generator(params: Dict[str, Any]) -> Callable:
|
||||
return populate_buy_trend
|
||||
|
||||
|
||||
def generate_optimizer(args):
|
||||
def optimizer(params):
|
||||
global _CURRENT_TRIES
|
||||
|
||||
strategy = Strategy()
|
||||
if 'roi_t1' in params:
|
||||
if has_space(args.spaces, 'roi'):
|
||||
strategy.minimal_roi = generate_roi_table(params)
|
||||
|
||||
if 'trigger' in params:
|
||||
if has_space(args.spaces, 'buy'):
|
||||
backtesting.populate_buy_trend = buy_strategy_generator(params)
|
||||
|
||||
if 'stoploss' in params:
|
||||
if has_space(args.spaces, 'stoploss'):
|
||||
stoploss = params['stoploss']
|
||||
else:
|
||||
stoploss = strategy.stoploss
|
||||
|
||||
results = backtest({'stake_amount': OPTIMIZE_CONFIG['stake_amount'],
|
||||
'processed': PROCESSED,
|
||||
'stoploss': stoploss})
|
||||
'stoploss': stoploss,
|
||||
'realistic': args.realistic_simulation,
|
||||
})
|
||||
result_explanation = format_results(results)
|
||||
|
||||
total_profit = results.profit_percent.sum()
|
||||
@ -451,6 +454,8 @@ def optimizer(params):
|
||||
'result': result_explanation,
|
||||
}
|
||||
|
||||
return optimizer
|
||||
|
||||
|
||||
def format_results(results: DataFrame):
|
||||
return ('{:6d} trades. Avg profit {: 5.2f}%. '
|
||||
@ -519,7 +524,7 @@ def start(args):
|
||||
|
||||
try:
|
||||
best_parameters = fmin(
|
||||
fn=optimizer,
|
||||
fn=generate_optimizer(args),
|
||||
space=hyperopt_space(args.spaces),
|
||||
algo=tpe.suggest,
|
||||
max_evals=TOTAL_TRIES,
|
||||
|
Loading…
Reference in New Issue
Block a user