和c++语法的虚函数有些相似,有相同的函数接口和函数名称,但是产生不同的行为
import numpy as np
# 注意所有ndarrays必须长度相同
inputs = {
'open': np.random.random(100),
'high': np.random.random(100),
'low': np.random.random(100),
'close': np.random.random(100),
'volume': np.random.random(100)
}
函数可以直接导入或者通过名字导入
from talib import abstract
sma = abstract.SMA
sma = abstract.Function('sma')
通过虚函数调用函数
from talib.abstract import *
output = SMA(input_arrays, timeperiod=25) # calculate on close prices by default
output = SMA(input_arrays, timeperiod=25, price='open') # calculate on opens
upper, middle, lower = BBANDS(input_arrays, 20, 2, 2)
slowk, slowd = STOCH(input_arrays, 5, 3, 0, 3, 0) # uses high, low, close by default
slowk, slowd = STOCH(input_arrays, 5, 3, 0, 3, 0, prices=['high', 'low', 'open'])