The Federal Reserve produces and maintains an amazing resource called FRED: the Federal Reserve Economic Database. I find it useful to maintain a cached RData file with my favourite FRED data. Then I use two functions: update_fred() and get_fred(). These depend on the quantmod and zoo libraries. In case you find this useful here they are:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
library(quantmod) library(zoo) update_fred <- function(start="1950-01-01",cacheFile="/home/ramin/fred.RData") { library(quantmod) identifiers <- c("DFF","DFEDTAR","CPIAUCSL","UNRATE","USRECD","TREAST" ,"MBST","GDP","UMCSENT","CSCICP02USM661S","PAYEMS" ,"SPCS20RSA","HOSINVUSA495N","HSN1F","PERMIT","BSCICP02USM460S" ,"CSCICP03USM665S","EVANQ","USSLIND","DGS10","FEDFUNDS","M08297USM548NNBR","M06006USM156NNBR" ,"AWHMAN","NEWORDER","TWEXB","M2","SP500","NAPM" ,"ACDGNO","NEWORDER","BAA" ) fred <- as.zoo(getSymbols(identifiers[1],src='FRED', auto.assign=FALSE)) for (i in 2:length(identifiers)) { fred <- merge(fred,as.zoo(getSymbols(identifiers[i],src='FRED', auto.assign=FALSE))) } save(fred,file=cacheFile) |
And to simply read in the fred object into the workspace I use the following:
1 2 3 4 |
get_fred <- function(cacheFile="/home/ramin/fred.RData") { load(file=cacheFile) return(fred) } |