voice32 / stock_market_indicators

A small Python library with most common stock market indicators
224 stars 108 forks source link

chaikin_oscillator #1

Closed renbuar closed 6 years ago

renbuar commented 6 years ago
  1. Money Flow Multiplier = [(Close - Low) - (High - Close)] /(High - Low)

    1. Money Flow Volume = Money Flow Multiplier x Volume for the Period

    2. ADL = Previous ADL + Current Period's Money Flow Volume

    3. Chaikin Oscillator = (3-day EMA of ADL) - (10-day EMA of ADL)


      Функция не учитывает предыдущее значение ADL, а в целом спасибо! ADL = Previous ADL + Current Period's Money Flow Volume

def chaikin_oscillator(data, periods_short=3, periods_long=10, high_col='', low_col='', close_col='', vol_col=''): ac = pd.Series([]) val_last = 0 for index, row in data.iterrows(): if row[high_col] != row[low_col]: val = val_last + ((row[close_col] - row[low_col]) - (row[high_col] - row[close_col])) / (row[high_col] - row[low_col]) * row[vol_col] else: val = val_last ac.set_value(index, val) val_last = val ema_long = ac.ewm(ignore_na=False, min_periods=0, com=periods_long, adjust=True).mean() ema_short = ac.ewm(ignore_na=False, min_periods=0, com=periods_short, adjust=True).mean() data['ch_osc'] = ema_short - ema_long

return data
voice32 commented 6 years ago

Спасибо! Пофиксил :)

chernovars commented 6 years ago

Надо тогда еще поправить Accumulation/Distribution line =)

def acc_dist(data, trend_periods=21, series=True, open_col='Open', ema=False, high_col='High', low_col='Low', close_col='Close', vol_col='Volume'):
    ######## val_last = 0
    for index, row in data.iterrows():
        if row[high_col] != row[low_col]:
            ac = val_last + ((row[close_col] - row[low_col]) - (row[high_col] - row[close_col])) / (row[high_col] - row[low_col]) * row[vol_col]
        else:
            ac = 0
        ######## val_last  = ac
        data.set_value(index, 'acc_dist', ac)
    data['acc_dist_ema' + str(trend_periods)] = data['acc_dist'].ewm(ignore_na=False, min_periods=0, com=trend_periods, adjust=True).mean()