Get startedGet started for free

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.

This exercise is part of the course

Importing and Managing Financial Data in R

View Course

Exercise instructions

  • Use to.period() to convert intraday_xts into a 5-second price series called xts_5sec.
  • Use to.period() to convert intraday_xts into a 10-minute price series called xts_10min.
  • Use to.period() to convert intraday_xts into a 1-hour price series called xts_1hour.

Hands-on interactive exercise

Have a go at this exercise by completing this sample 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 = ___)
Edit and Run Code