汇总不规则的日内数据
日内数据体量很大:每天可能有数十万条观测,每月上百万,每年上亿。在开始分析之前,通常需要先对这些数据做汇总。
您已在《xts 与 zoo 入门》课程中学习过如何汇总日度数据。本练习将使用 to.period() 将日内数据聚合为 OHLC 序列。汇总日内数据时,通常需要同时指定 period 和 k 参数。
intraday_xts 对象包含一个交易日的随机数据。
本练习是课程的一部分
在 R 中导入与管理金融数据
练习说明
- 使用
to.period()将intraday_xts转换为 5 秒价格序列,命名为xts_5sec。 - 使用
to.period()将intraday_xts转换为 10 分钟价格序列,命名为xts_10min。 - 使用
to.period()将intraday_xts转换为 1 小时价格序列,命名为xts_1hour。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Convert raw prices to 5-second prices
xts_5sec <- to.period(intraday_xts, period = "___", k = ___)
# Convert raw prices to 10-minute prices
xts_10min <-
# Convert raw prices to 1-hour prices
xts_1hour <- to.period(___, period = "___", k = ___)