此外,我现在的问题是,如果我想回归两个数组,例如,不相等的和无序的。
x = np.array([0.1, 0.5, 2.0, 1.6, 2.8, 3.5, 0.9, 1.5])
y = np.array([0.22, 1.21, 4.19, 3.39, 5.85, 7.21, 2.0, 3.2])
我应该做什么使用LINEARREG函数在talib?
感谢truf指出c代码链接,LINEARREG只处理euqal距离x-数组,并且只通过输入y-数组(这里的收盘价)回归。
y = array([ 2., 4., 6., 8., 10., 12., 14., 16.])
tb.LINEARREG_INTERCEPT(y,5)
>>> array([nan, nan, nan, nan, 2., 4., 6., 8.])
tb.LINEARREG_SLOPE(y,5)
>>> array([nan, nan, nan, nan, 2., 2., 2., 2.])
还应该注意,输入numpy数组需要类型检查。
dtype=np.float
以匹配c中的“双”。
原始问题
我使用TA来计算技术指标,但是我不理解LINEARREG函数,其中只有一个输入数组(称为close价格),通常进行线性回归,我们需要两个数组x和y来回归,例如,我们希望在返回时恢复关闭价格。
real = LINEARREG(close,timeperiod=14)
发布于 2019-01-24 14:15:06
最好检查这个函数的ta-lib代码:LINEARREG.c#l238
它载有以下解释:
/* Linear Regression is a concept also known as the
* "least squares method" or "best fit." Linear
* Regression attempts to fit a straight line between
* several data points in such a way that distance
* between each data point and the line is minimized.
*
* For each point, a straight line over the specified
* previous bar period is determined in terms
* of y = b + m*x:
*
* TA_LINEARREG : Returns b+m*(period-1)
* TA_LINEARREG_SLOPE : Returns 'm'
* TA_LINEARREG_ANGLE : Returns 'm' in degree.
* TA_LINEARREG_INTERCEPT: Returns 'b'
* TA_TSF : Returns b+m*(period)
*/
看来您的收盘价将被视为y数组,x将是天号数组1.14。TA_LINEARREG_SLOPE、TA_LINEARREG_ANGLE、TA_LINEARREG_INTERCEPT和TA_TSF是其他基于TA_LINEARREG的ta-lib函数.
https://stackoverflow.com/questions/54319318
复制相似问题