Пример #1
0
    def get_calendar(self, name='SZSH'):
        """
        Retrieves an instance of an TradingCalendar whose name is given.

        Parameters
        ----------
        name : str
            The name of the TradingCalendar to be retrieved.

        Returns
        -------
        calendar : zipline.utils.calendars.TradingCalendar
            The desired calendar.
        """
        canonical_name = self.resolve_alias(name)

        try:
            return self._calendars[canonical_name]
        except KeyError:
            # We haven't loaded this calendar yet, so make a new one.
            pass

        try:
            factory = self._calendar_factories[canonical_name]
        except KeyError:
            # We don't have a factory registered for this name.  Barf.
            raise InvalidCalendarName(calendar_name=name)

        # Cache the calendar for future use.
        calendar = self._calendars[canonical_name] = factory()
        return calendar
Пример #2
0
    def get_calendar(self, name):
        """
        Retrieves an instance of an TradingCalendar whose name is given.

        Parameters
        ----------
        name : str
            The name of the TradingCalendar to be retrieved.

        Returns
        -------
        TradingCalendar
            The desired calendar.
        """
        try:
            return self._calendars[name]
        except KeyError:
            pass

        for names, factory in self._calendar_factories.items():
            if name in names:
                # Use the same calendar for all exchanges that share the same
                # factory.
                calendar = factory()
                self._calendars.update({n: calendar for n in names})
                return calendar

        raise InvalidCalendarName(calendar_name=name)
Пример #3
0
def get_calendar(name):
    """
    Retrieves an instance of an TradingCalendar whose name is given.

    Parameters
    ----------
    name : str
        The name of the TradingCalendar to be retrieved.

    Returns
    -------
    TradingCalendar
        The desired calendar.
    """
    if name not in _static_calendars:
        if name == 'NYSE':
            cal = NYSEExchangeCalendar()
        elif name == 'CME':
            cal = CMEExchangeCalendar()
        elif name == 'BMF':
            cal = BMFExchangeCalendar()
        elif name == 'LSE':
            cal = LSEExchangeCalendar()
        elif name == 'TSX':
            cal = TSXExchangeCalendar()
        elif name == "ICE":
            cal = ICEExchangeCalendar()
        elif name == "CFE":
            cal = CFEExchangeCalendar()
        else:
            raise InvalidCalendarName(calendar_name=name)

        register_calendar(cal)

    return _static_calendars[name]
Пример #4
0
def get_calendar(name):
    """
    Retrieves an instance of an ExchangeCalendar whose name is given.

    Parameters
    ----------
    name : str
        The name of the ExchangeCalendar to be retrieved.
    """
    # First, check if the calendar is already registered
    if name not in _static_calendars:

        # Check if it is a lazy calendar. If so, build and register it.
        if name == 'NYSE':
            from zipline.utils.calendars.exchange_calendar_nyse \
                import NYSEExchangeCalendar
            nyse_cal = NYSEExchangeCalendar()
            register_calendar(nyse_cal)

        elif name == 'CME':
            from zipline.utils.calendars.exchange_calendar_cme \
                import CMEExchangeCalendar
            cme_cal = CMEExchangeCalendar()
            register_calendar(cme_cal)

        elif name == 'BMF':
            from zipline.utils.calendars.exchange_calendar_bmf \
                import BMFExchangeCalendar
            bmf_cal = BMFExchangeCalendar()
            register_calendar(bmf_cal)

        elif name == 'LSE':
            from zipline.utils.calendars.exchange_calendar_lse \
                import LSEExchangeCalendar
            lse_cal = LSEExchangeCalendar()
            register_calendar(lse_cal)

        elif name == 'TSX':
            from zipline.utils.calendars.exchange_calendar_tsx \
                import TSXExchangeCalendar
            tsx_cal = TSXExchangeCalendar()
            register_calendar(tsx_cal)

        else:
            # It's not a lazy calendar, so raise an exception
            raise InvalidCalendarName(calendar_name=name)

    return _static_calendars[name]