mpquant / MyTT

MyTT将通达信,同花顺,文华麦语言等指标公式,最简移植到Python中,核心库单个文件,仅百行代码,十几个核心函数,神奇的实现所有常见技术指标算法(不依赖talib库)的纯python实现和转换通达信MACD,RSI,BOLL,ATR,KDJ,CCI,PSY等公式,全部基于pandas函数计算方法封装,简洁且高性能,能非常方便的应用在股票指标公式,股市期货量化框架分析,自动程序化交易,数字货币量化等领域,它是您最精练的股市量化工具。Python library with most stock market indicators.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DMI算法有误,贡献一个更正后的算法

WangXiaopai595 opened this issue · comments

通过和币安、欧易对比,DMI值相差非常大,应该是算法有误

经过对算法分析,你这个算法部分地方有bug,正确代码如下:

def DMI(CLOSE, HIGH, LOW, M1=14, M2=6): 
    TR = SMA(MAX(MAX(HIGH - LOW, ABS(HIGH - REF(CLOSE, 1))), ABS(LOW - REF(CLOSE, 1))), M2)
    UP = HIGH - REF(HIGH, 1)
    DOWN = REF(LOW, 1) - LOW
    DMP = SMA(IF((UP > 0) & (UP > DOWN), UP, 0), M2)
    DMM = SMA(IF((DOWN > 0) & (DOWN > UP), DOWN, 0), M2)
    PDI = DMP * 100 / TR
    MDI = DMM * 100 / TR
    ADX = SMA(ABS(MDI - PDI) / (PDI + MDI) * 100, M1)
    ADXR = (ADX + REF(ADX, M1)) / 2
    return PDI, MDI, ADX, ADXR