def test_engine_with_multicolumn_loader(self): open_, close = USEquityPricing.open, USEquityPricing.close loader = MultiColumnLoader({ open_: ConstantLoader(dates=self.dates, assets=self.assets, constants={open_: 1}), close: ConstantLoader(dates=self.dates, assets=self.assets, constants={close: 2}) }) engine = SimpleFFCEngine(loader, self.dates, self.asset_finder) factor = RollingSumDifference() result = engine.factor_matrix({'f': factor}, self.dates[2], self.dates[-1]) self.assertIsNotNone(result) self.assertEqual({'f'}, set(result.columns)) # (close - open) * window = (1 - 2) * 3 = -3 # skipped 2 from the start, so that the window is full check_arrays(result['f'], Series([-3] * len(self.assets) * (len(self.dates) - 2)))
def setUp(self): self.constants = { # Every day, assume every stock starts at 2, goes down to 1, # goes up to 4, and finishes at 3. USEquityPricing.low: 1, USEquityPricing.open: 2, USEquityPricing.close: 3, USEquityPricing.high: 4, } self.assets = [1, 2, 3] self.dates = date_range('2014-01-01', '2014-02-01', freq='D', tz='UTC') self.loader = ConstantLoader( constants=self.constants, dates=self.dates, assets=self.assets, ) self.asset_info = make_simple_asset_info( self.assets, start_date=self.dates[0], end_date=self.dates[-1], ) self.asset_finder = AssetFinder(self.asset_info)