def init_class_fixtures(cls):
        super(WithInternationalDailyBarData, cls).init_class_fixtures()

        cls.daily_bar_sessions = {}
        cls.daily_bar_data = {}
        cls.daily_bar_readers = {}

        for calendar, assets, in cls.assets_by_calendar.items():
            name = calendar.name
            start_delta = cls.DAILY_BAR_LOOKBACK_DAYS * calendar.day
            start_session = cls.DAILY_BAR_START_DATE - start_delta

            sessions = calendar.sessions_in_range(
                start_session, cls.DAILY_BAR_END_DATE,
            )

            cls.daily_bar_sessions[name] = sessions
            cls.daily_bar_data[name] = dict(cls.make_daily_bar_data(
                assets=assets, calendar=calendar, sessions=sessions,
            ))

            panel = (pd.Panel.from_dict(cls.daily_bar_data[name])
                     .transpose(2, 1, 0))
            cls.daily_bar_readers[name] = InMemoryDailyBarReader.from_panel(
                panel,
                calendar,
            )
    def init_class_fixtures(cls):
        super(WithInternationalDailyBarData, cls).init_class_fixtures()

        cls.daily_bar_sessions = {}
        cls.daily_bar_data = {}
        cls.daily_bar_readers = {}
        cls.daily_bar_currency_codes = {}

        for calendar, assets, in cls.assets_by_calendar.items():
            name = calendar.name
            start_delta = cls.DAILY_BAR_LOOKBACK_DAYS * calendar.day
            start_session = cls.DAILY_BAR_START_DATE - start_delta

            sessions = calendar.sessions_in_range(
                start_session,
                cls.DAILY_BAR_END_DATE,
            )

            cls.daily_bar_sessions[name] = sessions
            cls.daily_bar_data[name] = dict(
                cls.make_daily_bar_data(
                    assets=assets,
                    calendar=calendar,
                    sessions=sessions,
                ))

            panel = pd.concat(cls.daily_bar_data[name], axis=0)
            dict_data = {}
            for column in panel.columns:
                dict_data[column] = pd.DataFrame(
                    panel[column]).unstack(level=0)
                dict_data[column].columns = dict_data[
                    column].columns.droplevel(0)

            cls.daily_bar_currency_codes[name] = cls.make_currency_codes(
                calendar,
                assets,
            )

            cls.daily_bar_readers[name] = InMemoryDailyBarReader.from_panel(
                dict_data,
                calendar,
                currency_codes=cls.daily_bar_currency_codes[name],
            )
Exemplo n.º 3
0
    def init_class_fixtures(cls):
        super(WithInternationalDailyBarData, cls).init_class_fixtures()

        cls.daily_bar_sessions = {}
        cls.daily_bar_data = {}
        cls.daily_bar_readers = {}
        cls.daily_bar_currency_codes = {}

        for calendar, assets, in cls.assets_by_calendar.items():
            name = calendar.name
            start_delta = cls.DAILY_BAR_LOOKBACK_DAYS * calendar.day
            start_session = cls.DAILY_BAR_START_DATE - start_delta

            sessions = calendar.sessions_in_range(
                start_session,
                cls.DAILY_BAR_END_DATE,
            )

            cls.daily_bar_sessions[name] = sessions
            cls.daily_bar_data[name] = dict(
                cls.make_daily_bar_data(
                    assets=assets,
                    calendar=calendar,
                    sessions=sessions,
                ))

            panel = (pd.Panel.from_dict(cls.daily_bar_data[name]).transpose(
                2, 1, 0))

            cls.daily_bar_currency_codes[name] = cls.make_currency_codes(
                calendar,
                assets,
            )

            cls.daily_bar_readers[name] = InMemoryDailyBarReader.from_panel(
                panel,
                calendar,
                currency_codes=cls.daily_bar_currency_codes[name],
            )