Example #1
0
def apply_filters(data):
    """
    Applies all 4 filters asked for and returns them in a python list.

    The list will be structured with rows in the following order:
        1. Linear OLS trend
        2. HP filters
        3. Bandpass filter
        4. First-difference

    Parameters
    ----------
    data: array-like, dtype=float
        The data set that will be run through the filters

    Returns
    -------
    filtered: list
        This is a 4 element list with the filtered data in the order
        listed above.

    Notes
    -----
        Because of how the filters work, the bandpass and first diff
        arrays will be different sizes than the hp filter ones.

        Note also that before applying the filters, we take the natural
        log of the data.
    """
    data = np.log(data)

    linear_ols = filters.hp_filter(data, lam=1e10)[1]
    hp_fils = filters.hp_filter(data, lam=1600)[1]
    bp_fils = filters.bandpass_filter(data, 10, 6, 32)

    temp1 = data.copy()
    temp1 = np.insert(temp1, temp1.size, 0)
    temp2 = data.copy()
    temp2 = np.insert(temp2, 0, 0)
    yhat = temp1 - temp2
    first_diff = yhat[1:-1]

    all_fils = [linear_ols, hp_fils, bp_fils, first_diff]

    return all_fils
Example #2
0
    def test_hpfilter(self):

        from dolo.numeric.filters import hp_filter

        import numpy
        import numpy.random

        sig = numpy.eye(2)  # number of series
        N = 100  # number of observations

        dumb_series = numpy.random.multivariate_normal([0, 0], sig, N).T

        trend_test = hpfilter_dense(dumb_series)

        [T, cycle] = hp_filter(dumb_series)

        from numpy.testing import assert_almost_equal

        assert_almost_equal(trend_test, T)
Example #3
0
    def test_hpfilter(self):

        from dolo.numeric.filters import hp_filter

        import numpy
        import numpy.random

        sig = numpy.eye( 2 )  # number of series
        N = 100  # number of observations

        dumb_series = numpy.random.multivariate_normal([0,0], sig, N).T

        trend_test = hpfilter_dense(dumb_series)

        [T, cycle] = hp_filter(dumb_series)

        from numpy.testing import assert_almost_equal

        assert_almost_equal(trend_test, T)