Beispiel #1
0
    def sum(self, *args, engine=None, engine_kwargs=None, **kwargs):
        if not self.adjust:
            raise NotImplementedError(
                "sum is not implemented with adjust=False")
        if maybe_use_numba(engine):
            if self.method == "single":
                func = generate_numba_ewm_func
            else:
                func = generate_numba_ewm_table_func
            ewm_func = func(
                **get_jit_arguments(engine_kwargs),
                com=self._com,
                adjust=self.adjust,
                ignore_na=self.ignore_na,
                deltas=tuple(self._deltas),
                normalize=False,
            )
            return self._apply(ewm_func)
        elif engine in ("cython", None):
            if engine_kwargs is not None:
                raise ValueError("cython engine does not accept engine_kwargs")
            nv.validate_window_func("sum", args, kwargs)

            deltas = None if self.times is None else self._deltas
            window_func = partial(
                window_aggregations.ewm,
                com=self._com,
                adjust=self.adjust,
                ignore_na=self.ignore_na,
                deltas=deltas,
                normalize=False,
            )
            return self._apply(window_func)
        else:
            raise ValueError("engine must be either 'numba' or 'cython'")
Beispiel #2
0
 def mean(self, *args, engine=None, engine_kwargs=None, **kwargs):
     if maybe_use_numba(engine):
         if self.method == "single":
             ewma_func = generate_numba_ewma_func(engine_kwargs, self._com,
                                                  self.adjust,
                                                  self.ignore_na,
                                                  self._deltas)
             numba_cache_key = (lambda x: x, "ewma")
         else:
             ewma_func = generate_ewma_numba_table_func(
                 engine_kwargs, self._com, self.adjust, self.ignore_na,
                 self._deltas)
             numba_cache_key = (lambda x: x, "ewma_table")
         return self._apply(
             ewma_func,
             numba_cache_key=numba_cache_key,
         )
     elif engine in ("cython", None):
         if engine_kwargs is not None:
             raise ValueError("cython engine does not accept engine_kwargs")
         nv.validate_window_func("mean", args, kwargs)
         window_func = partial(
             window_aggregations.ewma,
             com=self._com,
             adjust=self.adjust,
             ignore_na=self.ignore_na,
             deltas=self._deltas,
         )
         return self._apply(window_func)
     else:
         raise ValueError("engine must be either 'numba' or 'cython'")
Beispiel #3
0
    def mean(self, *args, **kwargs):
        """
        Exponential weighted moving average.

        Parameters
        ----------
        *args, **kwargs
            Arguments and keyword arguments to be passed into func.
        """
        nv.validate_window_func("mean", args, kwargs)
        if self.times is not None:
            window_func = window_aggregations.ewma_time
            window_func = partial(
                window_func,
                times=self.times,
                halflife=self.halflife,
            )
        else:
            window_func = window_aggregations.ewma
            window_func = partial(
                window_func,
                com=self.com,
                adjust=self.adjust,
                ignore_na=self.ignore_na,
            )
        return self._apply(window_func)
Beispiel #4
0
    def mean(self, *args, **kwargs):
        """
        Exponential weighted moving average.

        Parameters
        ----------
        *args, **kwargs
            Arguments and keyword arguments to be passed into func.
        """
        nv.validate_window_func("mean", args, kwargs)
        return self._apply("ewma", **kwargs)
Beispiel #5
0
 def mean(self, *args, **kwargs):
     nv.validate_window_func("mean", args, kwargs)
     window_func = window_aggregations.ewma
     window_func = partial(
         window_func,
         com=self._com,
         adjust=self.adjust,
         ignore_na=self.ignore_na,
         deltas=self._deltas,
     )
     return self._apply(window_func)
Beispiel #6
0
    def var(self, bias: bool = False, *args, **kwargs):
        """
        Exponential weighted moving variance.
        """
        nv.validate_window_func("var", args, kwargs)

        def f(arg):
            return window_aggregations.ewmcov(
                arg, arg, self.com, self.adjust, self.ignore_na, self.min_periods, bias
            )

        return self._apply(f)
Beispiel #7
0
 def std(self,
         bias: bool = False,
         numeric_only: bool = False,
         *args,
         **kwargs):
     nv.validate_window_func("std", args, kwargs)
     if (numeric_only and self._selected_obj.ndim == 1
             and not is_numeric_dtype(self._selected_obj.dtype)):
         # Raise directly so error message says std instead of var
         raise NotImplementedError(
             f"{type(self).__name__}.std does not implement numeric_only")
     return zsqrt(self.var(bias=bias, numeric_only=numeric_only, **kwargs))
Beispiel #8
0
    def var(self, bias: bool = False, *args, **kwargs):
        nv.validate_window_func("var", args, kwargs)
        window_func = window_aggregations.ewmcov
        wfunc = partial(
            window_func,
            com=self._com,
            adjust=self.adjust,
            ignore_na=self.ignore_na,
            bias=bias,
        )

        def var_func(values, begin, end, min_periods):
            return wfunc(values, begin, end, min_periods, values)

        return self._apply(var_func)
