TAStatistics
TA.LINEARREG_INTERCEPT() - 线性回归截距
Linear Regression Intercept,计算线性回归线的Y轴截距。
语法
python
TA.LINEARREG_INTERCEPT(data)
TA.LINEARREG_INTERCEPT(data, timeperiod=14)参数
| 参数 | 类型 | 说明 | 默认值 |
|---|---|---|---|
| data | array | 价格数据 | - |
| timeperiod | int | 回归周期 | 14 |
返回值
返回线性回归截距数组(回归线在Y轴的起始值)。
计算方法
plaintext
y = a + b×x
intercept = a = mean(y) - slope × mean(x)基础示例
python
def main():
records = exchange.GetRecords()
closes = [r['Close'] for r in records]
intercept = TA.LINEARREG_INTERCEPT(closes, 14)
slope = TA.LINEARREG_SLOPE(closes, 14)
# 预测未来价格
future_price = intercept[-1] + slope[-1] * 15
Log(f"预测下一周期价格: {future_price:.2f}")