2

我有一个时间序列向量,我需要创建一个趋势。

我试图在 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)
4

1 回答 1

1
bucketsize=10

bucket=rep(1:ceiling(length(price)/bucketsize),each=bucketsize)

aggregate(price,list(bucket),mean)
于 2013-02-19T22:18:48.607 回答