def test_force_registration(self):
        register_calendar("DMY", self.dummy_cal_type())
        first_dummy = get_calendar("DMY")

        # force-register a new instance
        register_calendar("DMY", self.dummy_cal_type(), force=True)

        second_dummy = get_calendar("DMY")

        self.assertNotEqual(first_dummy, second_dummy)
Esempio n. 2
0
    def test_force_registration(self):
        register_calendar("DMY", self.dummy_cal_type())
        first_dummy = get_calendar("DMY")

        # force-register a new instance
        register_calendar("DMY", self.dummy_cal_type(), force=True)

        second_dummy = get_calendar("DMY")

        self.assertNotEqual(first_dummy, second_dummy)
Esempio n. 3
0
    def test_both_places_are_checked(self):
        dummy_cal = self.dummy_cal_type()

        # if instance is registered, can't register type with same name
        register_calendar('DMY', dummy_cal)
        with self.assertRaises(CalendarNameCollision):
            register_calendar_type('DMY', type(dummy_cal))

        deregister_calendar('DMY')

        # if type is registered, can't register instance with same name
        register_calendar_type('DMY', type(dummy_cal))

        with self.assertRaises(CalendarNameCollision):
            register_calendar('DMY', dummy_cal)
    def test_both_places_are_checked(self):
        dummy_cal = self.dummy_cal_type()

        # if instance is registered, can't register type with same name
        register_calendar('DMY', dummy_cal)
        with self.assertRaises(CalendarNameCollision):
            register_calendar_type('DMY', type(dummy_cal))

        deregister_calendar('DMY')

        # if type is registered, can't register instance with same name
        register_calendar_type('DMY', type(dummy_cal))

        with self.assertRaises(CalendarNameCollision):
            register_calendar('DMY', dummy_cal)
Esempio n. 5
0
    def test_register_calendar(self):
        # Build a fake calendar
        dummy_cal = self.dummy_cal_type()

        # Try to register and retrieve the calendar
        register_calendar('DMY', dummy_cal)
        retr_cal = get_calendar('DMY')
        self.assertEqual(dummy_cal, retr_cal)

        # Try to register again, expecting a name collision
        with self.assertRaises(CalendarNameCollision):
            register_calendar('DMY', dummy_cal)

        # Deregister the calendar and ensure that it is removed
        deregister_calendar('DMY')
        with self.assertRaises(InvalidCalendarName):
            get_calendar('DMY')
Esempio n. 6
0
def run_example(example_name, environ):
    """
    Run an example module from catalyst.examples.
    """
    mod = EXAMPLE_MODULES[example_name]

    register_calendar("YAHOO", get_calendar("NYSE"), force=True)

    return run_algorithm(
        initialize=getattr(mod, 'initialize', None),
        handle_data=getattr(mod, 'handle_data', None),
        before_trading_start=getattr(mod, 'before_trading_start', None),
        analyze=getattr(mod, 'analyze', None),
        bundle='test',
        environ=environ,
        # Provide a default capital base, but allow the test to override.
        **merge({'capital_base': 1e7}, mod._test_args()))
    def test_register_calendar(self):
        # Build a fake calendar
        dummy_cal = self.dummy_cal_type()

        # Try to register and retrieve the calendar
        register_calendar('DMY', dummy_cal)
        retr_cal = get_calendar('DMY')
        self.assertEqual(dummy_cal, retr_cal)

        # Try to register again, expecting a name collision
        with self.assertRaises(CalendarNameCollision):
            register_calendar('DMY', dummy_cal)

        # Deregister the calendar and ensure that it is removed
        deregister_calendar('DMY')
        with self.assertRaises(InvalidCalendarName):
            get_calendar('DMY')
Esempio n. 8
0
def run_example(example_name, environ):
    """
    Run an example module from catalyst.examples.
    """
    mod = EXAMPLE_MODULES[example_name]

    register_calendar("YAHOO", get_calendar("NYSE"), force=True)

    return run_algorithm(
        initialize=getattr(mod, 'initialize', None),
        handle_data=getattr(mod, 'handle_data', None),
        before_trading_start=getattr(mod, 'before_trading_start', None),
        analyze=getattr(mod, 'analyze', None),
        bundle='test',
        environ=environ,
        # Provide a default capital base, but allow the test to override.
        **merge({'capital_base': 1e7}, mod._test_args())
    )
Esempio n. 9
0
		for day in pd.date_range(start_session, end_session, freq='D', closed='left'):
			key = symbol+'-'+day.strftime("%Y-%m-%d")
			if key not in cache:
				cache[key] = _get_minute_bar(symbol, day)
			yield sid, cache[key]


def bitmex(symbols: list):
	def ingest(
			environ,
			asset_db_writer,
			minute_bar_writer,
			daily_bar_writer,
			adjustment_writer,
			calendar,
			start_session,
			end_session,
			cache,
			show_progress,
			output_dir,
			path):
		sid_map = list(zip(range(len(symbols)), symbols))
		asset_db_writer.write(futures=_get_metadata(sid_map))
		minute_bar_writer.write(
				_get_minute_bars(sid_map, start_session, end_session, cache),
				show_progress=show_progress)
		adjustment_writer.write()
	return ingest

register_calendar('bitmex', BitmexCalendar())