开发者

Calculating a 12-month moving average of weekly series, but anchored at the last day of the month

I have a zoo object oi.zoo with weekly data. I would like to sooth this with a 12-month moving average (easy enough), but I can't figure out how to anchor the right edge of the the moving average window at the end of the month (to correspond with the on which factors I am regressing). For example:

> head(oi.zoo)
1986-01-15 1986-01-31 1986-02-14 1986-02-28 1986-03-14 1986-03-31 
   2966182    2986748    2948045    2990979    2993453    2936038 
> head(mkt)
1926-07-31 1926-08-31 1926-09-30 1926-10-31 1926-11-30 1926-12开发者_如何学运维-31 
      2.62       2.56       0.36      -3.43       2.44       2.77

I have some other factors and plan on using dynlm to regress.

Thanks!


oi.zoo.monthly <- aggregate(oi.zoo,yearmon,sum)
oi.zoo.ma <- 0.5 * rollapply(oi.zoo.monthly,12,mean,align="right")
mkt.mo <-aggregate(mkt,yearmon,identity)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