Ejemplo n.º 1
0
def mstd_nb(a, window, ewm, adjust=False, ddof=0):
    """Compute simple or exponential moving STD (`ewm=True`)."""
    if ewm:
        return generic_nb.ewm_std_nb(a,
                                     window,
                                     minp=window,
                                     adjust=adjust,
                                     ddof=ddof)
    return generic_nb.rolling_std_nb(a, window, minp=window, ddof=ddof)
Ejemplo n.º 2
0
def future_std_apply_nb(close, window, ewm, wait=1, adjust=False, ddof=0):
    """Get the standard deviation of the next period."""
    if ewm:
        out = generic_nb.ewm_std_nb(close[::-1], window, minp=window, adjust=adjust, ddof=ddof)[::-1]
    else:
        out = generic_nb.rolling_std_nb(close[::-1], window, minp=window, ddof=ddof)[::-1]
    if wait > 0:
        return generic_nb.bshift_nb(out, wait)
    return out
Ejemplo n.º 3
0
def mstd_caching_nb(ts, windows, ewms):
    """Caching function for `vectorbt.indicators.basic.MSTD`."""
    cache_dict = dict()
    for i in range(windows.shape[0]):
        h = hash((windows[i], ewms[i]))
        if h not in cache_dict:
            if ewms[i]:
                mstd = generic_nb.ewm_std_nb(ts, windows[i])
            else:
                mstd = generic_nb.rolling_std_nb(ts, windows[i])
            cache_dict[h] = mstd
    return cache_dict
Ejemplo n.º 4
0
def mstd_nb(a: tp.Array2d,
            window: int,
            ewm: int,
            adjust: bool = False,
            ddof: int = 0) -> tp.Array2d:
    """Compute simple or exponential moving STD (`ewm=True`)."""
    if ewm:
        return generic_nb.ewm_std_nb(a,
                                     window,
                                     minp=window,
                                     adjust=adjust,
                                     ddof=ddof)
    return generic_nb.rolling_std_nb(a, window, minp=window, ddof=ddof)
Ejemplo n.º 5
0
def future_std_apply_nb(close: tp.Array2d,
                        window: int,
                        ewm: bool,
                        wait: int = 1,
                        adjust: bool = False,
                        ddof: int = 0) -> tp.Array2d:
    """Get the standard deviation of the next period."""
    if ewm:
        out = generic_nb.ewm_std_nb(close[::-1],
                                    window,
                                    minp=window,
                                    adjust=adjust,
                                    ddof=ddof)[::-1]
    else:
        out = generic_nb.rolling_std_nb(close[::-1],
                                        window,
                                        minp=window,
                                        ddof=ddof)[::-1]
    if wait > 0:
        return generic_nb.bshift_nb(out, wait)
    return out
Ejemplo n.º 6
0
 def rolling_std(self, window, minp=1, ddof=1):  # pragma: no cover
     return self.wrap(
         nb.rolling_std_nb(self.to_2d_array(), window, minp=minp,
                           ddof=ddof))
Ejemplo n.º 7
0
 def rolling_std(self, window, minp=1, ddof=1):  # pragma: no cover
     """See `vectorbt.generic.nb.rolling_std_nb`."""
     return self.wrap(
         nb.rolling_std_nb(self.to_2d_array(), window, minp=minp,
                           ddof=ddof))