Пример #1
0
def test_date_from_idx():
    d1 = datetime(2008, 12, 31)
    idx = 15
    npt.assert_equal(_date_from_idx(d1, idx, 'Q'), datetime(2012, 9, 30))
    npt.assert_equal(_date_from_idx(d1, idx, 'A'), datetime(2023, 12, 31))
    npt.assert_equal(_date_from_idx(d1, idx, 'B'), datetime(2009, 1, 21))
    npt.assert_equal(_date_from_idx(d1, idx, 'D'), datetime(2009, 1, 15))
    npt.assert_equal(_date_from_idx(d1, idx, 'W'), datetime(2009, 4, 12))
    npt.assert_equal(_date_from_idx(d1, idx, 'M'), datetime(2010, 3, 31))
Пример #2
0
    def _get_predict_end(self, end):
        """
        See _get_predict_start for more information. Subclasses do not
        need to define anything for this.
        """

        out_of_sample = 0 # will be overwritten if needed
        if end is None:
            end = len(self.endog) - 1

        dates = self._data.dates
        if isinstance(end, str):
            if dates is None:
                raise ValueError("Got a string for end and dates is None")
            try:
                dtend = self._str_to_date(end)
                self._data.predict_end = dtend
                end = dates.indexMap[dtend]
            except ImportError as err: # make sure timeseries isn't the prob
                raise ImportError(err)
            except KeyError as err: # end is greater than dates[-1]...probably
                if dtend > self._data.dates[-1]:
                    end = len(self.endog) - 1
                    freq = self._data.freq
                    out_of_sample = datetools._idx_from_dates(dates[-1], dtend,
                                            freq)
                else:
                    raise err
            self._make_predict_dates() # attaches self._data.predict_dates

        elif isinstance(end, int) and dates is not None:
            try:
                self._data.predict_end = dates[end]
            except IndexError as err:
                nobs = len(self.endog) - 1 # as an index
                out_of_sample = end - nobs
                end = nobs
                freq = self._data.freq
                self._data.predict_end = datetools._date_from_idx(dates[-1],
                        out_of_sample, freq)
            self._make_predict_dates()

        elif isinstance(end, int):
            nobs = len(self.endog) - 1 # is an index
            if end > nobs:
                out_of_sample = end - nobs
                end = nobs

        return end, out_of_sample
Пример #3
0
    def _get_predict_end(self, end):
        """
        See _get_predict_start for more information. Subclasses do not
        need to define anything for this.
        """

        out_of_sample = 0  # will be overwritten if needed
        if end is None:
            end = len(self.endog) - 1

        dates = self._data.dates
        if isinstance(end, str):
            if dates is None:
                raise ValueError("Got a string for end and dates is None")
            try:
                dtend = self._str_to_date(end)
                self._data.predict_end = dtend
                end = dates.indexMap[dtend]
            except ImportError as err:  # make sure timeseries isn't the prob
                raise ImportError(err)
            except KeyError as err:  # end is greater than dates[-1]...probably
                if dtend > self._data.dates[-1]:
                    end = len(self.endog) - 1
                    freq = self._data.freq
                    out_of_sample = datetools._idx_from_dates(
                        dates[-1], dtend, freq)
                else:
                    raise err
            self._make_predict_dates()  # attaches self._data.predict_dates

        elif isinstance(end, int) and dates is not None:
            try:
                self._data.predict_end = dates[end]
            except IndexError as err:
                nobs = len(self.endog) - 1  # as an index
                out_of_sample = end - nobs
                end = nobs
                freq = self._data.freq
                self._data.predict_end = datetools._date_from_idx(
                    dates[-1], out_of_sample, freq)
            self._make_predict_dates()

        elif isinstance(end, int):
            nobs = len(self.endog) - 1  # is an index
            if end > nobs:
                out_of_sample = end - nobs
                end = nobs

        return end, out_of_sample