From c260e188b0c220f79173892299ffb0f63145ec1f Mon Sep 17 00:00:00 2001 From: fredfortier Date: Thu, 16 Nov 2017 18:14:24 -0500 Subject: [PATCH] BUG: looking a potential resampling issue --- tests/exchange/test_data_portal.py | 37 ++++++++++++++++++++++++++++++ tests/exchange/test_utils.py | 15 +++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/tests/exchange/test_data_portal.py b/tests/exchange/test_data_portal.py index 31c67295..efd2ffe6 100644 --- a/tests/exchange/test_data_portal.py +++ b/tests/exchange/test_data_portal.py @@ -113,3 +113,40 @@ class TestExchangeDataPortal: ) log.info('found history window: {}'.format(data)) + + def test_validate_resample(self): + symbol = ['eth_btc'] + exchange_name = 'poloniex' + exchange = get_exchange(exchange_name, base_currency=symbol) + + assets = exchange.get_assets(symbols=symbol) + + date = rnd_history_date_days( + max_days=10, + last_dt=pd.to_datetime('2017-11-1', utc=True) + ) + bar_count = rnd_bar_count(max_bars=10) + sample_minutes = 15 + sample_data = self.data_portal_backtest.get_history_window( + assets=assets, + end_dt=date, + bar_count=bar_count, + frequency='{}T'.format(sample_minutes), + field='close', + data_frequency='daily' + ) + minute_data = self.data_portal_backtest.get_history_window( + assets=assets, + end_dt=date, + bar_count=bar_count * sample_minutes, + frequency='1T', + field='close', + data_frequency='daily' + ) + resampled_minute_data = minute_data.resample( + '{}T'.format(sample_minutes)) + + print(sample_data.tail(10)) + print(resampled_minute_data.tail(10)) + print(minute_data.tail(10)) + pass diff --git a/tests/exchange/test_utils.py b/tests/exchange/test_utils.py index eb53bff5..d7f1df87 100644 --- a/tests/exchange/test_utils.py +++ b/tests/exchange/test_utils.py @@ -4,11 +4,20 @@ from random import randint import pandas as pd -def rnd_history_date_days(max_days=30): - now = pd.Timestamp.utcnow() +def rnd_history_date_days(max_days=30, last_dt=None): + if last_dt is None: + last_dt = pd.Timestamp.utcnow() + days = randint(0, max_days) - return now - timedelta(days=days) + return last_dt - timedelta(days=days) + + +def rnd_history_date_minutes(max_minutes=1440): + now = pd.Timestamp.utcnow() + days = randint(0, max_minutes) + + return now - timedelta(minutes=days) def rnd_bar_count(max_bars=21):