我有一个时间序列向量,我需要创建一个趋势。
我试图在R中获取EMA功能(通过TTR包 - 我正在加载quantmod,并且需要TTR)来运行一组价格。
有没有办法在向量中的给定行数上创建EMA估计值,因此每个桶有一个EMA估计值?假设我的桶大小为10,我想估计每个桶之间的趋势,只需选择打开和关闭桶即可消除大量信息,所以我想估算一下桶,但只是一个输出。
另外,我尝试对铲斗长度求平均值,但这不会产生所需的输出。
我正在使用的载体示例
dput(head(price, 200))
c(137, 137, 137, 137, 137, 137, 137, 137, 137, 136.9, 136.9,
136.9, 137, 137, 137, 137, 137, 137.2, 137.2, 137.2, 137.1, 137.4,
137.4, 137.4, 137.4, 137.4, 137.4, 137.1, 137, 137, 137, 137,
137, 136.9, 136.9, 136.9, 136.9, 136.9, 136.7, 137, 137, 137,
137, 136.7, 136.9, 136.9, 136.9, 136.5, 136.5, 136.9, 136.9,
136.9, 137, 137, 137.3, 136.7, 137, 137, 137, 137.1, 137, 137,
137.1, 137.1, 137, 137, 137.1, 137, 137, 136.8, 137, 137, 136.9,
136.8, 136.7, 137.1, 137, 137, 137.1, 137, 137.1, 137.1, 136.7,
136.7, 136.7, 136.7, 136.7, 136.8, 137, 137, 137, 136.9, 136.9,
136.9, 136.9, 136.9, 136.9, 136.9, 136.9, 136.9, 136.9, 136.9,
136.9, 136.9, 137, 136.9, 136.9, 136.9, 136.9, 136.9, 136.8,
136.8, 136.9, 136.9, 136.9, 136.9, 137, 136.9, 136.9, 136.9,
136.9, 136.9, 136.9, 137, 137, 137, 137, 137, 137, 137, 136.9,
136.9, 136.9, 137, 137, 136.9, 137, 137.1, 137.1, 137.1, 137,
137.2, 137.2, 137.2, 137.2, 137.2, 137.2, 137.1, 137.1, 136.9,
136.8, 136.9, 136.9, 136.9, 136.9, 136.9, 137, 136.9, 137, 137,
137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 137, 136.9,
137.1, 137.1, 137.1, 137.1, 137, 137, 137.1, 137.1, 137.1, 137.1,
137.1, 137.1, 137, 137, 137, 137, 137, 137, 136.9, 136.9, 136.9,
136.9, 136.9, 136.9, 136.9, 136.9, 136.9)
答案 0 :(得分:1)
bucketsize=10
bucket=rep(1:ceiling(length(price)/bucketsize),each=bucketsize)
aggregate(price,list(bucket),mean)