diff --git a/gamestonk_terminal/fred/README.md b/gamestonk_terminal/fred/README.md
index 504412b7457..51b71a957fb 100644
--- a/gamestonk_terminal/fred/README.md
+++ b/gamestonk_terminal/fred/README.md
@@ -1,31 +1,41 @@
# FRED
-The purpose of fred is to have the ability to look at economic data.
+https://fred.stlouisfed.org
-* [gdp](#gdp)
- * Get GDP data
+The purpose of fred is to have the ability to look at economic data. This page offers 2 options:
+
+* [predefined](#gdp)
+ * Get predefined data
* [cust](#cust)
* Get custom fred data
-## gdp
-```text
-usage: gdp [-n N_TO_GET] [-s START_DATE] [--noplot] [--hidedata]
-```
-Gets GDP data. Data is released quarterly
-* -n : Number of points to display. If unspecified, it will display all available.
-* -s : Start Date. Format YYYY-mm-dd. First point to get. Defaults to Jan 1 2015
-* --noplot : Flag to hide plot
-* --hidedata : Flag to suppress printing output
+The current predefined options are
+* GDP
+* 1,5,10,30 Year Treasury Rates
+* 30 Year Mortgage Rates
+* Unemployment Rate
+* 3 Month LIBOR
+* Moody's AAA Corporate Bond
-To get and plot the last 20 reported GDP values:
+## predefined
+```text
+usage: selected [-n N_TO_GET] [-s START_DATE] [--noplot] [--hidedata]
+```
+Gets predefined data. Arguments
+* selected : Key from the predefined list.
+* -s : Start Date. Format YYYY-mm-dd. First point to get. Defaults to Jan 1 2019
+* --noplot : Flag to hide plot
+* --hidedata : Flag to suppress printing output. Useful for data released daily/weekly.
+
+To plot the 30-Year Mortgage rates since 2018-01-01 suppressing the output.
````
-gdp -n 20
+mort30 -s 2018-01-01 --hidedata
````
To show all GDP data since 1/1/2016, with no plot.
````
gdp -s 2016-01-01 --noplot
````
-Outputs:
+Output:
````
GDP
Date
@@ -64,41 +74,46 @@ usage: cust [-i --id] [-s START_DATE] [--noplot] [--hidedata]
* --noplot : Flag to suppress output plot.
* --hidedata : Flag to suppress data output
-An example of custom data could be the unemployment rate. According to https://fred.stlouisfed.org/series/UNRATE , the series ID is UNRATE. So to plot this for 2019 to now
+An example of custom data could be the USD/EURO exchange rate.
+According to https://fred.stlouisfed.org/series/DEXUSEU , the series ID is DEXUSEU. So to plot this from the start of February 2021 to now (3/17)
````
-cust --id UNRATE -s 2019-01-01
+cust --id UNRATE -s 2021-02-01
````
This will plot and display:
-
````
- UNRATE
-Date
-2019-01-01 4.0
-2019-02-01 3.8
-2019-03-01 3.8
-2019-04-01 3.7
-2019-05-01 3.7
-2019-06-01 3.6
-2019-07-01 3.6
-2019-08-01 3.7
-2019-09-01 3.5
-2019-10-01 3.6
-2019-11-01 3.6
-2019-12-01 3.6
-2020-01-01 3.5
-2020-02-01 3.5
-2020-03-01 4.4
-2020-04-01 14.8
-2020-05-01 13.3
-2020-06-01 11.1
-2020-07-01 10.2
-2020-08-01 8.4
-2020-09-01 7.8
-2020-10-01 6.9
-2020-11-01 6.7
-2020-12-01 6.7
-2021-01-01 6.3
-2021-02-01 6.2
-````
\ No newline at end of file
+ DEXUSEU
+Date
+2021-02-01 1.2070
+2021-02-02 1.2020
+2021-02-03 1.2025
+2021-02-04 1.1974
+2021-02-05 1.2035
+2021-02-08 1.2045
+2021-02-09 1.2106
+2021-02-10 1.2132
+2021-02-11 1.2127
+2021-02-12 1.2126
+2021-02-15 NaN
+2021-02-16 1.2107
+2021-02-17 1.2042
+2021-02-18 1.2078
+2021-02-19 1.2136
+2021-02-22 1.2155
+2021-02-23 1.2142
+2021-02-24 1.2143
+2021-02-25 1.2229
+2021-02-26 1.2093
+2021-03-01 1.2054
+2021-03-02 1.2079
+2021-03-03 1.2073
+2021-03-04 1.2045
+2021-03-05 1.1914
+2021-03-08 1.1849
+2021-03-09 1.1885
+2021-03-10 1.1900
+2021-03-11 1.1978
+````
+
+Note the NaN on 2-15, which corresponds to President's Day.
\ No newline at end of file
diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py
index e5fce3a148a..490c152c7f8 100644
--- a/gamestonk_terminal/fred/fred_api.py
+++ b/gamestonk_terminal/fred/fred_api.py
@@ -14,32 +14,48 @@ from gamestonk_terminal import feature_flags as gtff
register_matplotlib_converters()
+api_map = {
+ "gdp": "GDP",
+ "t10": "DGS10",
+ "t01": "DGS1",
+ "t05": "DGS5",
+ "t30": "DGS30",
+ "mort30": "MORTGAGE30US",
+ "libor3m": "USD3MTD156N",
+ "moodAAA": "AAA",
+ "unemp": "UNRATE",
+}
+title_map = {
+ "gdp": "GDP",
+ "t10": "10-Year Treasury Constant Maturity Rate",
+ "t01": "1-Year Treasury Constant Maturity Rate",
+ "t05": "5-Year Treasury Constant Maturity Rate",
+ "t30": "30-Year Treasury Constant Maturity Rate",
+ "mort30": "30-Year Treasury Constant Maturity Rate",
+ "libor3m": "3-Month LIBOR, based on U.S. Dollar",
+ "moodAAA": "Moody's Seasoned AAA Corporate Bond Yield",
+ "unemp": "Unemployment Rate",
+}
-def get_GDP(l_args):
+
+def get_fred_data(l_args, choice):
fred = Fred(api_key=API_FRED_KEY)
+
parser = argparse.ArgumentParser(
add_help=False,
- prog="GDP",
+ prog="Custom",
description="""
- GDP
- """,
- )
- parser.add_argument(
- "-n",
- dest="n_to_get",
- type=int,
- default=-1,
- required=False,
- help="Number of GDP Values to Grab",
+ Custom Data
+ """,
)
parser.add_argument(
"-s",
dest="start_date",
type=valid_date,
- default="2015-01-01",
+ default="2019-01-01",
required=False,
- help="Date to Start",
+ help="Starting date (YYYY-MM-DD) of data",
)
parser.add_argument(
@@ -64,32 +80,33 @@ def get_GDP(l_args):
if not ns_parser:
return
- gdp = fred.get_series("GDP", ns_parser.start_date)
- gdp = pd.DataFrame(gdp, columns=["GDP"])
- gdp.index.name = "Date"
- if int(ns_parser.n_to_get) > 0:
- lastn = gdp.tail(int(ns_parser.n_to_get))
-
- else:
- lastn = gdp
+ string_to_get = api_map[choice]
+ title = title_map[choice]
+ data = fred.get_series(string_to_get, ns_parser.start_date)
+ data = pd.DataFrame(data, columns=[f"{string_to_get}"])
+ data.index.name = "Date"
if ns_parser.hidedata:
- print(lastn)
+ print(data)
print("")
-
if ns_parser.noplot:
plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)
- plt.plot(lastn.index, lastn.GDP, "-ok")
+ plt.plot(data.index, data.iloc[:, 0], "-ok")
plt.xlabel("Time")
- plt.xlim(lastn.index[0], lastn.index[-1])
- plt.ylabel("GDP (bn $)")
- plt.title("FRED GDP Data (in Billions of USD)")
+ plt.xlim(data.index[0], data.index[-1])
+ plt.ylabel(f"{string_to_get}")
plt.grid(b=True, which="major", color="#666666", linestyle="-")
plt.minorticks_on()
plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2)
+ plt.title(title)
plt.show()
print("")
+ if gtff.USE_ION:
+ plt.ion()
+
+ except SystemExit:
+ print("")
except Exception as e:
print(e)
print("")
@@ -114,7 +131,7 @@ def custom_data(l_args):
"-s",
dest="start_date",
type=valid_date,
- default="2015-01-01",
+ default="2019-01-01",
required=False,
help="Starting date (YYYY-MM-DD) of data",
)
diff --git a/gamestonk_terminal/fred/fred_menu.py b/gamestonk_terminal/fred/fred_menu.py
index 6c554fd0322..1c0137d740b 100644
--- a/gamestonk_terminal/fred/fred_menu.py
+++ b/gamestonk_terminal/fred/fred_menu.py
@@ -14,15 +14,36 @@ def print_fred():
print(" q quit this menu, and shows back to main menu")
print(" quit quit to abandon program")
print(" ")
- print(" gdp get GDP")
- print(" cust User Specified FRED Data")
+ print(" gdp GDP")
+ print(" unemp Unemployment Rate")
+ print(" t01 1-Year Treasury Constant Maturity Rate")
+ print(" t05 5-Year Treasury Constant Maturity Rate")
+ print(" t10 10-Year Treasury Constant Maturity Rate")
+ print(" t30 30-Year Treasury Constant Maturity Rate")
+ print(" mort30 30-Year Fixed Rate Mortgage Average")
+ print(" libor3m 3-Month LIBOR, based on U.S. Dollar")
+ print(" moodAAA Moody's Seasoned AAA Corporate Bond Yield")
+ print("")
+ print(" cust User Specified FRED Data - Please Specify --id")
print("")
return
def fred_menu():
fred_parser = argparse.ArgumentParser(prog="fred", add_help=False)
- choices = ["help", "q", "quit", "gdp", "cust"]
+ defined_choices = [
+ "gdp",
+ "unemp",
+ "t01",
+ "t05",
+ "t10",
+ "t30",
+ "mort30",
+ "libor3m",
+ "moodAAA",
+ ]
+ choices = ["help", "q", "quit", "cust"] + defined_choices
+
fred_parser.add_argument("cmd", choices=choices)
completer = NestedCompleter.from_nested_dict({c: None for c in choices})
@@ -58,8 +79,8 @@ def fred_menu():
# Abandon the program
return True
- elif ns_known_args.cmd == "gdp":
- fred_api.get_GDP(l_args)
+ elif ns_known_args.cmd in defined_choices:
+ fred_api.get_fred_data(l_args, ns_known_args.cmd)
elif ns_known_args.cmd == "cust":
fred_api.custom_data(l_args)