TA-Lib 在有限数据帧上的奇怪行为

TA-Lib's strange behaviour on limited dataframe

这个 TA-Lib 代码

df = pd.read_csv('RTS-MINUTES15.csv', header=None, 
    names=['index', 'OPEN', 'HIGH', 'LOW', 'CLOSE', 'VOL'], 
    index_col=0, skiprows = 1, nrows = 15)    

df['HAMMER'] = talib.CDLHAMMER(df['OPEN'], df['HIGH'], df['LOW'], df['CLOSE'])
print(df)

给予

                         OPEN      HIGH       LOW     CLOSE    VOL  HAMMER
index
2020-10-23 10:00:00  115090.0  115180.0  114720.0  114890.0  25100       0
2020-10-23 10:15:00  114890.0  115140.0  114600.0  115120.0  20920       0
2020-10-23 10:30:00  115120.0  115690.0  115120.0  115670.0  30587       0
2020-10-23 10:45:00  115670.0  115750.0  115510.0  115690.0  16208       0
2020-10-23 11:00:00  115700.0  115960.0  115540.0  115950.0  22705       0
2020-10-23 11:15:00  115950.0  116270.0  115900.0  116250.0  24552       0
2020-10-23 11:30:00  116250.0  116350.0  116080.0  116240.0  14682       0
2020-10-23 11:45:00  116240.0  116290.0  115960.0  116030.0  10856       0
2020-10-23 12:00:00  116030.0  116120.0  115950.0  116080.0   5965       0
2020-10-23 12:15:00  116070.0  116420.0  116060.0  116230.0  12657       0
2020-10-23 12:30:00  116230.0  116340.0  116160.0  116170.0   6673       0
2020-10-23 12:45:00  116170.0  116270.0  116120.0  116190.0   6299       0
2020-10-23 13:00:00  116200.0  116390.0  116190.0  116220.0   9088       0
**2020-10-23 13:15:00  116240.0  116260.0  116070.0  116180.0   8626     100**
2020-10-23 13:30:00  116180.0  116240.0  116060.0  116110.0   5722       0

代码运行良好,行“2020-10-23 13:15:00”中的 HAMMER = 100

但是如果我使用“skiprows=5”而不是“skiprows=1”,那么 TA-Lib 就找不到 HAMMER:

df = pd.read_csv('RTS-MINUTES15.csv', header=None, 
    names=['index', 'OPEN', 'HIGH', 'LOW', 'CLOSE', 'VOL'], 
    index_col=0, skiprows = 5, nrows = 15)    

结果

                         OPEN      HIGH       LOW     CLOSE    VOL  HAMMER
index
2020-10-23 11:00:00  115700.0  115960.0  115540.0  115950.0  22705       0
2020-10-23 11:15:00  115950.0  116270.0  115900.0  116250.0  24552       0
2020-10-23 11:30:00  116250.0  116350.0  116080.0  116240.0  14682       0
2020-10-23 11:45:00  116240.0  116290.0  115960.0  116030.0  10856       0
2020-10-23 12:00:00  116030.0  116120.0  115950.0  116080.0   5965       0
2020-10-23 12:15:00  116070.0  116420.0  116060.0  116230.0  12657       0
2020-10-23 12:30:00  116230.0  116340.0  116160.0  116170.0   6673       0
2020-10-23 12:45:00  116170.0  116270.0  116120.0  116190.0   6299       0
2020-10-23 13:00:00  116200.0  116390.0  116190.0  116220.0   9088       0
**2020-10-23 13:15:00  116240.0  116260.0  116070.0  116180.0   8626       0**
2020-10-23 13:30:00  116180.0  116240.0  116060.0  116110.0   5722       0
2020-10-23 13:45:00  116110.0  116160.0  116000.0  116070.0   7500       0
2020-10-23 14:00:00  116050.0  116150.0  115990.0  116040.0   3929       0
2020-10-23 14:15:00  116030.0  116040.0  115700.0  115780.0  14745       0
2020-10-23 14:30:00  115780.0  116090.0  115750.0  116080.0  10776       0

根据实验,我发现如果“skiprows”在 1-4 之间,它会找到 HAMMER

为什么?

P.S。原始数据为 here

这是因为 CDLHAMMER 试图检测蜡烛是否具有短实体。它是 is hardcodedreal body is short when it's shorter than the average of the 10 previous candles' real bodies 的定义。因此它无法检测到前 10 行中的任何内容,并且通过跳过行,您将感兴趣的行移动到离数据集开头太近的位置。