From 524290d678b15a58ec62b3b5cab588827a00e264 Mon Sep 17 00:00:00 2001 From: Gerald Lonlas Date: Mon, 29 Jan 2018 22:28:54 -0800 Subject: [PATCH 1/4] Fix backtesting ticker interval download --- freqtrade/misc.py | 4 +--- freqtrade/optimize/backtesting.py | 25 ++++++++++++++++--------- freqtrade/tests/test_main.py | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/freqtrade/misc.py b/freqtrade/misc.py index cf2db1004..0512330d9 100644 --- a/freqtrade/misc.py +++ b/freqtrade/misc.py @@ -218,7 +218,6 @@ def backtesting_options(parser: argparse.ArgumentParser) -> None: '-i', '--ticker-interval', help='specify ticker interval in minutes (1, 5, 30, 60, 1440)', dest='ticker_interval', - default=5, type=int, metavar='INT', ) @@ -269,9 +268,8 @@ def hyperopt_options(parser: argparse.ArgumentParser) -> None: ) parser.add_argument( '-i', '--ticker-interval', - help='specify ticker interval in minutes (default: 5)', + help='specify ticker interval in minutes (1, 5, 30, 60, 1440)', dest='ticker_interval', - default=5, type=int, metavar='INT', ) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index e8fcec875..fafa6e17b 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -169,22 +169,34 @@ def start(args): logger.info('Using config: %s ...', args.config) config = misc.load_config(args.config) - ticker_interval = config.get('ticker_interval', args.ticker_interval) - logger.info('Using ticker_interval: %s ...', ticker_interval) + + # If -i/--ticker-interval is use we override the configuration parameter + # (that will override the strategy configuration) + if args.ticker_interval: + config.update({'ticker_interval': args.ticker_interval}) + + # init the strategy to use + config.update({'strategy': args.strategy}) + strategy = Strategy() + strategy.init(config) + + logger.info('Using ticker_interval: %d ...', strategy.ticker_interval) data = {} pairs = config['exchange']['pair_whitelist'] if args.live: logger.info('Downloading data for all pairs in whitelist ...') for pair in pairs: - data[pair] = exchange.get_ticker_history(pair, ticker_interval) + data[pair] = exchange.get_ticker_history(pair, strategy.ticker_interval) else: logger.info('Using local backtesting data (using whitelist in given config) ...') logger.info('Using stake_currency: %s ...', config['stake_currency']) logger.info('Using stake_amount: %s ...', config['stake_amount']) timerange = misc.parse_timerange(args.timerange) - data = optimize.load_data(args.datadir, pairs=pairs, ticker_interval=args.ticker_interval, + data = optimize.load_data(args.datadir, + pairs=pairs, + ticker_interval=strategy.ticker_interval, refresh_pairs=args.refresh_pairs, timerange=timerange) max_open_trades = 0 @@ -192,11 +204,6 @@ def start(args): logger.info('Using max_open_trades: %s ...', config['max_open_trades']) max_open_trades = config['max_open_trades'] - # init the strategy to use - config.update({'strategy': args.strategy}) - strategy = Strategy() - strategy.init(config) - # Monkey patch config from freqtrade import main main._CONF = config diff --git a/freqtrade/tests/test_main.py b/freqtrade/tests/test_main.py index ba7f8108f..7727f5924 100644 --- a/freqtrade/tests/test_main.py +++ b/freqtrade/tests/test_main.py @@ -32,7 +32,7 @@ def test_parse_args_backtesting(mocker): assert call_args.loglevel == 20 assert call_args.subparser == 'backtesting' assert call_args.func is not None - assert call_args.ticker_interval == 5 + assert call_args.ticker_interval == None def test_main_start_hyperopt(mocker): From 321e3ede303d9b641d5598dae6f647527f202852 Mon Sep 17 00:00:00 2001 From: Gerald Lonlas Date: Mon, 29 Jan 2018 22:53:28 -0800 Subject: [PATCH 2/4] Fix hyperopt ticker interval download --- freqtrade/optimize/hyperopt.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/freqtrade/optimize/hyperopt.py b/freqtrade/optimize/hyperopt.py index 76932f7e3..8b89e1985 100644 --- a/freqtrade/optimize/hyperopt.py +++ b/freqtrade/optimize/hyperopt.py @@ -461,6 +461,11 @@ def start(args): config = load_config(args.config) pairs = config['exchange']['pair_whitelist'] + # If -i/--ticker-interval is use we override the configuration parameter + # (that will override the strategy configuration) + if args.ticker_interval: + config.update({'ticker_interval': args.ticker_interval}) + # init the strategy to use config.update({'strategy': args.strategy}) strategy = Strategy() @@ -468,7 +473,7 @@ def start(args): timerange = misc.parse_timerange(args.timerange) data = optimize.load_data(args.datadir, pairs=pairs, - ticker_interval=args.ticker_interval, + ticker_interval=strategy.ticker_interval, timerange=timerange) optimize.populate_indicators = populate_indicators PROCESSED = optimize.tickerdata_to_dataframe(data) From cac2f2b58bff1f53aa2000233e2c4dafc7901027 Mon Sep 17 00:00:00 2001 From: Gerald Lonlas Date: Mon, 29 Jan 2018 23:04:28 -0800 Subject: [PATCH 3/4] Wrong assert condition --- freqtrade/tests/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/tests/test_main.py b/freqtrade/tests/test_main.py index 7727f5924..aa44081bd 100644 --- a/freqtrade/tests/test_main.py +++ b/freqtrade/tests/test_main.py @@ -32,7 +32,7 @@ def test_parse_args_backtesting(mocker): assert call_args.loglevel == 20 assert call_args.subparser == 'backtesting' assert call_args.func is not None - assert call_args.ticker_interval == None + assert call_args.ticker_interval is None def test_main_start_hyperopt(mocker): From d313eb812d0ae4ffa596d2d2909699439d7b79bb Mon Sep 17 00:00:00 2001 From: Gerald Lonlas Date: Mon, 29 Jan 2018 23:07:54 -0800 Subject: [PATCH 4/4] Forgot one args.ticker_interval --- freqtrade/optimize/backtesting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index fafa6e17b..2778f4ab5 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -229,5 +229,5 @@ def start(args): }) logger.info( '\n==================================== BACKTESTING REPORT ====================================\n%s', # noqa - generate_text_table(data, results, config['stake_currency'], args.ticker_interval) + generate_text_table(data, results, config['stake_currency'], strategy.ticker_interval) )