FRED

import os
import pandas as pd
import seaborn as sns
from full_fred.fred import Fred

# FRED_API_KEY = os.getenv('FRED_API_KEY')
fred = Fred()
print(f"FRED API key is set to an environment variable: {fred.env_api_key_found()}")


def get_fred_data(name, start="2013-01-01", end=""):
    df = fred.get_series_df(name)[["date", "value"]].copy()
    df["date"] = pd.to_datetime(df["date"])
    df["value"] = pd.to_numeric(df["value"], errors="coerce")
    df = df.set_index("date")

    if end == "":
        df = df.loc[f"{start}":]
    else:
        df = df.loc[f"{start}":f"{end}"]

    return df
FRED API key is set to an environment variable:True

Unemployment Rate

Original source:https://fred.stlouisfed.org/series/UNRATE

df_UNRATE = get_fred_data("UNRATE", start="2010-01-01")
df_UNRATE.head(5)

value
date
2010-01-019.8
2010-02-019.8
2010-03-019.9
2010-04-019.9
2010-05-019.6
sns.set(rc={"figure.figsize": (15, 8)})
sns.lineplot(data=df_UNRATE, x="date", y="value")

png

ICE BofA US High Yield Index Option-Adjusted Spread

Source of data:https://fred.stlouisfed.org/series/BAMLH0A0HYM2

df_BAMLH0A0HYM2 = get_fred_data("BAMLH0A0HYM2", start="2010-01-01")
df_BAMLH0A0HYM2.head(5)

value
date
2010-01-01NaN
2010-01-046.34
2010-01-056.30
2010-01-066.17
2010-01-076.03

Wilshire US Large-Cap Growth Total Market Index

Source of data:https://fred.stlouisfed.org/series/WILLLRGCAPGR

df_WILLLRGCAPGR = get_fred_data("WILLLRGCAPGR", start="2010-01-01")
df_WILLLRGCAPGR.head(5)

value
date
2010-01-01NaN
2010-01-0426423.03
2010-01-0526494.24
2010-01-0626473.92
2010-01-0726512.36
sns.set(rc={"figure.figsize": (15, 8)})
sns.lineplot(data=df_WILLLRGCAPGR, x="date", y="value")
sns.lineplot(data=df_BAMLH0A0HYM2 * 10000, x="date", y="value")

png

Comments

(Comments will appear after approval)