2013-10-11 40 views
1
打开和关闭一周中旬每周

酒吧我可以每天一系列转换为每周如下:[R Quantmod:与

library(quantmod) 
getSymbols("SPY", from="2013-01-01", to=Sys.Date()) 
chartSeries(SPY) 
datW <- to.weekly(SPY) 

但该系列创建每周酒吧与上周五关闭。 如何更改此选项以创建周中的酒吧,以便每周酒吧在周三显示关闭?

谢谢您的帮助。

回答

1

它看起来不像有任何简单的方法来做到这一点。如果你看一下源to.period它基本上围绕外部调用换到.toPeriod并向它传递 endpoints(x, period, k)

xx <- .Call("toPeriod", x, endpoints(x, period, k), has.Vo(x), 
     has.Vo(x, which = TRUE), has.Ad(x) && is.OHLC(x), 
     index_at, cnames, PACKAGE = "xts") 

endpoints功能也适用外部调用。所以如果你每周的周末都会在星期三结束,看起来你要么必须自己编码,要么寻找一些不同的库。

作为一个起点,这是很容易找到在星期三发生的数据行,像这样:

> wednesdayRows<-which(as.POSIXlt(index(SPY))$wday==3) 
> head(SPY[wednesdayRows,]) 
      SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted 
2013-01-02 145.11 146.15 144.73 146.06 192059000  143.95 
2013-01-09 145.87 146.32 145.64 145.92 90745600  143.81 
2013-01-16 146.77 147.28 146.61 147.05 104849500  144.92 
2013-01-23 149.13 149.50 148.86 149.37 104596100  147.21 
2013-01-30 150.64 150.94 149.93 150.07 137447700  147.90 
2013-02-06 150.52 151.26 150.41 151.16 138762800  148.97 

所以,现在你只需要正确汇集OHLC数据。

+0

谢谢你的帮助。 –