How to utilize FRED datasets in pipeline?

Hi,

New to the platform, but having a hard time figuring out how to use some of the datasets, for example:

from quantopian.interactive.data.quandl import rateinf_inflation_usa # Inflation rate
from quantopian.interactive.data.quandl import fred_gnp # GNP
from quantopian.interactive.data.quandl import fred_gdp # GDP
from quantopian.interactive.data.quandl import fred_icsa # Unemployment Claims
from quantopian.interactive.data.quandl import adp_empl_sec # Total Jobs


These datasets are in the form of a Blaze expr. object. I figured out how to make them a Pandas.dataFrame, but I have no idea how to access the nearest time values (asof_date) in a CustomFactor or in the Pipeline itself.

What I would like to do is this:

For every day, look at the % change for each of the above values (GDP, GNP, etc) between the current value and the value a month ago).

Would appreciate any help on this, as I've been unable to make much progress. Thank you.

2 responses

Currently handling with an (inefficient) CustomFactor. Here I am iterating over each entry to find the closest date. Would love a more efficient approach, though.

from quantopian.interactive.data.quandl import adp_empl_sec

jobs = jobs.sort_values("asof_date")

def find_most_recent_jobs(date):
for i in range(len(jobs)):
asof_date = jobs.iloc[i].asof_date
date = date.replace(tzinfo=None)
if asof_date > date:
latest = jobs.iloc[i-1].total_private
prev = jobs.iloc[i-2].total_private
pct_change = latest / prev - 1
return pct_change

class TrainingData(CustomFactor):
inputs = []
outputs = ["jobs_change", "gnp_change", "gdp_change", "inflation_change", "unemployment_change"]
window_length = 30
def compute(self, today, assets, out):
jobs_change = find_most_recent_jobs(today)
out.jobs_change[:] = jobs_change



Hi Thomas,

Here's a notebook that gets the percent change between the last two Fred GNP values. I also put in some custom factors that get the latest GNP value as well as the latest corresponding asof_date so that you can play around with it. Note that since this is a value that updates quarterly, the percent_change will be forward filled on most days.

Also, Pipeline is limited to outputting dataframes where the result is mapped to US equities. To work with macroeconomic data, I broadcast the result across all of the assets and added a StaticAssets filter to the pipeline to just pull up GNP value and percent change each day.

Let me know if this helps.

22