Beispiel #1
0
    def test_expanding_apply_args_kwargs(self):
        def mean_w_arg(x, const):
            return np.mean(x) + const

        df = DataFrame(np.random.rand(20, 3))

        expected = mom.expanding_apply(df, np.mean) + 20.0

        assert_frame_equal(mom.expanding_apply(df, mean_w_arg, args=(20,)), expected)
        assert_frame_equal(mom.expanding_apply(df, mean_w_arg, kwargs={"const": 20}), expected)
    def test_expanding_apply_args_kwargs(self):
        def mean_w_arg(x, const):
            return np.mean(x) + const

        df = DataFrame(np.random.rand(20, 3))

        expected = mom.expanding_apply(df, np.mean) + 20.

        assert_frame_equal(mom.expanding_apply(df, mean_w_arg, args=(20, )),
                           expected)
        assert_frame_equal(
            mom.expanding_apply(df, mean_w_arg, kwargs={'const': 20}),
            expected)
Beispiel #3
0
    def test_expanding_apply(self):
        ser = Series([])
        assert_series_equal(ser, mom.expanding_apply(ser, lambda x: x.mean()))

        def expanding_mean(x, min_periods=1, freq=None):
            return mom.expanding_apply(x, lambda x: x.mean(), min_periods=min_periods, freq=freq)

        self._check_expanding(expanding_mean, np.mean)
Beispiel #4
0
    def test_expanding_apply(self):
        ser = Series([])
        assert_series_equal(ser, mom.expanding_apply(ser, lambda x: x.mean()))

        def expanding_mean(x, min_periods=1, freq=None):
            return mom.expanding_apply(x,
                                         lambda x: x.mean(),
                                         min_periods=min_periods,
                                         freq=freq)
        self._check_expanding(expanding_mean, np.mean)
Beispiel #5
0
 def expanding_mean(x, min_periods=1, freq=None):
     return mom.expanding_apply(x,
                                lambda x: x.mean(),
                                min_periods=min_periods,
                                freq=freq)
Beispiel #6
0
 def expanding_mean(x, min_periods=1, freq=None):
     return mom.expanding_apply(x,
                                lambda x: x.mean(),
                                min_periods=min_periods,
                                freq=freq)
Beispiel #7
0
def getPerc(X):
    res1 = pd.Series(X.shift(-1).Close / X.Close)
    res2 = expanding_apply(
        res1, lambda p: functools.reduce(operator.mul, p, 1)).shift(1)
    return res2.dropna()
def getPerc(X):
        res1=pd.Series(X.shift(-1).Close/X.Close)
        res2=expanding_apply(res1,lambda p:functools.reduce(operator.mul, p, 1)).shift(1)
        return res2.dropna()