Esempio n. 1
0
class HybridDataFactoryTestCase(unittest.TestCase):

    def setUp(self):
        dna.test_utils.setup_logger(self)
        self.test_index = pd.date_range(
            '2012/01/01', '2012/01/7', tz=pytz.utc)
        self.test_universe = 'forex,5'
        self.market = Market()
        self.market.parse_universe_description(self.test_universe)
        self.test_sids = self.market.sids

    def tearDown(self):
        dna.test_utils.teardown_logger(self)

    @nottest
    def _check_datasource(self, source):
        ok_((source.index == self.test_index).all())
        eq_(source.start, self.test_index[0])
        eq_(source.end, self.test_index[-1])
        eq_(source.sids, self.test_sids)
        self.assertIsNone(source._raw_data)
        eq_(source.arg_string, source.instance_hash)
        eq_(source.event_type, 4)
        ok_(hasattr(source, 'log'))
        self.assertFalse(source._is_live)

    @raises(InvalidDatafeed)
    def test_data_source_without_modules(self):
        config = {
            'sids': self.test_sids,
            'index': self.test_index
        }
        datafeed.HybridDataFactory(**config)

    @raises(InvalidDatafeed)
    def test_data_source_invalid_index(self):
        config = {
            'sids': self.test_sids,
            'index': bool
        }
        datafeed.HybridDataFactory(**config)

    def test_minimal_data_source(self):
        source = datafeed.HybridDataFactory(
            universe=self.market,
            index=self.test_index,
            backtest=FakeBacktestDatasource)
        self._check_datasource(source)

    def test_hybrid_mapping(self):
        source = datafeed.HybridDataFactory(
            universe=self.market,
            index=self.test_index,
            backtest=FakeBacktestDatasource,
            live=FakeLiveDatasource)

        self.assertIn('backtest', source.mapping)
        source._is_live = True
        self.assertIn('live', source.mapping)
Esempio n. 2
0
 def setUp(self):
     dna.test_utils.setup_logger(self)
     self.test_index = pd.date_range(
         '2012/01/01', '2012/01/7', tz=pytz.utc)
     self.test_universe = 'forex,5'
     self.market = Market()
     self.market.parse_universe_description(self.test_universe)
     self.test_sids = self.market.sids
Esempio n. 3
0
 def test_panel_without_volume_cac40_backtest_data_generation(self):
     test_universe = 'stocks:paris:cac40,5'
     market = Market()
     market.parse_universe_description(test_universe)
     source = datafeed.HybridDataFactory(
         universe=market,
         index=self.test_index,
         backtest=FakePanelWithoutVolumeBacktestDatasource)
     total_rows = 0
     for row in source.raw_data:
         if not total_rows:
             self.assertListEqual(
                 sorted(row.keys()),
                 sorted(['dt', 'price', 'low', 'high', 'sid', 'volume']))
         total_rows += 1
     eq_(total_rows, len(self.test_index) * len(market.sids))
Esempio n. 4
0
 def test_dataframe_forex_backtest_data_generation(self):
     test_universe = 'forex,5'
     market = Market()
     market.parse_universe_description(test_universe)
     source = datafeed.HybridDataFactory(
         universe=market,
         index=self.test_index,
         backtest=FakeBacktestDatasource)
     total_rows = 0
     for row in source.raw_data:
         if not total_rows:
             self.assertListEqual(
                 sorted(row.keys()),
                 sorted(['dt', 'price', 'sid', 'volume']))
         total_rows += 1
     eq_(total_rows, 2 * len(self.test_index) * len(market.sids))
Esempio n. 5
0
 def _setup_source(self):
     market = Market()
     market.parse_universe_description("forex,5")
     return HybridDataFactory(universe=market, index=self.test_index, backtest=FakeBacktestDatasource)