Ejemplo n.º 1
0
def vortex_index(high, low, close, window=20):
    true_range = np.maximum.reduce(
        [high[1:] - low[1:], high[1:] - close[:-1], low[1:] - close[:-1]])
    true_range = offset(rolling_func(true_range, window, [np.sum])[0], 1)
    uptrend = offset(np.abs(high[1:] - low[:-1]), 1)
    downtrend = offset(np.abs(low[1:] - high[:-1]), 1)

    vi_plus = divide(rolling_func(uptrend, window, [np.sum])[0], true_range)
    vi_minus = divide(rolling_func(downtrend, window, [np.sum])[0], true_range)
    vi_plus[:window] = np.nan
    vi_minus[:window] = np.nan
    return replace_nan(vi_plus), replace_nan(vi_minus)
Ejemplo n.º 2
0
def aroon(high, low, window=20):
    aroon_up = rolling_func(high, window + 1, [np.argmax])[0] / window
    aroon_down = rolling_func(low, window + 1, [np.argmin])[0] / window
    return aroon_down * 100, aroon_up * 100
Ejemplo n.º 3
0
def b_bands(price, window=20, multiplier=2):
    mean, std = rolling_func(price, window, [np.mean, np.std])
    lower = mean - multiplier * std
    upper = mean + multiplier * std
    return upper, mean, lower
Ejemplo n.º 4
0
def rolling_min(series, window=20):
    return rolling_func(series, window, [np.min])[0]
Ejemplo n.º 5
0
def rolling_max(series, window=20):
    return rolling_func(series, window, [np.max])[0]
Ejemplo n.º 6
0
def sma(series, window=20):
    return rolling_func(series, window, [np.mean])[0]
Ejemplo n.º 7
0
def cci(high, low, close, window=20):
    typical_price = true_price(high, low, close)
    ma_price, std = rolling_func(typical_price, window, [np.mean, np.std])
    cci = divide(typical_price - ma_price, 0.015 * std)
    return replace_nan(cci)
Ejemplo n.º 8
0
def vwma(price, volume, window=20):
    volume_sum = rolling_func(volume, window, [np.sum])[0]
    price_volume = rolling_func(price * volume, window, [np.sum])[0]
    vwma = divide(price_volume, volume_sum)
    return replace_nan(vwma)