# # Convert the WRDS yearly interest rates, reported monthly. The data set is the # WRDS Interest Rates (Federal Reserve, H15 report) # The column used is the federal funds column. # rootPath = "../data" # yearly percentage rates, reported quarterly interestFile = "monthly_interest_rates.csv" # interest reported quarterly interestOut = "quarterly_interest_rates.csv" interestPath = paste(rootPath, interestFile, sep="/") interestOutPath = paste(rootPath, interestOut, sep="/") interest.df = read.csv(interestPath) fedFundsCol = "FF_O" dateCol = "date" dates = as.Date(strptime(as.vector(as.character(interest.df[,dateCol])), format="%d%b%Y", tz="EST")) months = as.numeric(format(dates, format="%m")) ix = which(months %in% c(3, 6, 9, 12)) qtr = dates[ix] q1Ix = which(as.numeric(format(qtr, format="%m")) == 3) q1Yr = format(qtr[q1Ix], format="%Y") qtr[q1Ix] = as.Date(paste(q1Yr, "03-31", sep="-")) q2Ix = which(as.numeric(format(qtr, format="%m")) == 6) q2Yr = format(qtr[q2Ix], format="%Y") qtr[q2Ix] = as.Date(paste(q2Yr, "06-30", sep="-")) q3Ix = which(as.numeric(format(qtr, format="%m")) == 9) q3Yr = format(qtr[q3Ix], format="%Y") qtr[q3Ix] = as.Date(paste(q3Yr, "09-30", sep="-")) q4Ix = which(as.numeric(format(qtr, format="%m")) == 12) q4Yr = format(qtr[q4Ix], format="%Y") qtr[q4Ix] = as.Date(paste(q4Yr, "12-31", sep="-")) rates = interest.df[ix, fedFundsCol]/100 interestData.df = data.frame(qtr, rates) colnames(interestData.df) = c("date", "FedFunds") write.csv(x = interestData.df, file=interestOutPath, quote=F, row.names=F)