add --export-filename for backtesting
This commit is contained in:
parent
bdb25bbcbc
commit
e3227a741c
@ -137,6 +137,16 @@ class Arguments(object):
|
|||||||
default=None,
|
default=None,
|
||||||
dest='export',
|
dest='export',
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--export-filename',
|
||||||
|
help='Save backtest results to this filename \
|
||||||
|
requires --export to be set as well\
|
||||||
|
Example --export-filename=backtest_today.json\
|
||||||
|
(default: %(default)s',
|
||||||
|
type=str,
|
||||||
|
default='backtest-result.json',
|
||||||
|
dest='exportfilename',
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def optimizer_shared_options(parser: argparse.ArgumentParser) -> None:
|
def optimizer_shared_options(parser: argparse.ArgumentParser) -> None:
|
||||||
|
@ -157,6 +157,11 @@ class Configuration(object):
|
|||||||
config.update({'export': self.args.export})
|
config.update({'export': self.args.export})
|
||||||
logger.info('Parameter --export detected: %s ...', self.args.export)
|
logger.info('Parameter --export detected: %s ...', self.args.export)
|
||||||
|
|
||||||
|
# If --export-filename is used we add it to the configuration
|
||||||
|
if 'export' in config and 'exportfilename' in self.args and self.args.exportfilename:
|
||||||
|
config.update({'exportfilename': self.args.exportfilename})
|
||||||
|
logger.info('Storing backtest results to %s ...', self.args.exportfilename)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
def _load_hyperopt_config(self, config: Dict[str, Any]) -> Dict[str, Any]:
|
def _load_hyperopt_config(self, config: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
|
@ -154,6 +154,7 @@ class Backtesting(object):
|
|||||||
max_open_trades = args.get('max_open_trades', 0)
|
max_open_trades = args.get('max_open_trades', 0)
|
||||||
realistic = args.get('realistic', False)
|
realistic = args.get('realistic', False)
|
||||||
record = args.get('record', None)
|
record = args.get('record', None)
|
||||||
|
recordfilename = args.get('recordfn', 'backtest-result.json')
|
||||||
records = []
|
records = []
|
||||||
trades = []
|
trades = []
|
||||||
trade_count_lock: Dict = {}
|
trade_count_lock: Dict = {}
|
||||||
@ -196,8 +197,8 @@ class Backtesting(object):
|
|||||||
# For now export inside backtest(), maybe change so that backtest()
|
# For now export inside backtest(), maybe change so that backtest()
|
||||||
# returns a tuple like: (dataframe, records, logs, etc)
|
# returns a tuple like: (dataframe, records, logs, etc)
|
||||||
if record and record.find('trades') >= 0:
|
if record and record.find('trades') >= 0:
|
||||||
logger.info('Dumping backtest results')
|
logger.info('Dumping backtest results to %s', recordfilename)
|
||||||
file_dump_json('backtest-result.json', records)
|
file_dump_json(recordfilename, records)
|
||||||
labels = ['currency', 'profit_percent', 'profit_BTC', 'duration']
|
labels = ['currency', 'profit_percent', 'profit_BTC', 'duration']
|
||||||
return DataFrame.from_records(trades, columns=labels)
|
return DataFrame.from_records(trades, columns=labels)
|
||||||
|
|
||||||
@ -257,7 +258,8 @@ class Backtesting(object):
|
|||||||
'realistic': self.config.get('realistic_simulation', False),
|
'realistic': self.config.get('realistic_simulation', False),
|
||||||
'sell_profit_only': sell_profit_only,
|
'sell_profit_only': sell_profit_only,
|
||||||
'use_sell_signal': use_sell_signal,
|
'use_sell_signal': use_sell_signal,
|
||||||
'record': self.config.get('export')
|
'record': self.config.get('export'),
|
||||||
|
'recordfn': self.config.get('exportfilename'),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
logger.info(
|
logger.info(
|
||||||
|
@ -218,7 +218,8 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non
|
|||||||
'--realistic-simulation',
|
'--realistic-simulation',
|
||||||
'--refresh-pairs-cached',
|
'--refresh-pairs-cached',
|
||||||
'--timerange', ':100',
|
'--timerange', ':100',
|
||||||
'--export', '/bar/foo'
|
'--export', '/bar/foo',
|
||||||
|
'--export-filename', 'foo_bar.json'
|
||||||
]
|
]
|
||||||
|
|
||||||
config = setup_configuration(get_args(args))
|
config = setup_configuration(get_args(args))
|
||||||
@ -259,6 +260,11 @@ def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> Non
|
|||||||
'Parameter --export detected: {} ...'.format(config['export']),
|
'Parameter --export detected: {} ...'.format(config['export']),
|
||||||
caplog.record_tuples
|
caplog.record_tuples
|
||||||
)
|
)
|
||||||
|
assert 'exportfilename' in config
|
||||||
|
assert log_has(
|
||||||
|
'Storing backtest results to {} ...'.format(config['exportfilename']),
|
||||||
|
caplog.record_tuples
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_start(mocker, fee, default_conf, caplog) -> None:
|
def test_start(mocker, fee, default_conf, caplog) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user