Exercise

Align aggregated series with first day of month, then last day

Sometimes you may not be able to use convenience classes like yearmon to represent timestamps, like you did in the previous exercise.

This exercise will teach you how to manually align merged data to the timestamp representation you prefer. The idea is to merge the lower-frequency data with the aggregate data, then use na.locf() to fill the missing values forward (or backward, using fromLast = TRUE). Then you can subset the result of the na.locf() call using the index of the object with the representation you prefer.

Your workspace contains a monthly_fedfunds object that contains the result of apply.monthly(DFF, mean), and a merged_fedfunds object that contains the result of merge(FEDFUNDS, monthly_fedfunds) without converting the monthly_fedfunds index to yearmon first. Your workspace also contains FEDFUNDS.

Instructions

100xp

Use head() to look at the merged_fedfunds object. Note the NA values.

Use na.locf() to fill in the NA values with the value from the previous observation and assign it to an object named merged_fedfunds_locf.

Subset merged_fedfunds_locf by the index of monthly_fedfunds in order to create an xts object where the timestamps are aligned with the last day of the month. Name the resulting object aligned_last_day.

Use na.locf() and its fromLast argument to fill in the NA values with the value from the next observation and assign it to an object named merged_fedfunds_locb.

Subset merged_fedfunds_locb by the index of FEDFUNDS in order to create an xts object where the timestamps are aligned with the first day of the month. Name the object aligned_first_day.