【发布时间】:2020-05-18 23:37:50
【问题描述】:
我正在尝试使用高频包中的 spotvol 函数计算大型股票数据集的每日已实现/历史波动率。出于某种原因,我不断收到 POSIX(时间戳)错误,我尝试了多种不同的方法将我的样本转换为 xts 对象。
数据集的样本:
2015-01-02 10:00:00 80.15
2015-01-02 11:00:00 81.00
2015-01-02 12:00:00 80.50
2015-01-02 13:00:00 80.40
2015-01-02 14:00:00 80.15
2015-01-02 15:00:00 81.00
2015-01-02 16:00:00 80.50
2015-01-05 10:00:00 80.40
2015-01-05 11:00:00 80.95
2015-01-05 12:00:00 81.05
2015-01-05 13:00:00 80.85
2015-01-05 14:00:00 80.50
2015-01-05 15:00:00 80.40
2015-01-05 16:00:00 80.95
我用来转换成xts对象的代码如下:
vol_df2 <- vol_df1 %>%
mutate(time_stamp = as.POSIXct(time_stamp, format = "%Y-%m-%d %H:%M:%S"))
vol_df3 <- as.xts(vol_df2, order.by = vol_df2$time_stamp, tz = "", unique = F)
尝试从1小时时间段计算每日spotvol的代码如下: 注意:我的实际数据属于高频性质,因此我提供了 2 天内每小时的汇总数据。
spotvol(vol_df3, method = "detper", on = "hours", k = 1,
marketopen = "10:00:00", marketclose = "16:00:00")
我得到的错误如下:
Error in as.POSIXlt.character(x, tz, ...):
character string is not in a standard unambiguous format
do not know how to convert 'time' to class “POSIXct”
In addition: Warning messages:
1: All formats failed to parse. No formats found.
2: All formats failed to parse. No formats found.
3: In min.default(numeric(0), na.rm = FALSE) :
no non-missing arguments to min; returning Inf
4: In max.default(numeric(0), na.rm = FALSE) :
no non-missing arguments to max; returning -Inf
5: All formats failed to parse. No formats found.
和
Error in set(x, j = name, value = value) :
Supplied 1054304 items to be assigned to 1054377 items of column
'PRICE'. If you wish to 'recycle' the RHS please use rep() to make this
intent clear to readers of your code.
到目前为止,我所做的研究一无所获,因为我只是按照说明转换我的时间戳并转换为 xts 对象。 当我运行 Linux 系统时,我遇到了这个问题: https://github.com/Rdatatable/data.table/issues/1619
我也尝试过使用 data.table 方法,这也会产生关于 POSIX 时间戳的明确格式的错误。
就像我在 spotvol 的命令中缺少参数,但是,我无法确定是否有可以从此处找到的文档中更改的默认值:https://www.rdocumentation.org/packages/highfrequency/versions/0.6.3/topics/spotvol
编辑:我现在收到的唯一错误是列表中关于设置中的错误的最后一个错误...当我将 @987654332 的 aggregatePrice 部分中的 fill=TRUE 更改为 fill=FALSE 时@函数spotvol似乎想计算一下,但仍然抛出Error in set错误。
对此的任何帮助将不胜感激。 干杯:)
【问题讨论】:
标签: r timestamp time-series xts