Aggregate irregular intra-day data
Intraday data can be huge, with hundreds of thousands of observations per day, millions per month, and hundreds of millions per year. These datasets often need to be aggregated before you can work with them.
You learned how to aggregate daily data in the Introduction to xts and zoo course. This exercise will use to.period() to aggregate intraday data to an OHLC series. You often need to specify both period and k arguments to aggregate intraday data.
The intraday_xts object contains one trading day of random data.
Cet exercice fait partie du cours
Importing and Managing Financial Data in R
Instructions
- Use
to.period()to convertintraday_xtsinto a 5-second price series calledxts_5sec. - Use
to.period()to convertintraday_xtsinto a 10-minute price series calledxts_10min. - Use
to.period()to convertintraday_xtsinto a 1-hour price series calledxts_1hour.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# 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 = ___)