No args for backtest(), use arguments
This commit is contained in:
parent
82797e768f
commit
f4c7edf551
@ -279,30 +279,28 @@ class Backtesting:
|
|||||||
return bt_res
|
return bt_res
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def backtest(self, args: Dict) -> DataFrame:
|
def backtest(self, processed: Dict, stake_amount: int,
|
||||||
|
start_date, end_date,
|
||||||
|
max_open_trades: int = 0, position_stacking: bool = False) -> DataFrame:
|
||||||
"""
|
"""
|
||||||
Implements backtesting functionality
|
Implement backtesting functionality
|
||||||
|
|
||||||
NOTE: This method is used by Hyperopt at each iteration. Please keep it optimized.
|
NOTE: This method is used by Hyperopt at each iteration. Please keep it optimized.
|
||||||
Of course try to not have ugly code. By some accessor are sometime slower than functions.
|
Of course try to not have ugly code. By some accessor are sometime slower than functions.
|
||||||
Avoid, logging on this method
|
Avoid extensive logging in this method and functions it calls.
|
||||||
|
|
||||||
:param args: a dict containing:
|
:param processed: a processed dictionary with format {pair, data}
|
||||||
stake_amount: btc amount to use for each trade
|
:param stake_amount: amount to use for each trade
|
||||||
processed: a processed dictionary with format {pair, data}
|
:param start_date: backtesting timerange start datetime
|
||||||
max_open_trades: maximum number of concurrent trades (default: 0, disabled)
|
:param end_date: backtesting timerange end datetime
|
||||||
position_stacking: do we allow position stacking? (default: False)
|
:param max_open_trades: maximum number of concurrent trades, <= 0 means unlimited
|
||||||
:return: DataFrame
|
:param position_stacking: do we allow position stacking?
|
||||||
|
:return: DataFrame with trades (results of backtesting)
|
||||||
"""
|
"""
|
||||||
# Arguments are long and noisy, so this is commented out.
|
logger.debug(f"Run backtest, stake_amount: {stake_amount}, "
|
||||||
# Uncomment if you need to debug the backtest() method.
|
f"start_date: {start_date}, end_date: {end_date}, "
|
||||||
# logger.debug(f"Start backtest, args: {args}")
|
f"max_open_trades: {max_open_trades}, position_stacking: {position_stacking}"
|
||||||
processed = args['processed']
|
)
|
||||||
stake_amount = args['stake_amount']
|
|
||||||
max_open_trades = args.get('max_open_trades', 0)
|
|
||||||
position_stacking = args.get('position_stacking', False)
|
|
||||||
start_date = args['start_date']
|
|
||||||
end_date = args['end_date']
|
|
||||||
trades = []
|
trades = []
|
||||||
trade_count_lock: Dict = {}
|
trade_count_lock: Dict = {}
|
||||||
|
|
||||||
@ -369,18 +367,21 @@ class Backtesting:
|
|||||||
|
|
||||||
def start(self) -> None:
|
def start(self) -> None:
|
||||||
"""
|
"""
|
||||||
Run a backtesting end-to-end
|
Run backtesting end-to-end
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
data: Dict[str, Any] = {}
|
data: Dict[str, Any] = {}
|
||||||
|
|
||||||
logger.info('Using stake_currency: %s ...', self.config['stake_currency'])
|
logger.info('Using stake_currency: %s ...', self.config['stake_currency'])
|
||||||
logger.info('Using stake_amount: %s ...', self.config['stake_amount'])
|
logger.info('Using stake_amount: %s ...', self.config['stake_amount'])
|
||||||
|
|
||||||
# Use max_open_trades in backtesting, except --disable-max-market-positions is set
|
# Use max_open_trades in backtesting, except --disable-max-market-positions is set
|
||||||
if self.config.get('use_max_market_positions', True):
|
if self.config.get('use_max_market_positions', True):
|
||||||
max_open_trades = self.config['max_open_trades']
|
max_open_trades = self.config['max_open_trades']
|
||||||
else:
|
else:
|
||||||
logger.info('Ignoring max_open_trades (--disable-max-market-positions was used) ...')
|
logger.info('Ignoring max_open_trades (--disable-max-market-positions was used) ...')
|
||||||
max_open_trades = 0
|
max_open_trades = 0
|
||||||
|
position_stacking = self.config.get('position_stacking', False)
|
||||||
|
|
||||||
data, timerange = self.load_bt_data()
|
data, timerange = self.load_bt_data()
|
||||||
|
|
||||||
@ -403,14 +404,12 @@ class Backtesting:
|
|||||||
)
|
)
|
||||||
# Execute backtest and print results
|
# Execute backtest and print results
|
||||||
all_results[self.strategy.get_strategy_name()] = self.backtest(
|
all_results[self.strategy.get_strategy_name()] = self.backtest(
|
||||||
{
|
processed=preprocessed,
|
||||||
'stake_amount': self.config.get('stake_amount'),
|
stake_amount=self.config.get('stake_amount'),
|
||||||
'processed': preprocessed,
|
start_date=min_date,
|
||||||
'max_open_trades': max_open_trades,
|
end_date=max_date,
|
||||||
'position_stacking': self.config.get('position_stacking', False),
|
max_open_trades=max_open_trades,
|
||||||
'start_date': min_date,
|
position_stacking=position_stacking,
|
||||||
'end_date': max_date,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
for strategy, results in all_results.items():
|
for strategy, results in all_results.items():
|
||||||
|
@ -372,14 +372,12 @@ class Hyperopt:
|
|||||||
min_date, max_date = get_timerange(processed)
|
min_date, max_date = get_timerange(processed)
|
||||||
|
|
||||||
backtesting_results = self.backtesting.backtest(
|
backtesting_results = self.backtesting.backtest(
|
||||||
{
|
processed=processed,
|
||||||
'stake_amount': self.config['stake_amount'],
|
stake_amount=self.config['stake_amount'],
|
||||||
'processed': processed,
|
start_date=min_date,
|
||||||
'max_open_trades': self.max_open_trades,
|
end_date=max_date,
|
||||||
'position_stacking': self.position_stacking,
|
max_open_trades=self.max_open_trades,
|
||||||
'start_date': min_date,
|
position_stacking=self.position_stacking,
|
||||||
'end_date': max_date,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
return self._get_results_dict(backtesting_results, min_date, max_date,
|
return self._get_results_dict(backtesting_results, min_date, max_date,
|
||||||
params_dict, params_details)
|
params_dict, params_details)
|
||||||
|
Loading…
Reference in New Issue
Block a user