Nothing
###############################################################################################
##### Download data from Federal Reserve Bank of St. Louis
###############################################################################################
#' @name xd.fred
#' @aliases xd.fred
#' @title Download data from Federal Reserve Bank of St. Louis
#' @description This function returns a data from the Federal Reserve Bank of St. Louis database. It can take one ticker or a string of tickers, which will output a merged data frame with all observations.
#' @usage xd.fred(tkr, start_date, end_date)
#' @param tkr :one data ticker or a string of tickers used by the database
#' @param start_date :starting date of the data(default is set as 1900-01-01)
#' @param end_date :ending date of the data(default is set as 2018-01-01)
#' @examples
#' cpi <- xd.fred("CPIAUCSL") # CPI data
#' head(cpi)
#' tail(cpi)
#'
#' #Frequently used tickers:
#' #CPIAUCSL: Consumer Price Index for All Urban Consumers: All Items
#' #A191RL1Q225SBEA: Real Gross Domestic Product
#' #DGS10: 10-Year Treasury Constant Maturity Rate
#' #UNRATE: Civilian Unemployment Rate
xd.fred <- function(tkr, start_date = "1900-01-01", end_date = "2018-01-01"){
# when there is only one ticker
if(length(tkr) == 1){
url <- paste0("https://fred.stlouisfed.org/graph/fredgraph.csv?chart_type=line&recession_bars=on&log_scales=&bgcolor=%23e1e9f0&graph_bgcolor=%23ffffff&fo=Open+Sans&ts=12&tts=12&txtcolor=%23444444&show_legend=yes&show_axis_titles=yes&drp=0&cosd=",start_date,"&coed=",end_date,"&height=450&stacking=&range=&mode=fred&id=",tkr[1],"&transformation=lin&nd=1947-01-01&ost=-99999&oet=99999&lsv=&lev=&mma=0&fml=a&fgst=lin&fgsnd=2009-06-01&fq=Monthly&fam=avg&vintage_date=&revision_date=&line_color=%234572a7&line_style=solid&lw=2&scale=left&mark_type=none&mw=2&width=1168")
df <- read.csv(url)
# when there are multiple tickers
}else{
# create the first data frame to be merged with
url <- paste0("https://fred.stlouisfed.org/graph/fredgraph.csv?chart_type=line&recession_bars=on&log_scales=&bgcolor=%23e1e9f0&graph_bgcolor=%23ffffff&fo=Open+Sans&ts=12&tts=12&txtcolor=%23444444&show_legend=yes&show_axis_titles=yes&drp=0&cosd=",start_date,"&coed=",end_date,"&height=450&stacking=&range=&mode=fred&id=",tkr[1],"&transformation=lin&nd=1947-01-01&ost=-99999&oet=99999&lsv=&lev=&mma=0&fml=a&fgst=lin&fgsnd=2009-06-01&fq=Monthly&fam=avg&vintage_date=&revision_date=&line_color=%234572a7&line_style=solid&lw=2&scale=left&mark_type=none&mw=2&width=1168")
df <- read.csv(url)
for (i in 2:length(tkr)) {
url <- paste0("https://fred.stlouisfed.org/graph/fredgraph.csv?chart_type=line&recession_bars=on&log_scales=&bgcolor=%23e1e9f0&graph_bgcolor=%23ffffff&fo=Open+Sans&ts=12&tts=12&txtcolor=%23444444&show_legend=yes&show_axis_titles=yes&drp=0&cosd=",start_date,"&coed=",end_date,"&height=450&stacking=&range=&mode=fred&id=",tkr[i],"&transformation=lin&nd=1947-01-01&ost=-99999&oet=99999&lsv=&lev=&mma=0&fml=a&fgst=lin&fgsnd=2009-06-01&fq=Monthly&fam=avg&vintage_date=&revision_date=&line_color=%234572a7&line_style=solid&lw=2&scale=left&mark_type=none&mw=2&width=1168")
new <- read.csv(url)
# merge with all obervations
df <- merge(df, new, all = TRUE)
}
}
return(df)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.