Changed max_open_trades type to int or inf

This commit is contained in:
Antonio Della Fortuna
2023-01-15 11:44:10 +01:00
parent 192f75254f
commit b0f1d914c8
11 changed files with 97 additions and 30 deletions

View File

@@ -1237,8 +1237,8 @@ class Backtesting:
if not self.config.get('use_max_market_positions', True):
logger.info(
'Ignoring max_open_trades (--disable-max-market-positions was used) ...')
self.strategy.max_open_trades = -1
self.config.update({'max_open_trades': float('inf')})
self.strategy.max_open_trades = float('inf')
self.config.update({'max_open_trades': self.strategy.max_open_trades})
# need to reprocess data every time to populate signals
preprocessed = self.strategy.advise_all_indicators(data)

View File

@@ -120,8 +120,8 @@ class Hyperopt:
# Use max_open_trades for hyperopt as well, except --disable-max-market-positions is set
if not self.config.get('use_max_market_positions', True):
logger.debug('Ignoring max_open_trades (--disable-max-market-positions was used) ...')
self.backtesting.strategy.max_open_trades = -1
config.update({'max_open_trades': float('inf')})
self.backtesting.strategy.max_open_trades = float('inf')
config.update({'max_open_trades': self.backtesting.strategy.max_open_trades})
if HyperoptTools.has_space(self.config, 'sell'):
# Make sure use_exit_signal is enabled
@@ -211,7 +211,8 @@ class Hyperopt:
result['trailing'] = self.custom_hyperopt.generate_trailing_params(params)
if HyperoptTools.has_space(self.config, 'trades'):
result['max_open_trades'] = {
'max_open_trades': self.backtesting.strategy.max_open_trades}
'max_open_trades': self.backtesting.strategy.max_open_trades
if self.backtesting.strategy.max_open_trades != float('inf') else -1}
return result
@@ -344,16 +345,13 @@ class Hyperopt:
# Ignore unlimited max open trades if stake amount is unlimited
params_dict.update({'max_open_trades': self.config['max_open_trades']})
updated_config_max_open_trades = int(params_dict['max_open_trades']) \
updated_max_open_trades = int(params_dict['max_open_trades']) \
if (params_dict['max_open_trades'] != -1
and params_dict['max_open_trades'] != 0) else float('inf')
updated_strategy_max_open_trades = int(updated_config_max_open_trades) \
if updated_config_max_open_trades != float('inf') else -1
self.config.update({'max_open_trades': updated_max_open_trades})
self.config.update({'max_open_trades': updated_config_max_open_trades})
self.backtesting.strategy.max_open_trades = updated_strategy_max_open_trades
self.backtesting.strategy.max_open_trades = updated_max_open_trades
with self.data_pickle_file.open('rb') as f:
processed = load(f, mmap_mode='r')

View File

@@ -8,7 +8,7 @@ from pandas import DataFrame, to_datetime
from tabulate import tabulate
from freqtrade.constants import (DATETIME_PRINT_FORMAT, LAST_BT_RESULT_FN, UNLIMITED_STAKE_AMOUNT,
Config)
Config, IntOrInf)
from freqtrade.data.metrics import (calculate_cagr, calculate_calmar, calculate_csum,
calculate_expectancy, calculate_market_change,
calculate_max_drawdown, calculate_sharpe, calculate_sortino)
@@ -191,7 +191,7 @@ def generate_tag_metrics(tag_type: str,
return []
def generate_exit_reason_stats(max_open_trades: int, results: DataFrame) -> List[Dict]:
def generate_exit_reason_stats(max_open_trades: IntOrInf, results: DataFrame) -> List[Dict]:
"""
Generate small table outlining Backtest results
:param max_open_trades: Max_open_trades parameter