Closed renbuar closed 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()
Money Flow Multiplier = [(Close - Low) - (High - Close)] /(High - Low)
Money Flow Volume = Money Flow Multiplier x Volume for the Period
ADL = Previous ADL + Current Period's Money Flow Volume
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