From 6ca375a39783eea32aafe271c5672ea85215c11c Mon Sep 17 00:00:00 2001 From: creslin <34645187+creslinux@users.noreply.github.com> Date: Sat, 2 Jun 2018 19:45:08 +0300 Subject: [PATCH 1/4] Extend timerange to accept unix timestamps. This gives greater granularity over backtest, parsing tickerfiles. Example runs using date and unix time below. /usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/creslin/PycharmProjects/freqtrade/scripts/report_correlation.py --timerange=20180528-20180529 2018-06-02 18:44:58,829 - freqtrade.configuration - INFO - Log level set to INFO 2018-06-02 18:44:58,830 - freqtrade.configuration - INFO - Using max_open_trades: 200 ... 2018-06-02 18:44:58,831 - freqtrade.configuration - INFO - Parameter --timerange detected: 20180528-20180529 ... 2018-06-02 18:44:58,831 - freqtrade.configuration - INFO - Parameter --datadir detected: freqtrade/tests/testdata ... BasePair Pair Correlation BTC % Change Pair % USD Ch Pair % BTC Ch Gain % on BTC Start Stop BTC Volume 1 BTC_USDT ETC_USD 0.965 -2.942 -4.070 -1.163 -1.128585 05-28 00:00 05-29 00:00 335.19 0 BTC_USDT SNT_USD 0.943 -2.942 -5.857 -3.004 -2.915585 05-28 00:00 05-29 00:00 496.01 3 BTC_USDT DASH_USD 0.902 -2.942 -9.034 -6.277 -6.092432 05-28 00:00 05-29 00:00 751.41 2 BTC_USDT MTH_USD 0.954 -2.942 -9.290 -6.541 -6.348708 05-28 00:00 05-29 00:00 23.00 4 BTC_USDT TRX_USD 0.951 -2.942 -13.647 -11.029 -10.704957 05-28 00:00 05-29 00:00 14544.57 Process finished with exit code 0 /usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /Users/creslin/PycharmProjects/freqtrade/scripts/report_correlation.py --timerange=1527595200-1527618600 2018-06-02 18:47:40,382 - freqtrade.configuration - INFO - Log level set to INFO 2018-06-02 18:47:40,382 - freqtrade.configuration - INFO - Using max_open_trades: 200 ... 2018-06-02 18:47:40,383 - freqtrade.configuration - INFO - Parameter --timerange detected: 1527595200-1527618600 ... 2018-06-02 18:47:40,383 - freqtrade.configuration - INFO - Parameter --datadir detected: freqtrade/tests/testdata ... BasePair Pair Correlation BTC % Change Pair % USD Ch Pair % BTC Ch Gain % on BTC Start Stop BTC Volume 0 BTC_USDT SNT_USD 0.680 NaN NaN NaN NaN 05-29 12:00 05-29 18:30 68866.30 1 BTC_USDT ETC_USD 0.857 NaN NaN NaN NaN 05-29 12:00 05-29 18:30 227514.17 2 BTC_USDT MTH_USD 0.790 NaN NaN NaN NaN 05-29 12:00 05-29 18:30 12103.96 3 BTC_USDT DASH_USD 0.862 NaN NaN NaN NaN 05-29 12:00 05-29 18:30 72982.78 4 BTC_USDT TRX_USD 0.178 NaN NaN NaN NaN 05-29 12:00 05-29 18:30 1258316.95 Process finished with exit code 0 --- freqtrade/arguments.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/freqtrade/arguments.py b/freqtrade/arguments.py index afcb05511..00869f974 100644 --- a/freqtrade/arguments.py +++ b/freqtrade/arguments.py @@ -222,6 +222,9 @@ class Arguments(object): syntax = [(r'^-(\d{8})$', (None, 'date')), (r'^(\d{8})-$', ('date', None)), (r'^(\d{8})-(\d{8})$', ('date', 'date')), + (r'^-(\d{10})$', (None, 'timestamp')), + (r'^(\d{10})-$', ('timestamp', None)), + (r'^(\d{10})-(\d{10})$', ('timestamp', 'timestamp')), (r'^(-\d+)$', (None, 'line')), (r'^(\d+)-$', ('line', None)), (r'^(\d+)-(\d+)$', ('index', 'index'))] @@ -237,6 +240,8 @@ class Arguments(object): start = rvals[index] if stype[0] == 'date': start = arrow.get(start, 'YYYYMMDD').timestamp + elif stype[0] == 'timestamp': + start = arrow.get(start).timestamp else: start = int(start) index += 1 @@ -244,6 +249,8 @@ class Arguments(object): stop = rvals[index] if stype[1] == 'date': stop = arrow.get(stop, 'YYYYMMDD').timestamp + elif stype[1] == 'timestamp': + stop = arrow.get(stop).timestamp else: stop = int(stop) return stype, start, stop From 9dbe5fdb852e1fc32bab6792bb37610fab508d04 Mon Sep 17 00:00:00 2001 From: creslin <34645187+creslinux@users.noreply.github.com> Date: Sat, 2 Jun 2018 19:49:23 +0300 Subject: [PATCH 2/4] Update back testing document to include example using Posix timestamps as timerange e.g --timerange=1527595200-1527618600 --- docs/backtesting.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/backtesting.md b/docs/backtesting.md index df105bd77..8c4c4180d 100644 --- a/docs/backtesting.md +++ b/docs/backtesting.md @@ -83,6 +83,8 @@ The full timerange specification: - 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` +- Use tickframes between POSIX timestamps 1527595200 1527618600: + `--timerange=1527595200-1527618600` **Update testdata directory** From 43ba02afc63e106925b47d3ee9e25a87809f02ae Mon Sep 17 00:00:00 2001 From: creslin <34645187+creslinux@users.noreply.github.com> Date: Sat, 2 Jun 2018 21:59:18 +0300 Subject: [PATCH 3/4] Per feed back, kept the stype as date. Use a tuple to keep as epoch int or process via arrow to timestamp. I'll look at the test file also. --- freqtrade/arguments.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/freqtrade/arguments.py b/freqtrade/arguments.py index 00869f974..b61324ccc 100644 --- a/freqtrade/arguments.py +++ b/freqtrade/arguments.py @@ -222,9 +222,9 @@ class Arguments(object): syntax = [(r'^-(\d{8})$', (None, 'date')), (r'^(\d{8})-$', ('date', None)), (r'^(\d{8})-(\d{8})$', ('date', 'date')), - (r'^-(\d{10})$', (None, 'timestamp')), - (r'^(\d{10})-$', ('timestamp', None)), - (r'^(\d{10})-(\d{10})$', ('timestamp', 'timestamp')), + (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'))] @@ -239,18 +239,16 @@ class Arguments(object): if stype[0]: start = rvals[index] if stype[0] == 'date': - start = arrow.get(start, 'YYYYMMDD').timestamp - elif stype[0] == 'timestamp': - start = arrow.get(start).timestamp + start = int(start) if len(start) == 10 \ + else arrow.get(start, 'YYYYMMDD').timestamp else: start = int(start) index += 1 if stype[1]: stop = rvals[index] if stype[1] == 'date': - stop = arrow.get(stop, 'YYYYMMDD').timestamp - elif stype[1] == 'timestamp': - stop = arrow.get(stop).timestamp + stop = int(stop) if len(stop) == 10 \ + else arrow.get(stop, 'YYYYMMDD').timestamp else: stop = int(stop) return stype, start, stop From 94e586c049211e2267726e3b0509ece14b95bef3 Mon Sep 17 00:00:00 2001 From: creslinux Date: Sat, 2 Jun 2018 22:46:54 +0300 Subject: [PATCH 4/4] Added unit test to check posix time arguments passed to timerange Here is the pass report: freqtrade_new creslin$ pytest freqtrade/tests/test_arguments.py ==================================================================== test session starts ===================================================================== platform darwin -- Python 3.6.5, pytest-3.6.0, py-1.5.3, pluggy-0.6.0 rootdir: /Users/creslin/PycharmProjects/freqtrade_new, inifile: plugins: mock-1.10.0, cov-2.5.1 collected 19 items freqtrade/tests/test_arguments.py ................... [100%] ================================================================= 19 passed in 2.37 seconds ================================================================== --- freqtrade/tests/test_arguments.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/freqtrade/tests/test_arguments.py b/freqtrade/tests/test_arguments.py index 279ace0dc..474aa2507 100644 --- a/freqtrade/tests/test_arguments.py +++ b/freqtrade/tests/test_arguments.py @@ -116,6 +116,12 @@ def test_parse_timerange_incorrect() -> None: timerange = Arguments.parse_timerange('20100522-20150730') assert timerange == (('date', 'date'), 1274486400, 1438214400) + # Added test for unix timestamp - BTC genesis date + assert (('date', None), 1231006505, None) == Arguments.parse_timerange('1231006505-') + assert ((None, 'date'), None, 1233360000) == Arguments.parse_timerange('-1233360000') + timerange = Arguments.parse_timerange('1231006505-1233360000') + assert timerange == (('date', 'date'), 1231006505, 1233360000) + with pytest.raises(Exception, match=r'Incorrect syntax.*'): Arguments.parse_timerange('-')