mirror of
https://github.com/wassname/catalyst.git
synced 2026-06-30 09:55:52 +08:00
BLD: fix periods calculations and bundle unit-test
This commit is contained in:
@@ -16,6 +16,7 @@ from catalyst.exchange.utils.serialization_utils import ExchangeJSONEncoder, \
|
||||
ExchangeJSONDecoder
|
||||
from catalyst.utils.paths import data_root, ensure_directory, \
|
||||
last_modified_time
|
||||
from catalyst.exchange.utils.datetime_utils import get_periods_range
|
||||
|
||||
|
||||
def get_sid(symbol):
|
||||
@@ -739,7 +740,21 @@ def get_candles_df(candles, field, freq, bar_count, end_dt=None):
|
||||
|
||||
for asset in candles:
|
||||
asset_df = transform_candles_to_df(candles[asset])
|
||||
periods = pd.date_range(end=end_dt, periods=bar_count, freq=freq)
|
||||
rounded_end_dt = end_dt.round(freq)
|
||||
|
||||
periods = get_periods_range(
|
||||
start_dt=None, end_dt=rounded_end_dt,
|
||||
freq=freq, periods=bar_count
|
||||
)
|
||||
|
||||
if rounded_end_dt > end_dt:
|
||||
periods = periods[:-1]
|
||||
elif rounded_end_dt <= end_dt:
|
||||
periods = periods[1:]
|
||||
|
||||
print rounded_end_dt
|
||||
print periods
|
||||
# periods = pd.date_range(end=end_dt, periods=bar_count, freq=freq)
|
||||
asset_df = forward_fill_df_if_needed(asset_df, periods)
|
||||
|
||||
all_series[asset] = pd.Series(asset_df[field])
|
||||
|
||||
@@ -107,14 +107,14 @@ class TestSuiteBundle:
|
||||
print('saved {} test results: {}'.format(end_dt, folder))
|
||||
|
||||
assert_frame_equal(
|
||||
right=data['bundle'],
|
||||
left=data['exchange'],
|
||||
right=data['bundle'][:-1],
|
||||
left=data['exchange'][:-1],
|
||||
check_less_precise=1,
|
||||
)
|
||||
try:
|
||||
assert_frame_equal(
|
||||
right=data['bundle'],
|
||||
left=data['exchange'],
|
||||
right=data['bundle'][:-1],
|
||||
left=data['exchange'][:-1],
|
||||
check_less_precise=min([a.decimals for a in assets]),
|
||||
)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user