mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-27 11:20:45 +08:00
BUG: looking a potential resampling issue
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user