- EMA(CLOSE, 10),
talib.set_compatibility(0)
is the default, and is equivalent toEXPMEMA
- The first not nan value starts as
talib.SMA(CLOSE, 10)
- The first not nan value starts as
- EMA(CLOSE, 10),
talib.set_compatibility(1)
- The first not nan value starts as
CLOSE
- The first not nan value starts as
Since the logic of EMA
calculation has changed in TA-Lib
's compatibility mode 0
, it is complex and inefficient to implement it using expressions.
We only implement compatibility mode 1
.
It just so happens that the Chinese stock software only implements compatibility mode 1
.
You can compare the full data with TA-Lib
for unit testing.
Indicators affected by EMA
include MACD, DEMA, TEMA, TRIX, T3
, etc.
In essence, it is RMA compatibility mode 0
, that is,
the first valid value is the moving average. And then the difference is alpha
SMA(X, N, M) = X.ema_mean(alpha=M/N)
RMA(X, N) = X.ema_mean(alpha=1/N) = SMA(X, N, 1)
EMA(x, N) = X.ema_mean(alpha=2/(N+1)) = X.ema_mean(span=N)
Refer to: ewm_mean
In this case, we use RMA compatibility mode 1
.
There exists error in switching between the two modes.
So please provide enough length of data.
The data in the later part can be used for unit testing.
Indicators affected by SMA
include ATR, RSI
, etc.
Some indicators including ADX
require the first value as a SUM
rather than SMA
. We will implement them later by ema_mean(alpha=1/N)
- In package
wq
,max_/min_
are cross-sectional operators,ts_max/ts_min
are time series indicators - In
talib
,MAX/MIN
are time series indicators, without cross-sectional operators. - In
ta
, to mimictalib
,MAX/MIN
are time series indicators, without cross-sectional operators. - In
tdx
,MAX/MIN
are cross-sectional operators,HHV/LLV
are time series indicators.
- EMA(CLOSE, 10),
talib.set_compatibility(0)
,此为默认设置,等价于EXPMEMA
- 第一个有效值为
talib.SMA(CLOSE, 10)
- 第一个有效值为
- EMA(CLOSE, 10),
talib.set_compatibility(1)
- 第一个有效值为
CLOSE
- 第一个有效值为
由于TA-Lib
的兼容模式0
在EMA
计算时逻辑发生了变动,用表达式实现起来复杂、计算效率低。
所以本库只实现兼容模式1
。正好国内股票软件其实也只实现了兼容模式1
。可以全量数据与TA-Lib
进行单元测试比较
因EMA
受影响的指标有MACD, DEMA, TEMA, TRIX, T3
等。
本质上是国外的RMA 兼容模式0
,即第一个有效值为移动平均,然后就是alpha
区别
SMA(X, N, M) = X.ema_mean(alpha=M/N)
RMA(X, N) = X.ema_mean(alpha=1/N) = SMA(X, N, 1)
EMA(x, N) = X.ema_mean(alpha=2/(N+1)) = X.ema_mean(span=N)
换算关系可参考: ewm_mean
遇到这种情况,本项目还是用RMA 兼容模式1
来代替,数据误差由大到小,所以请预先提供一定长度的数据。后面一段的数据可以单元测试
受影响的的指标有ATR, RSI
等
ADX
等一类的指标第一个有效值算法为SUM
,而不是SMA
,之后使用ema_mean(alpha=1/N)
。此类暂不实现
- 在
wq
中,max_/min_
横向算子,ts_max/ts_min
时序指标 - 在
talib
中,MAX/MIN
时序指标,没有横向算子 - 在
ta
中,由于要模仿talib
,所以有MAX/MIN
时序指标,也没有横向算子 - 在
tdx
中,MAX/MIN
横向算子,HHV/LLV
时序指标