【发布时间】:2016-07-07 18:38:16
【问题描述】:
我想将 xts 对象的每日值更改为每月到期的 OHLCV 数据。我想我可以使用quantmod::options.expiry 这样做...
library("quantmod")
# get SPX daily values
SPX <- getSymbols("^GSPC",from="2016-01-01",auto.assign=FALSE)
# option expiration rows/dates using options.expiry()
spx_expiry <- SPX[options.expiry(SPX),]
# spx_expiry will only return the closing values for option expiration **day**
# it is missing the OHLCV data in between expiration months.
# The Close/Adjusted columns are correct but the Open, High, Low, Volumes
# columns are incorrect.
# Here is what I have tried:
period.apply(SPX,INDEX=options.expiry(SPX),FUN=function(x) to.monthly(x,indexAt='firstof'))
【问题讨论】: