Ejemplo n.º 1
0
def triangular_moving_average(data, period):
    """
    Triangular Moving Average.

    Formula:
    TMA = SMA(SMA())
    """
    catch_errors.check_for_period_error(data, period)

    tma = sma(sma(data, period), period)
    return tma
Ejemplo n.º 2
0
def volume_oscillator(volume, short_period, long_period):
    """
    Volume Oscillator.

    Formula:
    vo = 100 * (SMA(vol, short) - SMA(vol, long) / SMA(vol, long))
    """
    catch_errors.check_for_period_error(volume, short_period)
    catch_errors.check_for_period_error(volume, long_period)

    vo = (100 * ((sma(volume, short_period) - sma(volume, long_period)) /
                 sma(volume, long_period)))
    return vo
Ejemplo n.º 3
0
def between_day_min_ma(day_csv, min_csv, remote=True):
    day_rb = pd.read_csv(day_csv, index_col=0)
    day_rb.index = pd.DatetimeIndex(day_rb.index)
    min_rb = pd.read_csv(min_csv, index_col=0)
    min_rb.index = pd.DatetimeIndex(min_rb.index)
    short = sma(min_rb['close'], 5)
    long = sma(day_rb['close'], 2)
    # plot_kline(day_rb)
    _plot_lines((list(range(min_rb.shape[0])), list(range(day_rb.shape[0]))),
                (short, long),
                ('min_short', 'day_long'),
                remote,
                'between_day_min_ma.html')
Ejemplo n.º 4
0
def center_band(data, period):
    """
    Center Band.

    Formula:
    SMA(data)
    """
    cb = sma(data, period)
    return cb
Ejemplo n.º 5
0
def center_band(close_data, high_data, low_data, period):
    """
    Center Band.

    Formula:
    CB = SMA(TP)
    """
    tp = typical_price(close_data, high_data, low_data)
    cb = sma(tp, period)
    return cb
Ejemplo n.º 6
0
def percent_d(data, period):
    """
    %D.

    Formula:
    %D = SMA(%K, 3)
    """
    p_k = percent_k(data, period)
    percent_d = sma(p_k, 3)
    return percent_d
Ejemplo n.º 7
0
def band_width(high_data, low_data, period):
    """
    Bandwidth.

    Formula:
    BW = SMA(H - L)
    """
    catch_errors.check_for_input_len_diff(high_data, low_data)
    diff = np.array(high_data) - np.array(low_data)
    bw = sma(diff, period)
    return bw
Ejemplo n.º 8
0
def commodity_channel_index(close_data, high_data, low_data, period):
    """
    Commodity Channel Index.

    Formula:
    CCI = (TP - SMA(TP)) / (0.015 * Mean Deviation)
    """
    catch_errors.check_for_input_len_diff(close_data, high_data, low_data)
    catch_errors.check_for_period_error(close_data, period)
    tp = typical_price(close_data, high_data, low_data)
    cci = ((tp - sma(tp, period)) /
           (0.015 * np.mean(np.absolute(tp - np.mean(tp)))))
    return cci
Ejemplo n.º 9
0
def middle_bollinger_band(data, period, std=2.0):
    """
    Middle Bollinger Band.

    Formula:
    m_bb = sma()
    """
    catch_errors.check_for_period_error(data, period)

    period = int(period)
    mid_bb = sma(data, period)

    return mid_bb
Ejemplo n.º 10
0
def between_days_ma(day_csv, remote=True):
    day_rb = pd.read_csv(day_csv, index_col=0)
    day_rb.index = pd.DatetimeIndex(day_rb.index)
    index = list(range(day_rb.shape[0]))
    ma_list = [day_rb['close'].values]
    names = ['origin_data']
    for p in range(2, 20, 2):
        ma_list.append(sma(day_rb['close'], p))
        names.append('%s_day_period' % p)
        _plot_lines((index,) * len(ma_list),
                    ma_list,
                    names,
                    remote,
                    'between_days_ma.html')
Ejemplo n.º 11
0
def upper_bollinger_band(data, period, std_mult=2.0):
    """
    Upper Bollinger Band.

    Formula:
    u_bb = SMA(t) + STD(SMA(t-n:t)) * std_mult
    """
    catch_errors.check_for_period_error(data, period)

    period = int(period)
    simple_ma = sma(data, period)[period - 1:]

    upper_bb = []
    for idx in range(len(data) - period + 1):
        std_dev = np.std(data[idx:idx + period])
        upper_bb.append(simple_ma[idx] + std_dev * std_mult)
    upper_bb = fill_for_noncomputable_vals(data, upper_bb)

    return np.array(upper_bb)