简体   繁体   English

组/存储桶上的EWMA

[英]EWMA on group / bucket of data

I have a time series vector I need to create a trend off of. 我需要一个时间序列向量来创建趋势。

I was trying to get the EMA function in R (through the TTR package - I am loading quantmod, and TTR is required) to run over a group of prices. 我试图在R中获得EMA函数(通过TTR包-我正在加载quantmod,并且需要TTR)来运行一组价格。

Is there a way to create an EMA estimate over a given amount of rows in the vector, so I have one EMA estimate for each bucket? 有没有一种方法可以针对向量中给定的行数创建EMA估算,因此每个存储区都有一个EMA估算? Say I have a bucket size of 10 and I would like to estimate the trend between each bucket, just choosing open and close for the bucket negates a large amount of info, so I would like to have an estimate over the bucket, but with just one output. 假设我的存储桶大小为10,我想估计每个存储桶之间的趋势,只为该存储桶选择打开和关闭将否定大量信息,因此我想对存储桶进行估算,但是一个输出。

Alteratively I tried averaging over the bucket length, but this doesn't produce the desired output. 或者,我尝试对存储段长度进行平均,但这无法产生所需的输出。

Example of the vector I am using 我正在使用的向量的示例

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)
bucketsize=10

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

aggregate(price,list(bucket),mean)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM