Session Ready
Exercise

Make irregular intra-day data regular

Earlier you learned how to create a regular daily series from irregular daily data. Now you will create regular intra-day data from an irregular series.

Intra-day financial data often does not span a full 24 hours. Most markets are usually closed part of the day. This exercise assumes markets open at 9AM and close at 4PM Monday-Friday.

Your data may not have an observation exactly at the market open and/or close. So, you would not be able to use start() and end() as you could with the daily data. You need to specify the start and end date-times to create this regular sequence.

The regular date-time sequence will include periods when markets are closed, but you can use xts' time-of-day subsetting to extract only the periods the market is open.

Instructions
100 XP
  • Finish the command to create a regular 30-minute date-time sequence between 09:00 Monday and 16:00 Friday.
  • Set the values for x and order.by to create a zero-width xts object.
  • Create merged_xts by merging irregular_xts and regular_xts. Use the fill argument to replace NA with their previous value using na.locf().
  • Use xts' time-of-day subsetting to extract observations between 9AM and 4PM every day. Assign the result to trade_day.