【发布时间】:2015-07-09 18:04:45
【问题描述】:
我在名为price_data 的数据框中有来自雅虎财经的每日股价数据。
我想为此添加一列,它提供来自 Adj Close 列的时间序列趋势的拟合值。
这是我正在使用的数据结构:
In [41]: type(price_data)
Out[41]: pandas.core.frame.DataFrame
In [42]: list(price_data.columns.values)
Out[42]: ['Open', 'High', 'Low', 'Close', 'Volume', 'Adj Close']
In [45]: type(price_data.index)
Out[45]: pandas.tseries.index.DatetimeIndex
在 Python 语言中实现这一目标的最佳方式是什么?
顺便说一句,以下是用 R 语言实现的
all_time_fitted <- function(data)
{
all_time_model <- lm(Adj.Close ~ Date, data=data)
fitted_value <- predict(all_time_model)
return(fitted_value)
}
这里是一些示例数据:
In [3]: price_data
Out[3]:
Open High Low Close Volume Adj Close
Date
2005-09-27 21.05 21.40 19.10 19.30 961200 19.16418
2005-09-28 19.30 20.53 19.20 20.50 5747900 20.35573
2005-09-29 20.40 20.58 20.10 20.21 1078200 20.06777
2005-09-30 20.26 21.05 20.18 21.01 3123300 20.86214
2005-10-03 20.90 21.75 20.90 21.50 1057900 21.34869
2005-10-04 21.44 22.50 21.44 22.16 1768800 22.00405
2005-10-05 22.10 22.31 21.75 22.20 904300 22.04377
【问题讨论】:
-
您能添加一些输入数据的样本吗?
-
向问题添加示例数据
-
而且,这可能很愚蠢,但是“拟合值”是什么意思?
-
对于给定的 x (Date) 值,模型计算的 y (Adj Close) 的预期值。这是参考businessdictionary.com/definition/fitted-value.html
标签: python pandas time-series statsmodels trend