LoslegenKostenlos loslegen

Aggregate daily data and merge with monthly data

Sometimes two series have the same periodicity, but represent timestamps differently. For example, monthly series may be timestamped with the first or last date of the month. This difference creates many NA when series are merged. The yearmon class from the zoo package helps solve this problem.

In this exercise, you will aggregate the FRED daily Fed Funds rate (DFF) to a monthly periodicity and merge it with the FRED monthly Fed Funds rate (FEDFUNDS).The DFF aggregate will be timestamped with the last day of the month, while FEDFUNDS is timestamped with the first day of the month.

The FEDFUNDS and DFF data have already been downloaded from FRED for you, using getSymbols(c("FEDFUNDS", "DFF"), src = "FRED").

Diese Übung ist Teil des Kurses

Importing and Managing Financial Data in R

Kurs anzeigen

Anleitung zur Übung

  • Use apply.monthly() with mean() to calculate the average of all days for each month. Assign the result to monthly_fedfunds.
  • Finish the command to use as.yearmon() to convert the index to yearmon.
  • Create an object named merged_fedfunds by merging FEDFUNDS with the monthly aggregate you created in the first step.
  • Use head() to check the output of merged_fedfunds.

Interaktive Übung

Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.

# Aggregate DFF to monthly averages


# Convert index to yearmon
index(___) <- ___(index(___))


# Merge FEDFUNDS with the monthly aggregate


# Look at the first few rows of the merged object
Code bearbeiten und ausführen