我希望在股票图表上绘制Excel所称的“指数趋势/回归”图。当我在IPython笔记本中运行下面的代码时,它只是显示“内核已死亡,您要重新启动吗?”。有什么解决办法吗?此外,这仅仅是尝试进行线性回归,我不太清楚如何对指数数据进行回归。
import datetime
import matplotlib.pyplot as plt
import statsmodels.api as sm
from pandas.io.data import DataReader
sp500 = DataReader("AGG", "yahoo", start=datetime.datetime(2000, 1, 1)) # returns a DataFrame
sp500["regression"] = sm.OLS(sp500["Adj Close"], sp500.index).fit().fittedvalues()
top = plt.subplot2grid((3,1), (0, 0), rowspan=2)
top.plot(sp500.index, sp500["Adj Close"], 'b-', sp500.index, sp500["regression"], 'r-')
bottom = plt.subplot2grid((3,1), (2,0))
bottom.bar(sp500.index, sp500.Volume)
plt.gcf().set_size_inches(18,8)
ipython --pylab
时出现分段错误。 - bmu