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)
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
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
def rolling_min(series, window=20): return rolling_func(series, window, [np.min])[0]
def rolling_max(series, window=20): return rolling_func(series, window, [np.max])[0]
def sma(series, window=20): return rolling_func(series, window, [np.mean])[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)
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)