Beispiel #9
0
 def mean(self, *args, **kwargs):
     nv.validate_window_func("mean", args, kwargs)
     if self.times is not None:
         window_func = window_aggregations.ewma_time
         window_func = partial(
             window_func,
             times=self.times,
             halflife=self.halflife,
         )
     else:
         window_func = window_aggregations.ewma
         window_func = partial(
             window_func,
             com=self.com,
             adjust=self.adjust,
             ignore_na=self.ignore_na,
         )
     return self._apply(window_func)
Beispiel #10
0
    def var(self, bias=False, *args, **kwargs):
        """
        Exponential weighted moving variance.
        """
        nv.validate_window_func("var", args, kwargs)

        def f(arg):
            return libwindow.ewmcov(
                arg,
                arg,
                self.com,
                int(self.adjust),
                int(self.ignore_na),
                int(self.min_periods),
                int(bias),
            )

        return self._apply(f, **kwargs)
Beispiel #11
0
    def var(self, bias: bool = False, *args, **kwargs):
        """
        Exponential weighted moving variance.
        """
        nv.validate_window_func("var", args, kwargs)
        window_func = self._get_roll_func("ewmcov")
        window_func = partial(
            window_func,
            com=self.com,
            adjust=self.adjust,
            ignore_na=self.ignore_na,
            bias=bias,
        )

        def var_func(values, begin, end, min_periods):
            return window_func(values, begin, end, min_periods, values)

        return self._apply(var_func)
Beispiel #12
0
    def mean(self, *args, **kwargs):
        """
        Exponential weighted moving average.

        Parameters
        ----------
        *args, **kwargs
            Arguments and keyword arguments to be passed into func.
        """
        nv.validate_window_func("mean", args, kwargs)
        window_func = self._get_roll_func("ewma")
        window_func = partial(
            window_func,
            com=self.com,
            adjust=self.adjust,
            ignore_na=self.ignore_na,
            minp=self.min_periods,
        )
        return self._apply(window_func)
Beispiel #13
0
    def mean(
        self,
        numeric_only: bool = False,
        *args,
        engine=None,
        engine_kwargs=None,
        **kwargs,
    ):
        maybe_warn_args_and_kwargs(type(self), "mean", args, kwargs)
        if maybe_use_numba(engine):
            if self.method == "single":
                func = generate_numba_ewm_func
            else:
                func = generate_numba_ewm_table_func
            ewm_func = func(
                **get_jit_arguments(engine_kwargs),
                com=self._com,
                adjust=self.adjust,
                ignore_na=self.ignore_na,
                deltas=tuple(self._deltas),
                normalize=True,
            )
            return self._apply(ewm_func, name="mean")
        elif engine in ("cython", None):
            if engine_kwargs is not None:
                raise ValueError("cython engine does not accept engine_kwargs")
            nv.validate_window_func("mean", args, kwargs)

            deltas = None if self.times is None else self._deltas
            window_func = partial(
                window_aggregations.ewm,
                com=self._com,
                adjust=self.adjust,
                ignore_na=self.ignore_na,
                deltas=deltas,
                normalize=True,
            )
            return self._apply(window_func,
                               name="mean",
                               numeric_only=numeric_only)
        else:
            raise ValueError("engine must be either 'numba' or 'cython'")
Beispiel #14
0
 def mean(self, *args, **kwargs):
     nv.validate_window_func("mean", args, kwargs)
     if self.times is not None:
         com = 1.0
         times = self.times.astype(np.float64)
         halflife = float(self.halflife)
     else:
         com = self.com
         times = np.arange(len(self.obj), dtype=np.float64)
         halflife = 1.0
     window_func = window_aggregations.ewma
     window_func = partial(
         window_func,
         com=com,
         adjust=self.adjust,
         ignore_na=self.ignore_na,
         times=times,
         halflife=halflife,
     )
     return self._apply(window_func)
Beispiel #15
0
    def var(self,
            bias: bool = False,
            numeric_only: bool = False,
            *args,
            **kwargs):
        maybe_warn_args_and_kwargs(type(self), "var", args, kwargs)
        nv.validate_window_func("var", args, kwargs)
        window_func = window_aggregations.ewmcov
        wfunc = partial(
            window_func,
            com=self._com,
            adjust=self.adjust,
            ignore_na=self.ignore_na,
            bias=bias,
        )

        def var_func(values, begin, end, min_periods):
            return wfunc(values, begin, end, min_periods, values)

        return self._apply(var_func, name="var", numeric_only=numeric_only)
Beispiel #16
0
 def std(self, bias: bool = False, *args, **kwargs):
     nv.validate_window_func("std", args, kwargs)
     return zsqrt(self.var(bias=bias, **kwargs))
Beispiel #17
0
 def std(self, bias: bool = False, *args, **kwargs):
     """
     Exponential weighted moving stddev.
     """
     nv.validate_window_func("std", args, kwargs)
     return zsqrt(self.var(bias=bias, **kwargs))