0

所以我正在尝试使用 yfinance api(使用亚马逊股票代码)预测股票,我认为它工作正常,我唯一的问题是在 matplotlib 中绘制它。每当我尝试使用预测均值绘制收盘价时,它确实将它与当前价格前面的预测一起绘制,正如您所期望的那样,这两个图位于两个不同的位置。我的情节

这是代码:

import yfinance as yf
ticker = yf.Ticker("AMZN")
history = ticker.history(period="max")
import matplotlib.pyplot as plt
import statsmodels.api as sm
model=sm.tsa.statespace.SARIMAX(history['Close'],order=(1, 1, 1),seasonal_order=(1,1,1,12))
results=model.fit()
prediction = results.get_forecast(steps=12)
pred_ci = prediction.conf_int()
ax = history['Close'].plot(label='observed', figsize=(14, 4))
prediction.predicted_mean.plot(ax=ax, label='Forecast')
ax.fill_between(pred_ci.index,
                pred_ci.iloc[:, 0],
                pred_ci.iloc[:, 1], color='k', alpha=.25)
plt.legend()
plt.show()
4

0 回答 0