예제 #1
0
def chaikin_osc(cadl: nda.NdType, fast_ma: tp.Any = 3, slow_ma: tp.Any = 10):
    """
    Chaikin Accumulation Distribution Oscillator
    :return:
    """
    if isinstance(fast_ma, int):
        fast_ma_period = fast_ma
        fast_ma = lambda s: ema(s, fast_ma_period)
    if isinstance(slow_ma, int):
        slow_ma_period = slow_ma
        slow_ma = lambda s: ema(s, slow_ma_period)
    fast = fast_ma(cadl)
    slow = slow_ma(cadl)
    return fast - slow
예제 #2
0
def sroc(series: nda.NdType, ma: tp.Any = 13, periods: int = 21):
    """
    Smooth rate of change
    """
    if isinstance(ma, int):
        ma_period = ma
        ma = lambda s: ema(s, ma_period)
    smooth = ma(series)
    return roc(smooth, periods)
예제 #3
0
def macd(series: NdType, fast_ma: tp.Any = 12, slow_ma: tp.Any = 26, signal_ma: tp.Any = 9) \
        -> tp.Tuple[NdType, NdType, NdType]:
    """
    MACD
    :return: (macd_line, signal_line, histogram)
    """
    if isinstance(fast_ma, int):
        fast_ma_period = fast_ma
        fast_ma = lambda s: ema(s, fast_ma_period)
    if isinstance(slow_ma, int):
        slow_ma_period = slow_ma
        slow_ma = lambda s: ema(s, slow_ma_period)
    if isinstance(signal_ma, int):
        signal_ma_period = signal_ma
        signal_ma = lambda s: ema(s, signal_ma_period)
    fast = fast_ma(series)
    slow = slow_ma(series)
    macd_line = fast - slow
    signal_line = signal_ma(macd_line)
    hist = macd_line - signal_line
    return macd_line, signal_line, hist