From 16e10d99b98f1dee27c0176017a179e108a69fff Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 19 Oct 2019 14:53:56 +0200 Subject: [PATCH] Remove timeframe logic for non-date entries --- docs/backtesting.md | 6 ------ docs/edge.md | 5 +---- freqtrade/configuration/timerange.py | 9 ++++++--- freqtrade/data/history.py | 12 ++---------- tests/data/test_btanalysis.py | 4 ++-- 5 files changed, 11 insertions(+), 25 deletions(-) diff --git a/docs/backtesting.md b/docs/backtesting.md index 6db573224..837fcfa3b 100644 --- a/docs/backtesting.md +++ b/docs/backtesting.md @@ -103,12 +103,6 @@ The full timerange specification: - Use tickframes since 2018/01/31 till 2018/03/01 : `--timerange=20180131-20180301` - Use tickframes between POSIX timestamps 1527595200 1527618600: `--timerange=1527595200-1527618600` -- Use last 123 tickframes of data: `--timerange=-123` -- Use first 123 tickframes of data: `--timerange=123-` -- Use tickframes from line 123 through 456: `--timerange=123-456` - -!!! warning - Be carefull when using non-date functions - these do not allow you to specify precise dates, so if you updated the test-data it will probably use a different dataset. ## Understand the backtesting result diff --git a/docs/edge.md b/docs/edge.md index d91522770..6374da9e6 100644 --- a/docs/edge.md +++ b/docs/edge.md @@ -249,13 +249,10 @@ freqtrade edge --stoplosses=-0.01,-0.1,-0.001 #min,max,step freqtrade edge --timerange=20181110-20181113 ``` -Doing `--timerange=-200` will get the last 200 timeframes from your inputdata. You can also specify specific dates, or a range span indexed by start and stop. +Doing `--timerange=-20190901` will get all available data until September 1st (excluding September 1st 2019). The full timerange specification: -* Use last 123 tickframes of data: `--timerange=-123` -* Use first 123 tickframes of data: `--timerange=123-` -* Use tickframes from line 123 through 456: `--timerange=123-456` * Use tickframes till 2018/01/31: `--timerange=-20180131` * Use tickframes since 2018/01/31: `--timerange=20180131-` * Use tickframes since 2018/01/31 till 2018/03/01 : `--timerange=20180131-20180301` diff --git a/freqtrade/configuration/timerange.py b/freqtrade/configuration/timerange.py index ec6eb75e6..2e92c9d85 100644 --- a/freqtrade/configuration/timerange.py +++ b/freqtrade/configuration/timerange.py @@ -42,9 +42,8 @@ class TimeRange: (r'^-(\d{10})$', (None, 'date')), (r'^(\d{10})-$', ('date', None)), (r'^(\d{10})-(\d{10})$', ('date', 'date')), - (r'^(-\d+)$', (None, 'line')), - (r'^(\d+)-$', ('line', None)), - (r'^(\d+)-(\d+)$', ('index', 'index'))] + (r'^(\d{13})-(\d{13})$', ('date', 'date')), + ] for rex, stype in syntax: # Apply the regular expression to text match = re.match(rex, text) @@ -57,6 +56,8 @@ class TimeRange: starts = rvals[index] if stype[0] == 'date' and len(starts) == 8: start = arrow.get(starts, 'YYYYMMDD').timestamp + elif len(starts) == 13: + start = int(starts) // 1000 else: start = int(starts) index += 1 @@ -64,6 +65,8 @@ class TimeRange: stops = rvals[index] if stype[1] == 'date' and len(stops) == 8: stop = arrow.get(stops, 'YYYYMMDD').timestamp + elif len(stops) == 13: + stop = int(stops) // 1000 else: stop = int(stops) return TimeRange(stype[0], stype[1], start, stop) diff --git a/freqtrade/data/history.py b/freqtrade/data/history.py index 991a639ca..3bebcf44f 100644 --- a/freqtrade/data/history.py +++ b/freqtrade/data/history.py @@ -33,20 +33,12 @@ def trim_tickerlist(tickerlist: List[Dict], timerange: TimeRange) -> List[Dict]: start_index = 0 stop_index = len(tickerlist) - if timerange.starttype == 'line': - stop_index = timerange.startts - if timerange.starttype == 'index': - start_index = timerange.startts - elif timerange.starttype == 'date': + if timerange.starttype == 'date': while (start_index < len(tickerlist) and tickerlist[start_index][0] < timerange.startts * 1000): start_index += 1 - if timerange.stoptype == 'line': - start_index = max(len(tickerlist) + timerange.stopts, 0) - if timerange.stoptype == 'index': - stop_index = timerange.stopts - elif timerange.stoptype == 'date': + if timerange.stoptype == 'date': while (stop_index > 0 and tickerlist[stop_index-1][0] > timerange.stopts * 1000): stop_index -= 1 diff --git a/tests/data/test_btanalysis.py b/tests/data/test_btanalysis.py index 27a8ee02e..4068e00e4 100644 --- a/tests/data/test_btanalysis.py +++ b/tests/data/test_btanalysis.py @@ -53,12 +53,12 @@ def test_load_trades_db(default_conf, fee, mocker): def test_extract_trades_of_period(testdatadir): pair = "UNITTEST/BTC" - timerange = TimeRange(None, 'line', 0, -1000) + # 2018-11-14 06:07:00 + timerange = TimeRange('date', None, 1510639620, 0) data = load_pair_history(pair=pair, ticker_interval='1m', datadir=testdatadir, timerange=timerange) - # timerange = 2017-11-14 06:07 - 2017-11-14 22:58:00 trades = DataFrame( {'pair': [pair, pair, pair, pair], 'profit_percent': [0.0, 0.1, -0.2, -0.5],