Giter Club home page Giter Club logo

federal's Introduction

Federal Package

This is a simple package built on top of Pandas-Datareader to make it easer to pull in Federal Reserve Data from the Federal Reserve in St. Louis (FRED).

Installation

pip install Federal

Basic Usage:

# Import the GDP and DateFormatter Modules
from Federal.Econ import GDP
from Federal.Formatter import DateFormatter

#Insatiate the GDP and DateFormatter Objects
g = GDP()
d = DateFormatter()

#Set your Start & End Dates
d.start_date(1900,1,1)
d.end_date(2018,1,1)

# Make the Call
df = g.metro_gdp(name='Houston')
df.head()

Setting Start & End Dates

Once imported, you declare the start date and end date via the DateFormatter.start_date() and DateFormatter.end_date() functions. These functions define the range of dates for the data that you are for. Once declared these values will be applied to each query unless explicitly changed.

There are several different DateTime format variants that the DateFormatter.start_date() and DateFormatter.end_date() functions accept:

  1. DateTime format: (Year, Month, Day): Integer
# Import the DateFormatter Modules
from Federal.Formatter import DateFormatter

#Insatiate the DateFormatter Object
d = DateFormatter()

d.start_date(1900,1,1)
d.end_date(2018,1,1)
  1. DateTime format: (Day/Month/Year): String
# Import the DateFormatter Modules
from Federal.Formatter import DateFormatter

#Insatiate the DateFormatter Object
d = DateFormatter()

d.start_date('1/1/1900')
d.end_date('1/1/2018')
  1. DateTime format: (Day-Month-Year): String
# Import the DateFormatter Modules
from Federal.Formatter import DateFormatter

#Insatiate the DateFormatter Object
d = DateFormatter()

d.start_date('1-1-1900')
d.end_date('1-1-2018')
  1. DateTime format: (Day.Month.Year): String
# Import the DateFormatter Modules
from Federal.Formatter import DateFormatter

#Insatiate the DateFormatter Object
d = DateFormatter()

d.start_date('1.1.1900')
d.end_date('1.1.2018')
  1. DateTime format: (Month/Day/Year): String
# Import the DateFormatter Modules
from Federal.Formatter import DateFormatter

#Insatiate the DateFormatter Object
d = DateFormatter()

d.start_date('14/1/1900')
d.end_date('16/1/2018')

National Gross Domestic Product (GDP)

After instantiating a FRED object, and defining the start and end dates using the GDP.start_date() and GDP.end_date() functions you can use the function GDP.national_gdp() depending on its parameters to return either nominal GDP or real GDP.

# Import the GDP and DateFormatter Modules
from Federal.Econ import GDP
from Federal.Formatter import DateFormatter

#Insatiate the GDP and DateFormatter Objects
g = GDP()
d = DateFormatter()

#Set Dates
d.start_date('1/1/1900')
d.end_date('1/1/2018')

# Real GDP
df = g.national_gdp()
df.head()

# Nominal GDP
df = g.national_gdp(nominal=True)
df.head()

State Gross Domestic Product (GSP)

Similar to the GDP.national_gdp() after making the necessary calls you can pull in information around State-Level GDP using the GDP.state_gdp() function. It requires one argument, which is the two-character string representing the state of interest. In the case below we pull the state GDP for Indiana.

# Import the GDP and DateFormatter Modules
from Federal.Econ import GDP
from Federal.Formatter import DateFormatter

#Insatiate the GDP and DateFormatter Objects
g = GDP()
d = DateFormatter()

#Set the Dates
d.start_date('1/1/1900')
d.end_date('1/1/2018')

# State GDP
df = g.state_gdp('IN')
df.head()

Metropolitan Gross Domestic Product (GMP)

The final variation of GDP that the FRED module pulls in is Metropolitan-Level GDP. The Federal Reserve uses Core-Based Statistical Area (CBSA) Codes to define each metro within their API. Here using the GDP.metro_gdp() function you can either pass the CBSA code or a name of a metro area as arguments within the function. Beyond this, similar to national GDP, by passing GDP.metro_gdp(name='<Any Metro Name>',nominal=True) with nominal equal to True, the function will return the nominal metro GDP.

# Import the GDP and DateFormatter Modules
from Federal.Econ import GDP
from Federal.Formatter import DateFormatter

#Insatiate the GDP and DateFormatter Objects
g = GDP()
d = DateFormatter()

#Set the Dates
d.start_date('1/1/1900')
d.end_date('1/1/2018')

# Metropolitan GDP - Passing the City Name as an argument
df = g.metro_gdp(name='Houston')
df.head()

# Metropolitan GDP - Passing the CBSA code as an argument
df = g.metro_gdp(cbsa=26420)
df.head()

# Metropolitan GDP - nominal
df = g.metro_gdp(cbsa=26420, nominal=True)
df.head()

# Metropolitan GDP - nominal
df = g.metro_gdp(name='Houston', nominal=True)
df.head()

National Unemployment

Unemployment is defined by the Unemployment.national_unemp() function. This function takes an argument sa which returns either seasonally-adjusted non seasonally-adjusted unemployment.

# Import the GDP and DateFormatter Modules
from Federal.Econ import Unemployment
from Federal.Formatter import DateFormatter

#Insatiate the GDP and DateFormatter Objects
u = Unemployment()
d = DateFormatter()

#Set the Dates
d.start_date('1/1/1900')
d.end_date('1/1/2018')

# Seasonally-Adjusted National Unemployment
df = u.national_unemp(sa=True)
df.head()

# Non Seasonally-Adjusted National Unemployment
df = u.national_unemp(sa=False)
df.head()

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.