Code Monkey home page Code Monkey logo

fredr's Introduction

#FredR: R Interface to the Federal Reserve Economic Data API Travis-CI Build Status Coverage Status

This package provides an interface to the Federal Reserve Economic Data (FRED) API. FRED covers 240,000 US and international macroeconomic time series from 77 sources (including the World Bank, OECD, and BIS).

FredR has been designed in a way that gives a user a complete interface to all available functionalities of the API. Currently, the package is still poorly documented (improving on this will be the next step). However, the naming conventions used in the package map one-to-one to the official API calls, so one can for now use the official API documentation (available here) to see the meaning of particular functions and parameters.

##Installation FredR is currently only available on Github, so you will need Hadley's devtools in order to install it:

devtools::install_github(jcizel/FredR)

Quick Demonstration

In order to use the API, you first need to create an account here: http://api.stlouisfed.org/api_key.html. Once you have the account, copy-paste your API key and supply it is a string argument to FredR function, like so:

api.key = '...'  # substitute ... with your API key

Next, you need to initialize FredR:

fred <- FredR(api.key)

Call to FredR generates a list of functions each of which performs a specific type of query to the API. Each functions returns a data.table object containing the result of the query.

Let's view all the available functions in FredR:

str(fred,1)

Ok, let's get to work. Say, that we want to find all series, whose name contains a string 'GDP':

gdp.series <- fred$series.search("GDP")

gdp is now a data.table containing all available GDP series and their properties.

To see which one to use for further analysis, one can dig deeper:

library(pipeR)
library(dplyr)

gdp.series %>>%
select(
    id,
    title,
    observation_start,
    observation_end,
    popularity
) %>>%
arrange(
    desc(as.numeric(popularity))
)

Let's say that we decide to download the time series data for the series with id = 'GDPC1' (Real Gross Domestic Product in the U.S.):

gdp <- fred$series.observations(series_id = 'GDPC1')

Plot the result:

gdp %>>%
select(
    date,
    value
) %>>%
mutate(
    date = as.Date(date),
    value = as.numeric(value)
) ->
    dt

require(ggplot2)
qplot(data = dt, x = date, y = value, geom = 'line')

fredr's People

Contributors

jcizel avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.