mirror of
https://github.com/wassname/catalyst.git
synced 2026-08-11 11:16:15 +08:00
BLD: improved the bundle test suite and related adjustments
This commit is contained in:
@@ -10,7 +10,8 @@ from catalyst.exchange.exchange_bcolz import BcolzExchangeBarReader, \
|
||||
from catalyst.exchange.exchange_bundle import ExchangeBundle, \
|
||||
BUNDLE_NAME_TEMPLATE
|
||||
from catalyst.exchange.utils.bundle_utils import get_bcolz_chunk, \
|
||||
get_start_dt, get_df_from_arrays
|
||||
get_df_from_arrays
|
||||
from exchange.utils.datetime_utils import get_start_dt
|
||||
from catalyst.exchange.utils.exchange_utils import get_exchange_folder
|
||||
from catalyst.exchange.utils.factory import get_exchange
|
||||
from catalyst.exchange.utils.stats_utils import df_to_string
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import pandas as pd
|
||||
from logbook import Logger
|
||||
|
||||
from catalyst.testing import ZiplineTestCase
|
||||
from catalyst.testing.fixtures import WithLogger
|
||||
from .base import BaseExchangeTestCase
|
||||
from catalyst.exchange.ccxt.ccxt_exchange import CCXT
|
||||
from catalyst.exchange.exchange_execution import ExchangeLimitOrder
|
||||
@@ -59,7 +61,7 @@ class TestCCXT(BaseExchangeTestCase):
|
||||
freq='5T',
|
||||
assets=[self.exchange.get_asset('eth_btc')],
|
||||
bar_count=200,
|
||||
start_dt=pd.to_datetime('2017-01-01', utc=True)
|
||||
start_dt=pd.to_datetime('2017-09-01', utc=True)
|
||||
)
|
||||
|
||||
for asset in candles:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import random
|
||||
|
||||
import os
|
||||
import pandas as pd
|
||||
from logbook import TestHandler
|
||||
from pandas.util.testing import assert_frame_equal
|
||||
@@ -11,7 +12,6 @@ from catalyst.exchange.utils.exchange_utils import get_candles_df
|
||||
from catalyst.exchange.utils.factory import get_exchange
|
||||
from catalyst.exchange.utils.test_utils import output_df, \
|
||||
select_random_assets
|
||||
from catalyst.testing.fixtures import WithLogger, ZiplineTestCase
|
||||
|
||||
pd.set_option('display.expand_frame_repr', False)
|
||||
pd.set_option('precision', 8)
|
||||
@@ -19,7 +19,7 @@ pd.set_option('display.width', 1000)
|
||||
pd.set_option('display.max_colwidth', 1000)
|
||||
|
||||
|
||||
class TestSuiteBundle(WithLogger, ZiplineTestCase):
|
||||
class TestSuiteBundle:
|
||||
@staticmethod
|
||||
def get_data_portal(exchanges):
|
||||
open_calendar = get_calendar('OPEN')
|
||||
@@ -46,7 +46,9 @@ class TestSuiteBundle(WithLogger, ZiplineTestCase):
|
||||
assets
|
||||
end_dt
|
||||
bar_count
|
||||
sample_minutes
|
||||
freq
|
||||
data_frequency
|
||||
data_portal
|
||||
|
||||
Returns
|
||||
-------
|
||||
@@ -64,10 +66,6 @@ class TestSuiteBundle(WithLogger, ZiplineTestCase):
|
||||
field='close',
|
||||
data_frequency=data_frequency,
|
||||
)
|
||||
print('bundle data:\n{}'.format(
|
||||
data['bundle'].tail(10))
|
||||
)
|
||||
|
||||
candles = exchange.get_candles(
|
||||
end_dt=end_dt,
|
||||
freq=freq,
|
||||
@@ -81,19 +79,31 @@ class TestSuiteBundle(WithLogger, ZiplineTestCase):
|
||||
bar_count=bar_count,
|
||||
end_dt=end_dt,
|
||||
)
|
||||
print('exchange data:\n{}'.format(
|
||||
data['exchange'].tail(10))
|
||||
)
|
||||
for source in data:
|
||||
df = data[source]
|
||||
path = output_df(df, assets, '{}_{}'.format(freq, source))
|
||||
print('saved {}:\n{}'.format(source, path))
|
||||
path, folder = output_df(
|
||||
df, assets, '{}_{}'.format(freq, source)
|
||||
)
|
||||
|
||||
assert_frame_equal(
|
||||
right=data['bundle'],
|
||||
left=data['exchange'],
|
||||
check_less_precise=True,
|
||||
check_less_precise=1,
|
||||
)
|
||||
try:
|
||||
assert_frame_equal(
|
||||
right=data['bundle'],
|
||||
left=data['exchange'],
|
||||
check_less_precise=min([a.decimals for a in assets]),
|
||||
)
|
||||
except Exception as e:
|
||||
print('Some differences were found within a 1 decimal point '
|
||||
'interval of confidence: {}'.format(e))
|
||||
with open(os.path.join(folder, 'compare.txt'), 'w+') as handle:
|
||||
handle.write(e.args[0])
|
||||
|
||||
print('saved test results: {}'.format(folder))
|
||||
pass
|
||||
|
||||
def test_validate_bundles(self):
|
||||
# exchange_population = 3
|
||||
|
||||
Reference in New Issue
Block a user