From e29405283e1b737ed81b084415e5f5dc57e600c8 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 14:44:02 -0400 Subject: [PATCH 01/18] Added a fred page and added the ability to look at GDP data. --- gamestonk_terminal/config_terminal.py | 3 ++ gamestonk_terminal/fred/README.md | 24 ++++++++++ gamestonk_terminal/fred/__init__.py | 0 gamestonk_terminal/fred/fred_api.py | 66 +++++++++++++++++++++++++++ gamestonk_terminal/fred/fred_menu.py | 64 ++++++++++++++++++++++++++ gamestonk_terminal/main_helper.py | 4 ++ terminal.py | 6 ++- 7 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 gamestonk_terminal/fred/README.md create mode 100644 gamestonk_terminal/fred/__init__.py create mode 100644 gamestonk_terminal/fred/fred_api.py create mode 100644 gamestonk_terminal/fred/fred_menu.py diff --git a/gamestonk_terminal/config_terminal.py b/gamestonk_terminal/config_terminal.py index f1b8757890d..8aa5b4b9437 100644 --- a/gamestonk_terminal/config_terminal.py +++ b/gamestonk_terminal/config_terminal.py @@ -25,3 +25,6 @@ API_POLYGON_KEY = os.getenv("GT_API_POLYGON_KEY") or "REPLACE_ME" API_TWITTER_KEY = os.getenv("GT_API_TWITTER_KEY") or "REPLACE_ME" API_TWITTER_SECRET_KEY = os.getenv("GT_API_TWITTER_SECRET_KEY") or "REPLACE_ME" API_TWITTER_BEARER_TOKEN = os.getenv("GT_API_TWITTER_BEARER_TOKEN") or "REPLACE_ME" + +# fred api ket +FRED_API_KEY = os.getenv("GT_FRED_API_KEY") or "REPLACE_ME" \ No newline at end of file diff --git a/gamestonk_terminal/fred/README.md b/gamestonk_terminal/fred/README.md new file mode 100644 index 00000000000..5ccf25df3ac --- /dev/null +++ b/gamestonk_terminal/fred/README.md @@ -0,0 +1,24 @@ +# fred + +The purpose of fred is to have the ability to look at economic data. + +* [GDP](#GDP) + * Get GDP data + +## GDP +```text +usage: GDP [-n N_TO_GET] [-s START_DATE] [-p PLOT]] +``` +Gets GDP data. Data is released quarterly +* -n : Number of points to display. If unspecified, it will display all available. +* -s : Start Date. Format m/d/y. First point to get +* -p : Option to plot. Defaults to False + +To get the last 20 reported GDP values: +```` +GDP -n 20 +```` +To plot all GDP data since 1/1/2010: +```` +GDP -s 1/1/2010 -p True +```` \ No newline at end of file diff --git a/gamestonk_terminal/fred/__init__.py b/gamestonk_terminal/fred/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py new file mode 100644 index 00000000000..9c3844cf758 --- /dev/null +++ b/gamestonk_terminal/fred/fred_api.py @@ -0,0 +1,66 @@ +from fredapi import Fred +import argparse +import matplotlib.pyplot as plt +from gamestonk_terminal.helper_funcs import ( + parse_known_args_and_warn, +) +from gamestonk_terminal.config_terminal import FRED_API_KEY + +def get_GDP(l_args): + fred = Fred(api_key=FRED_API_KEY) + parser = argparse.ArgumentParser( + add_help=False, + prog="GDP", + description=""" + GDP + """, + ) + parser.add_argument( + "-n", + dest='n_to_get', + type=int, + default=-1, + required=False, + help="Number of GDP Values to Grab", + ) + + parser.add_argument("-s", + dest = "start_date", + type = str, + default='1/1/2020', + required=False, + help='Date to Start') + + parser.add_argument("-p", + dest = "plot_", + type = bool, + default = False, + required=False, + help = 'Plot GDP') + + try: + ns_parser = parse_known_args_and_warn(parser, l_args) + + if not ns_parser: + return + + #gdp = fred.get_series_latest_release('GDP') + gdp = fred.get_series('GDP',ns_parser.start_date) + if int(ns_parser.n_to_get) > 0: + lastn = gdp.tail(int(ns_parser.n_to_get)) + else: + lastn = gdp + for date, val in lastn.iteritems(): + print(f'Date: {date.strftime("%m-%d-%Y")}, GDP: {val} ') + if ns_parser.plot_: + plt.figure() + lastn.plot(style = 'ok') + plt.xlabel('Time') + plt.ylabel('GDP') + plt.show() + except Exception as e: + print(e) + print("") + return + + diff --git a/gamestonk_terminal/fred/fred_menu.py b/gamestonk_terminal/fred/fred_menu.py new file mode 100644 index 00000000000..3563b3c3596 --- /dev/null +++ b/gamestonk_terminal/fred/fred_menu.py @@ -0,0 +1,64 @@ +import argparse + +from gamestonk_terminal import feature_flags as gtff +from gamestonk_terminal.helper_funcs import get_flair +from gamestonk_terminal.menu import session +from prompt_toolkit.completion import NestedCompleter +from gamestonk_terminal.fred import fred_api + + +def print_fred(): + """ Print help """ + + print("\nFred Economic Data:") # https://github.com/JerBouma/FundamentalAnalysis + print(" help show this menu again") + print(" q quit this menu, and shows back to main menu") + print(" quit quit to abandon program") + print(" ") + print(" GDP get GDP") + return + +def fred_menu(): + fred_parser = argparse.ArgumentParser(prog="fa", add_help=False) + choices = [ + "help", + "q", + "quit", + "GDP"] + fred_parser.add_argument("cmd", choices=choices) + completer = NestedCompleter.from_nested_dict({c: None for c in choices}) + + should_print_help = True + while True: + if should_print_help: + print_fred() + should_print_help = False + + # Get input command from user + if session and gtff.USE_PROMPT_TOOLKIT: + as_input = session.prompt( + f"{get_flair()} (fred)> ", + completer=completer, + ) + else: + as_input = input(f"{get_flair()} (fred)> ") + try: + (ns_known_args, l_args) = fred_parser.parse_known_args(as_input.split()) + + except SystemExit: + print("The command selected doesn't exist\n") + continue + + if ns_known_args.cmd == "help": + should_print_help = True + + elif ns_known_args.cmd == "q": + # Just leave the FA menu + return False + + elif ns_known_args.cmd == "quit": + # Abandon the program + return True + + elif ns_known_args.cmd == "GDP": + fred_api.get_GDP(l_args) diff --git a/gamestonk_terminal/main_helper.py b/gamestonk_terminal/main_helper.py index 4e650481d3e..461af450570 100644 --- a/gamestonk_terminal/main_helper.py +++ b/gamestonk_terminal/main_helper.py @@ -52,6 +52,10 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open): print( " sen sentiment of the market, \t from: reddit, stocktwits, twitter" ) + print( + " fred Data from Federal Reserve Bank of St.Louis" + ) + if s_ticker: print( " res research web page, \t e.g.: macroaxis, yahoo finance, fool" diff --git a/terminal.py b/terminal.py index 0d114f028fa..897c417a496 100644 --- a/terminal.py +++ b/terminal.py @@ -20,7 +20,7 @@ from gamestonk_terminal.papermill import papermill_menu as mill from gamestonk_terminal.sentiment import sen_menu as sm from gamestonk_terminal.technical_analysis import ta_menu as tam from gamestonk_terminal.comparison_analysis import ca_menu as cam - +from gamestonk_terminal.fred import fred_menu as fm # import warnings # warnings.simplefilter("always") @@ -65,6 +65,7 @@ def main(): "dd", "pred", "ca", + "fred" ] menu_parser.add_argument("opt", choices=choices) completer = NestedCompleter.from_nested_dict({c: None for c in choices}) @@ -172,6 +173,9 @@ def main(): elif ns_known_args.opt == "dd": b_quit = ddm.dd_menu(df_stock, s_ticker, s_start, s_interval) + elif ns_known_args.opt == "fred": + b_quit = fm.fred_menu() + elif ns_known_args.opt == "pred": if not gtff.ENABLE_PREDICT: From db1a97f4b8125f81fad4ccd10cbc25ae0d565b4e Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 15:07:13 -0400 Subject: [PATCH 02/18] Added function to allow for custom fred data. --- gamestonk_terminal/fred/README.md | 26 +++++++++++- gamestonk_terminal/fred/fred_api.py | 63 ++++++++++++++++++++++++++++ gamestonk_terminal/fred/fred_menu.py | 7 +++- requirements.txt | 1 + 4 files changed, 94 insertions(+), 3 deletions(-) diff --git a/gamestonk_terminal/fred/README.md b/gamestonk_terminal/fred/README.md index 5ccf25df3ac..65e5a814155 100644 --- a/gamestonk_terminal/fred/README.md +++ b/gamestonk_terminal/fred/README.md @@ -4,7 +4,9 @@ The purpose of fred is to have the ability to look at economic data. * [GDP](#GDP) * Get GDP data - +* [cust](#cust) + * Get custom fred data + ## GDP ```text usage: GDP [-n N_TO_GET] [-s START_DATE] [-p PLOT]] @@ -21,4 +23,24 @@ GDP -n 20 To plot all GDP data since 1/1/2010: ```` GDP -s 1/1/2010 -p True -```` \ No newline at end of file +```` + + +## cust + +The fred database has many different datasets freely available. They each have their own custom SERIES_ID which can be obtained through the website. + +```` +usage: cust [-id] [-s START_DATE] [-p PLOT] [-disp DISP] +```` +* -id : Series ID for FRED data. Required argument +* -s : Start data to acquire data. Defaults to 1/1/2020 +* -p : Option to plot. Defaults to False +* -disp : Option to print data to console. Defaults to True. + +The GDP is specifically defined in this menu, but to reproduce it with the custom function, it would be +```` +cust -id GDP -s 1/1/2020 -p True -disp False +```` + +The plot flag allows for plotting and the disp flag tells whether or not to print data to the console. \ No newline at end of file diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py index 9c3844cf758..dbad6692689 100644 --- a/gamestonk_terminal/fred/fred_api.py +++ b/gamestonk_terminal/fred/fred_api.py @@ -63,4 +63,67 @@ def get_GDP(l_args): print("") return +def custom_data(l_args): + fred = Fred(api_key=FRED_API_KEY) + + parser = argparse.ArgumentParser( + add_help=False, + prog="Custom", + description=""" + Custom Data + """, + ) + parser.add_argument('-id', + dest = 'series_id', + required = True, + type=str, + help = 'FRED Series ID') + parser.add_argument("-s", + dest="start_date", + type=str, + default='1/1/2020', + required=False, + help='Date to Start') + parser.add_argument("-p", + dest="plot_", + type=bool, + default=False, + required=False, + help='Plot data') + parser.add_argument("-disp", + dest="disp_", + type=bool, + default=True, + required=False, + help='Printdata') + + + try: + ns_parser = parse_known_args_and_warn(parser, l_args) + + if not ns_parser: + return + + data = fred.get_series(ns_parser.series_id,ns_parser.start_date) + if ns_parser.disp_: + for date, val in data.iteritems(): + print(f'Date: {date.strftime("%m-%d-%Y")}, DATA: {val} ') + try: + if ns_parser.plot_: + plt.figure() + data.plot(style='ok') + plt.xlabel('Time') + plt.ylabel('DATA') + plt.show() + except Exception as e: + print(e) + print("") + return + except Exception as e: + print(e) + print("") + return + + + diff --git a/gamestonk_terminal/fred/fred_menu.py b/gamestonk_terminal/fred/fred_menu.py index 3563b3c3596..96ed35f3130 100644 --- a/gamestonk_terminal/fred/fred_menu.py +++ b/gamestonk_terminal/fred/fred_menu.py @@ -16,6 +16,7 @@ def print_fred(): print(" quit quit to abandon program") print(" ") print(" GDP get GDP") + print(" cust User Specified FRED Data") return def fred_menu(): @@ -24,7 +25,8 @@ def fred_menu(): "help", "q", "quit", - "GDP"] + "GDP", + "cust"] fred_parser.add_argument("cmd", choices=choices) completer = NestedCompleter.from_nested_dict({c: None for c in choices}) @@ -62,3 +64,6 @@ def fred_menu(): elif ns_known_args.cmd == "GDP": fred_api.get_GDP(l_args) + + elif ns_known_args.cmd == "cust": + fred_api.custom_data(l_args) diff --git a/requirements.txt b/requirements.txt index a6b36ab22f8..e2b6c236cc2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -25,6 +25,7 @@ decorator==4.4.2; python_full_version >= "3.6.1" and python_version >= "3.6" and defusedxml==0.7.1; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6" entrypoints==0.3; python_version >= "3.6" finviz==1.3.4 +fredapi==0.4.3 fundamentalanalysis==0.2.6 hijri-converter==2.1.1; python_version >= "3.6" holidays==0.10.5.2 From 287f3f1e0c21f8a6ed26662d3b9e8d6438372835 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 15:32:59 -0400 Subject: [PATCH 03/18] poetry add fredapi --- gamestonk_terminal/config_terminal.py | 2 +- poetry.lock | 25 ++++++++++++++++++++++++- pyproject.toml | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gamestonk_terminal/config_terminal.py b/gamestonk_terminal/config_terminal.py index 8aa5b4b9437..ba3ca0764d7 100644 --- a/gamestonk_terminal/config_terminal.py +++ b/gamestonk_terminal/config_terminal.py @@ -26,5 +26,5 @@ API_TWITTER_KEY = os.getenv("GT_API_TWITTER_KEY") or "REPLACE_ME" API_TWITTER_SECRET_KEY = os.getenv("GT_API_TWITTER_SECRET_KEY") or "REPLACE_ME" API_TWITTER_BEARER_TOKEN = os.getenv("GT_API_TWITTER_BEARER_TOKEN") or "REPLACE_ME" -# fred api ket +# fred api key FRED_API_KEY = os.getenv("GT_FRED_API_KEY") or "REPLACE_ME" \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index 44353264ba9..f31b2b8df6f 100644 --- a/poetry.lock +++ b/poetry.lock @@ -476,6 +476,17 @@ category = "main" optional = true python-versions = "*" +[[package]] +name = "fredapi" +version = "0.4.3" +description = "Python API for Federal Reserve Economic Data (FRED) from St. Louis Fed" +category = "main" +optional = false +python-versions = "*" + +[package.dependencies] +pandas = "*" + [[package]] name = "ftfy" version = "5.9" @@ -2474,7 +2485,7 @@ prediction = ["fbprophet", "tensorflow", "pmdarima", "transformers", "flair", "t [metadata] lock-version = "1.1" python-versions = "^3.6.8" -content-hash = "cfb418b140b12dd94550b1f21431ceb8bf23df30ae4ec9735a98bc76edbfbb85" +content-hash = "184502c6b8d4b7db5baa4323e7f70b2585c6140c304583f0678e24681b8f9c9b" [metadata.files] absl-py = [ @@ -2778,6 +2789,10 @@ flatbuffers = [ {file = "flatbuffers-1.12-py2.py3-none-any.whl", hash = "sha256:9e9ef47fa92625c4721036e7c4124182668dc6021d9e7c73704edd395648deb9"}, {file = "flatbuffers-1.12.tar.gz", hash = "sha256:63bb9a722d5e373701913e226135b28a6f6ac200d5cc7b4d919fa38d73b44610"}, ] +fredapi = [ + {file = "fredapi-0.4.3-py3-none-any.whl", hash = "sha256:e06075592eabddadfe0635f3c59e9072c9f48647430328b4582171ea10f7df2f"}, + {file = "fredapi-0.4.3.tar.gz", hash = "sha256:d9b3194fb60541991bd33f019c710d4a9580ecfb5e47efbf2d2571888a2aac02"}, +] ftfy = [ {file = "ftfy-5.9.tar.gz", hash = "sha256:8c4fb2863c0b82eae2ab3cf353d9ade268dfbde863d322f78d6a9fd5cefb31e9"}, ] @@ -3610,18 +3625,26 @@ pyyaml = [ {file = "PyYAML-5.4.1-cp27-cp27mu-manylinux1_x86_64.whl", hash = "sha256:bb4191dfc9306777bc594117aee052446b3fa88737cd13b7188d0e7aa8162185"}, {file = "PyYAML-5.4.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:6c78645d400265a062508ae399b60b8c167bf003db364ecb26dcab2bda048253"}, {file = "PyYAML-5.4.1-cp36-cp36m-manylinux1_x86_64.whl", hash = "sha256:4e0583d24c881e14342eaf4ec5fbc97f934b999a6828693a99157fde912540cc"}, + {file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_aarch64.whl", hash = "sha256:72a01f726a9c7851ca9bfad6fd09ca4e090a023c00945ea05ba1638c09dc3347"}, + {file = "PyYAML-5.4.1-cp36-cp36m-manylinux2014_s390x.whl", hash = "sha256:895f61ef02e8fed38159bb70f7e100e00f471eae2bc838cd0f4ebb21e28f8541"}, {file = "PyYAML-5.4.1-cp36-cp36m-win32.whl", hash = "sha256:3bd0e463264cf257d1ffd2e40223b197271046d09dadf73a0fe82b9c1fc385a5"}, {file = "PyYAML-5.4.1-cp36-cp36m-win_amd64.whl", hash = "sha256:e4fac90784481d221a8e4b1162afa7c47ed953be40d31ab4629ae917510051df"}, {file = "PyYAML-5.4.1-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:5accb17103e43963b80e6f837831f38d314a0495500067cb25afab2e8d7a4018"}, {file = "PyYAML-5.4.1-cp37-cp37m-manylinux1_x86_64.whl", hash = "sha256:e1d4970ea66be07ae37a3c2e48b5ec63f7ba6804bdddfdbd3cfd954d25a82e63"}, + {file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_aarch64.whl", hash = "sha256:cb333c16912324fd5f769fff6bc5de372e9e7a202247b48870bc251ed40239aa"}, + {file = "PyYAML-5.4.1-cp37-cp37m-manylinux2014_s390x.whl", hash = "sha256:fe69978f3f768926cfa37b867e3843918e012cf83f680806599ddce33c2c68b0"}, {file = "PyYAML-5.4.1-cp37-cp37m-win32.whl", hash = "sha256:dd5de0646207f053eb0d6c74ae45ba98c3395a571a2891858e87df7c9b9bd51b"}, {file = "PyYAML-5.4.1-cp37-cp37m-win_amd64.whl", hash = "sha256:08682f6b72c722394747bddaf0aa62277e02557c0fd1c42cb853016a38f8dedf"}, {file = "PyYAML-5.4.1-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:d2d9808ea7b4af864f35ea216be506ecec180628aced0704e34aca0b040ffe46"}, {file = "PyYAML-5.4.1-cp38-cp38-manylinux1_x86_64.whl", hash = "sha256:8c1be557ee92a20f184922c7b6424e8ab6691788e6d86137c5d93c1a6ec1b8fb"}, + {file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_aarch64.whl", hash = "sha256:fd7f6999a8070df521b6384004ef42833b9bd62cfee11a09bda1079b4b704247"}, + {file = "PyYAML-5.4.1-cp38-cp38-manylinux2014_s390x.whl", hash = "sha256:bfb51918d4ff3d77c1c856a9699f8492c612cde32fd3bcd344af9be34999bfdc"}, {file = "PyYAML-5.4.1-cp38-cp38-win32.whl", hash = "sha256:fa5ae20527d8e831e8230cbffd9f8fe952815b2b7dae6ffec25318803a7528fc"}, {file = "PyYAML-5.4.1-cp38-cp38-win_amd64.whl", hash = "sha256:0f5f5786c0e09baddcd8b4b45f20a7b5d61a7e7e99846e3c799b05c7c53fa696"}, {file = "PyYAML-5.4.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:294db365efa064d00b8d1ef65d8ea2c3426ac366c0c4368d930bf1c5fb497f77"}, {file = "PyYAML-5.4.1-cp39-cp39-manylinux1_x86_64.whl", hash = "sha256:74c1485f7707cf707a7aef42ef6322b8f97921bd89be2ab6317fd782c2d53183"}, + {file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_aarch64.whl", hash = "sha256:d483ad4e639292c90170eb6f7783ad19490e7a8defb3e46f97dfe4bacae89122"}, + {file = "PyYAML-5.4.1-cp39-cp39-manylinux2014_s390x.whl", hash = "sha256:fdc842473cd33f45ff6bce46aea678a54e3d21f1b61a7750ce3c498eedfe25d6"}, {file = "PyYAML-5.4.1-cp39-cp39-win32.whl", hash = "sha256:49d4cdd9065b9b6e206d0595fee27a96b5dd22618e7520c33204a4a3239d5b10"}, {file = "PyYAML-5.4.1-cp39-cp39-win_amd64.whl", hash = "sha256:c20cfa2d49991c8b4147af39859b167664f2ad4561704ee74c1de03318e898db"}, {file = "PyYAML-5.4.1.tar.gz", hash = "sha256:607774cbba28732bfa802b54baa7484215f530991055bb562efbed5b2f20a45e"}, diff --git a/pyproject.toml b/pyproject.toml index 0eb5c36af5f..b11836c7ad0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,6 +38,7 @@ jupyter = "^1.0.0" mplfinance = "^0.12.7-alpha.7" seaborn = "^0.11.0" scipy = "1.5.4" +fredapi = "^0.4.3" [tool.poetry.dev-dependencies] pytest = "^6.2.2" From 027e71bf0847dad2b759e49e6baa6e639a3a566a Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 15:36:20 -0400 Subject: [PATCH 04/18] delete commmented text --- gamestonk_terminal/config_terminal.py | 4 ++-- gamestonk_terminal/fred/fred_api.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gamestonk_terminal/config_terminal.py b/gamestonk_terminal/config_terminal.py index ba3ca0764d7..21e62b02c93 100644 --- a/gamestonk_terminal/config_terminal.py +++ b/gamestonk_terminal/config_terminal.py @@ -26,5 +26,5 @@ API_TWITTER_KEY = os.getenv("GT_API_TWITTER_KEY") or "REPLACE_ME" API_TWITTER_SECRET_KEY = os.getenv("GT_API_TWITTER_SECRET_KEY") or "REPLACE_ME" API_TWITTER_BEARER_TOKEN = os.getenv("GT_API_TWITTER_BEARER_TOKEN") or "REPLACE_ME" -# fred api key -FRED_API_KEY = os.getenv("GT_FRED_API_KEY") or "REPLACE_ME" \ No newline at end of file +# https://fred.stlouisfed.org/docs/api/api_key.html +API_FRED_KEY = os.getenv("GT_FRED_API_KEY") or "REPLACE_ME" \ No newline at end of file diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py index dbad6692689..e1f6d7d273a 100644 --- a/gamestonk_terminal/fred/fred_api.py +++ b/gamestonk_terminal/fred/fred_api.py @@ -4,7 +4,7 @@ import matplotlib.pyplot as plt from gamestonk_terminal.helper_funcs import ( parse_known_args_and_warn, ) -from gamestonk_terminal.config_terminal import FRED_API_KEY +from gamestonk_terminal.config_terminal import API_FRED_KEY def get_GDP(l_args): fred = Fred(api_key=FRED_API_KEY) @@ -44,14 +44,17 @@ def get_GDP(l_args): if not ns_parser: return - #gdp = fred.get_series_latest_release('GDP') gdp = fred.get_series('GDP',ns_parser.start_date) + if int(ns_parser.n_to_get) > 0: lastn = gdp.tail(int(ns_parser.n_to_get)) + else: lastn = gdp + for date, val in lastn.iteritems(): print(f'Date: {date.strftime("%m-%d-%Y")}, GDP: {val} ') + if ns_parser.plot_: plt.figure() lastn.plot(style = 'ok') From 005f73151889d11e1cd8464ab9cc791e2ee1627f Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 15:41:56 -0400 Subject: [PATCH 05/18] black gamestonk_terminal --- gamestonk_terminal/config_terminal.py | 2 +- gamestonk_terminal/fred/fred_api.py | 88 ++++++++++++--------------- gamestonk_terminal/fred/fred_menu.py | 8 +-- gamestonk_terminal/main_helper.py | 4 +- 4 files changed, 43 insertions(+), 59 deletions(-) diff --git a/gamestonk_terminal/config_terminal.py b/gamestonk_terminal/config_terminal.py index 21e62b02c93..6939d823cee 100644 --- a/gamestonk_terminal/config_terminal.py +++ b/gamestonk_terminal/config_terminal.py @@ -27,4 +27,4 @@ API_TWITTER_SECRET_KEY = os.getenv("GT_API_TWITTER_SECRET_KEY") or "REPLACE_ME" API_TWITTER_BEARER_TOKEN = os.getenv("GT_API_TWITTER_BEARER_TOKEN") or "REPLACE_ME" # https://fred.stlouisfed.org/docs/api/api_key.html -API_FRED_KEY = os.getenv("GT_FRED_API_KEY") or "REPLACE_ME" \ No newline at end of file +API_FRED_KEY = os.getenv("GT_FRED_API_KEY") or "REPLACE_ME" diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py index e1f6d7d273a..fafdca5c129 100644 --- a/gamestonk_terminal/fred/fred_api.py +++ b/gamestonk_terminal/fred/fred_api.py @@ -6,6 +6,7 @@ from gamestonk_terminal.helper_funcs import ( ) from gamestonk_terminal.config_terminal import API_FRED_KEY + def get_GDP(l_args): fred = Fred(api_key=FRED_API_KEY) parser = argparse.ArgumentParser( @@ -17,26 +18,25 @@ def get_GDP(l_args): ) parser.add_argument( "-n", - dest='n_to_get', + dest="n_to_get", type=int, default=-1, required=False, help="Number of GDP Values to Grab", ) - parser.add_argument("-s", - dest = "start_date", - type = str, - default='1/1/2020', - required=False, - help='Date to Start') + parser.add_argument( + "-s", + dest="start_date", + type=str, + default="1/1/2020", + required=False, + help="Date to Start", + ) - parser.add_argument("-p", - dest = "plot_", - type = bool, - default = False, - required=False, - help = 'Plot GDP') + parser.add_argument( + "-p", dest="plot_", type=bool, default=False, required=False, help="Plot GDP" + ) try: ns_parser = parse_known_args_and_warn(parser, l_args) @@ -44,7 +44,7 @@ def get_GDP(l_args): if not ns_parser: return - gdp = fred.get_series('GDP',ns_parser.start_date) + gdp = fred.get_series("GDP", ns_parser.start_date) if int(ns_parser.n_to_get) > 0: lastn = gdp.tail(int(ns_parser.n_to_get)) @@ -57,15 +57,16 @@ def get_GDP(l_args): if ns_parser.plot_: plt.figure() - lastn.plot(style = 'ok') - plt.xlabel('Time') - plt.ylabel('GDP') + lastn.plot(style="ok") + plt.xlabel("Time") + plt.ylabel("GDP") plt.show() except Exception as e: print(e) print("") return + def custom_data(l_args): fred = Fred(api_key=FRED_API_KEY) @@ -76,30 +77,23 @@ def custom_data(l_args): Custom Data """, ) - parser.add_argument('-id', - dest = 'series_id', - required = True, - type=str, - help = 'FRED Series ID') - parser.add_argument("-s", - dest="start_date", - type=str, - default='1/1/2020', - required=False, - help='Date to Start') - parser.add_argument("-p", - dest="plot_", - type=bool, - default=False, - required=False, - help='Plot data') - parser.add_argument("-disp", - dest="disp_", - type=bool, - default=True, - required=False, - help='Printdata') - + parser.add_argument( + "-id", dest="series_id", required=True, type=str, help="FRED Series ID" + ) + parser.add_argument( + "-s", + dest="start_date", + type=str, + default="1/1/2020", + required=False, + help="Date to Start", + ) + parser.add_argument( + "-p", dest="plot_", type=bool, default=False, required=False, help="Plot data" + ) + parser.add_argument( + "-disp", dest="disp_", type=bool, default=True, required=False, help="Printdata" + ) try: ns_parser = parse_known_args_and_warn(parser, l_args) @@ -107,16 +101,16 @@ def custom_data(l_args): if not ns_parser: return - data = fred.get_series(ns_parser.series_id,ns_parser.start_date) + data = fred.get_series(ns_parser.series_id, ns_parser.start_date) if ns_parser.disp_: for date, val in data.iteritems(): print(f'Date: {date.strftime("%m-%d-%Y")}, DATA: {val} ') try: if ns_parser.plot_: plt.figure() - data.plot(style='ok') - plt.xlabel('Time') - plt.ylabel('DATA') + data.plot(style="ok") + plt.xlabel("Time") + plt.ylabel("DATA") plt.show() except Exception as e: print(e) @@ -126,7 +120,3 @@ def custom_data(l_args): print(e) print("") return - - - - diff --git a/gamestonk_terminal/fred/fred_menu.py b/gamestonk_terminal/fred/fred_menu.py index 96ed35f3130..9094870a8ec 100644 --- a/gamestonk_terminal/fred/fred_menu.py +++ b/gamestonk_terminal/fred/fred_menu.py @@ -19,14 +19,10 @@ def print_fred(): print(" cust User Specified FRED Data") return + def fred_menu(): fred_parser = argparse.ArgumentParser(prog="fa", add_help=False) - choices = [ - "help", - "q", - "quit", - "GDP", - "cust"] + choices = ["help", "q", "quit", "GDP", "cust"] fred_parser.add_argument("cmd", choices=choices) completer = NestedCompleter.from_nested_dict({c: None for c in choices}) diff --git a/gamestonk_terminal/main_helper.py b/gamestonk_terminal/main_helper.py index 461af450570..3f491e3835e 100644 --- a/gamestonk_terminal/main_helper.py +++ b/gamestonk_terminal/main_helper.py @@ -52,9 +52,7 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open): print( " sen sentiment of the market, \t from: reddit, stocktwits, twitter" ) - print( - " fred Data from Federal Reserve Bank of St.Louis" - ) + print(" fred Data from Federal Reserve Bank of St.Louis") if s_ticker: print( From ca3711d99b0c9089a6c31c940122ab22e283a605 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 15:44:27 -0400 Subject: [PATCH 06/18] black terminal.py --- terminal.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/terminal.py b/terminal.py index 897c417a496..5e4ce05ae7d 100644 --- a/terminal.py +++ b/terminal.py @@ -21,6 +21,7 @@ from gamestonk_terminal.sentiment import sen_menu as sm from gamestonk_terminal.technical_analysis import ta_menu as tam from gamestonk_terminal.comparison_analysis import ca_menu as cam from gamestonk_terminal.fred import fred_menu as fm + # import warnings # warnings.simplefilter("always") @@ -65,7 +66,7 @@ def main(): "dd", "pred", "ca", - "fred" + "fred", ] menu_parser.add_argument("opt", choices=choices) completer = NestedCompleter.from_nested_dict({c: None for c in choices}) From eeb320231ae510bc24efe5c27d974ba6dd4be6d1 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 15:46:29 -0400 Subject: [PATCH 07/18] fixed api key reference --- gamestonk_terminal/fred/fred_api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py index fafdca5c129..1246d592186 100644 --- a/gamestonk_terminal/fred/fred_api.py +++ b/gamestonk_terminal/fred/fred_api.py @@ -8,7 +8,7 @@ from gamestonk_terminal.config_terminal import API_FRED_KEY def get_GDP(l_args): - fred = Fred(api_key=FRED_API_KEY) + fred = Fred(api_key=API_FRED_KEY) parser = argparse.ArgumentParser( add_help=False, prog="GDP", @@ -68,7 +68,7 @@ def get_GDP(l_args): def custom_data(l_args): - fred = Fred(api_key=FRED_API_KEY) + fred = Fred(api_key=API_FRED_KEY) parser = argparse.ArgumentParser( add_help=False, From c320329b372c44f92d1492bc7b3a26d0db8f3c20 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 17:10:05 -0400 Subject: [PATCH 08/18] minor formatting changes --- gamestonk_terminal/fred/README.md | 24 ++++++++++---------- gamestonk_terminal/fred/fred_api.py | 33 ++++++++++++++++++++++------ gamestonk_terminal/fred/fred_menu.py | 12 +++++----- gamestonk_terminal/main_helper.py | 2 +- 4 files changed, 45 insertions(+), 26 deletions(-) diff --git a/gamestonk_terminal/fred/README.md b/gamestonk_terminal/fred/README.md index 65e5a814155..ec0ef0791f1 100644 --- a/gamestonk_terminal/fred/README.md +++ b/gamestonk_terminal/fred/README.md @@ -1,28 +1,28 @@ -# fred +# FRED The purpose of fred is to have the ability to look at economic data. -* [GDP](#GDP) +* [gdp](#gdp) * Get GDP data * [cust](#cust) * Get custom fred data -## GDP +## gdp ```text -usage: GDP [-n N_TO_GET] [-s START_DATE] [-p PLOT]] +usage: gdp [-n N_TO_GET] [-s START_DATE] [-p PLOT]] ``` Gets GDP data. Data is released quarterly * -n : Number of points to display. If unspecified, it will display all available. * -s : Start Date. Format m/d/y. First point to get * -p : Option to plot. Defaults to False -To get the last 20 reported GDP values: +To get and plot the last 20 reported GDP values: ```` -GDP -n 20 +gdp -n 20 ```` -To plot all GDP data since 1/1/2010: +To show all GDP data since 1/1/2010, with no plot. ```` -GDP -s 1/1/2010 -p True +gdp -s 1/1/2010 -p True ```` @@ -35,12 +35,12 @@ usage: cust [-id] [-s START_DATE] [-p PLOT] [-disp DISP] ```` * -id : Series ID for FRED data. Required argument * -s : Start data to acquire data. Defaults to 1/1/2020 -* -p : Option to plot. Defaults to False -* -disp : Option to print data to console. Defaults to True. +* -p : Option to plot. Defaults to True +* -disp : Option to print data to console. Defaults to False. The GDP is specifically defined in this menu, but to reproduce it with the custom function, it would be ```` -cust -id GDP -s 1/1/2020 -p True -disp False +cust -id GDP -s 1/1/2020 -p True ```` -The plot flag allows for plotting and the disp flag tells whether or not to print data to the console. \ No newline at end of file +The plot flag allows for plotting and the disp flag tells whether to print data to the console. \ No newline at end of file diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py index 1246d592186..394387e014e 100644 --- a/gamestonk_terminal/fred/fred_api.py +++ b/gamestonk_terminal/fred/fred_api.py @@ -35,7 +35,11 @@ def get_GDP(l_args): ) parser.add_argument( - "-p", dest="plot_", type=bool, default=False, required=False, help="Plot GDP" + "-p", dest="plot", + type=bool, + default=True, + required=False, + help="Plot GDP" ) try: @@ -55,12 +59,13 @@ def get_GDP(l_args): for date, val in lastn.iteritems(): print(f'Date: {date.strftime("%m-%d-%Y")}, GDP: {val} ') - if ns_parser.plot_: + if ns_parser.plot: plt.figure() lastn.plot(style="ok") plt.xlabel("Time") plt.ylabel("GDP") plt.show() + except Exception as e: print(e) print("") @@ -78,8 +83,12 @@ def custom_data(l_args): """, ) parser.add_argument( - "-id", dest="series_id", required=True, type=str, help="FRED Series ID" + "-id", dest="series_id", + required=True, + type=str, + help="FRED Series ID" ) + parser.add_argument( "-s", dest="start_date", @@ -89,10 +98,20 @@ def custom_data(l_args): help="Date to Start", ) parser.add_argument( - "-p", dest="plot_", type=bool, default=False, required=False, help="Plot data" + "-p", + dest="plot", + type=bool, + default=True, + required=False, + help="Plot data" ) parser.add_argument( - "-disp", dest="disp_", type=bool, default=True, required=False, help="Printdata" + "-disp", + dest="disp", + type=bool, + default=False, + required=False, + help="Print data" ) try: @@ -102,11 +121,11 @@ def custom_data(l_args): return data = fred.get_series(ns_parser.series_id, ns_parser.start_date) - if ns_parser.disp_: + if ns_parser.disp: for date, val in data.iteritems(): print(f'Date: {date.strftime("%m-%d-%Y")}, DATA: {val} ') try: - if ns_parser.plot_: + if ns_parser.plot: plt.figure() data.plot(style="ok") plt.xlabel("Time") diff --git a/gamestonk_terminal/fred/fred_menu.py b/gamestonk_terminal/fred/fred_menu.py index 9094870a8ec..f7f2d427fad 100644 --- a/gamestonk_terminal/fred/fred_menu.py +++ b/gamestonk_terminal/fred/fred_menu.py @@ -10,19 +10,19 @@ from gamestonk_terminal.fred import fred_api def print_fred(): """ Print help """ - print("\nFred Economic Data:") # https://github.com/JerBouma/FundamentalAnalysis + print("\nFred Economic Data:") print(" help show this menu again") print(" q quit this menu, and shows back to main menu") print(" quit quit to abandon program") print(" ") - print(" GDP get GDP") + print(" gdp get GDP") print(" cust User Specified FRED Data") return def fred_menu(): - fred_parser = argparse.ArgumentParser(prog="fa", add_help=False) - choices = ["help", "q", "quit", "GDP", "cust"] + fred_parser = argparse.ArgumentParser(prog="fred", add_help=False) + choices = ["help", "q", "quit", "gdp", "cust"] fred_parser.add_argument("cmd", choices=choices) completer = NestedCompleter.from_nested_dict({c: None for c in choices}) @@ -51,14 +51,14 @@ def fred_menu(): should_print_help = True elif ns_known_args.cmd == "q": - # Just leave the FA menu + # Leave the fred menu return False elif ns_known_args.cmd == "quit": # Abandon the program return True - elif ns_known_args.cmd == "GDP": + elif ns_known_args.cmd == "gdp": fred_api.get_GDP(l_args) elif ns_known_args.cmd == "cust": diff --git a/gamestonk_terminal/main_helper.py b/gamestonk_terminal/main_helper.py index 3f491e3835e..c0c0d5e6e89 100644 --- a/gamestonk_terminal/main_helper.py +++ b/gamestonk_terminal/main_helper.py @@ -52,7 +52,7 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open): print( " sen sentiment of the market, \t from: reddit, stocktwits, twitter" ) - print(" fred Data from Federal Reserve Bank of St.Louis") + print(" fred economic data, \t\t\t from: Federal Reserve Bank of St. Louis ") if s_ticker: print( From 5abd4aa5f22304c200c68fd38d43d03858ad915f Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 17:34:41 -0400 Subject: [PATCH 09/18] added helper function str to bool to fix issue where using -p False was not changing from the default. --- gamestonk_terminal/fred/README.md | 37 +++++++++++++++++++++++++---- gamestonk_terminal/fred/fred_api.py | 35 ++++++++++++++------------- gamestonk_terminal/helper_funcs.py | 9 +++++++ gamestonk_terminal/main_helper.py | 4 +++- 4 files changed, 62 insertions(+), 23 deletions(-) diff --git a/gamestonk_terminal/fred/README.md b/gamestonk_terminal/fred/README.md index ec0ef0791f1..a394a9b0ca6 100644 --- a/gamestonk_terminal/fred/README.md +++ b/gamestonk_terminal/fred/README.md @@ -13,16 +13,43 @@ usage: gdp [-n N_TO_GET] [-s START_DATE] [-p PLOT]] ``` Gets GDP data. Data is released quarterly * -n : Number of points to display. If unspecified, it will display all available. -* -s : Start Date. Format m/d/y. First point to get +* -s : Start Date. Format YYYY-mm-dd. First point to get. Defaults to Jan 1 2015 * -p : Option to plot. Defaults to False To get and plot the last 20 reported GDP values: ```` gdp -n 20 ```` -To show all GDP data since 1/1/2010, with no plot. +To show all GDP data since 1/1/2016, with no plot. ```` -gdp -s 1/1/2010 -p True +gdp -s 2016-01-01 -p False +```` +```` +Date: 01-01-2015, GDP: 18003.399 +Date: 04-01-2015, GDP: 18223.577 +Date: 07-01-2015, GDP: 18347.425 +Date: 10-01-2015, GDP: 18378.803 +Date: 01-01-2016, GDP: 18470.156 +Date: 04-01-2016, GDP: 18656.207 +Date: 07-01-2016, GDP: 18821.359 +Date: 10-01-2016, GDP: 19032.58 +Date: 01-01-2017, GDP: 19237.435 +Date: 04-01-2017, GDP: 19379.232 +Date: 07-01-2017, GDP: 19617.288 +Date: 10-01-2017, GDP: 19937.963 +Date: 01-01-2018, GDP: 20242.215 +Date: 04-01-2018, GDP: 20552.653 +Date: 07-01-2018, GDP: 20742.723 +Date: 10-01-2018, GDP: 20909.853 +Date: 01-01-2019, GDP: 21115.309 +Date: 04-01-2019, GDP: 21329.877 +Date: 07-01-2019, GDP: 21540.325 +Date: 10-01-2019, GDP: 21747.394 +Date: 01-01-2020, GDP: 21561.139 +Date: 04-01-2020, GDP: 19520.114 +Date: 07-01-2020, GDP: 21170.252 +Date: 10-01-2020, GDP: 21487.896 + ```` @@ -34,13 +61,13 @@ The fred database has many different datasets freely available. They each have usage: cust [-id] [-s START_DATE] [-p PLOT] [-disp DISP] ```` * -id : Series ID for FRED data. Required argument -* -s : Start data to acquire data. Defaults to 1/1/2020 +* -s : Start Date. Format YYYY-mm-dd. First point to get. Defaults to Jan 1 2015. * -p : Option to plot. Defaults to True * -disp : Option to print data to console. Defaults to False. The GDP is specifically defined in this menu, but to reproduce it with the custom function, it would be ```` -cust -id GDP -s 1/1/2020 -p True +cust -id GDP -s 2020-01-01 -p True ```` The plot flag allows for plotting and the disp flag tells whether to print data to the console. \ No newline at end of file diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py index 394387e014e..b96aceb8a94 100644 --- a/gamestonk_terminal/fred/fred_api.py +++ b/gamestonk_terminal/fred/fred_api.py @@ -3,6 +3,8 @@ import argparse import matplotlib.pyplot as plt from gamestonk_terminal.helper_funcs import ( parse_known_args_and_warn, + valid_date, + str_to_bool, ) from gamestonk_terminal.config_terminal import API_FRED_KEY @@ -28,18 +30,19 @@ def get_GDP(l_args): parser.add_argument( "-s", dest="start_date", - type=str, - default="1/1/2020", + type=valid_date, + default="2015-01-01", required=False, help="Date to Start", ) parser.add_argument( - "-p", dest="plot", - type=bool, + "-p", + dest="plot", + type=str_to_bool, default=True, required=False, - help="Plot GDP" + help="Plot GDP", ) try: @@ -61,7 +64,7 @@ def get_GDP(l_args): if ns_parser.plot: plt.figure() - lastn.plot(style="ok") + lastn.plot(style="-ok") plt.xlabel("Time") plt.ylabel("GDP") plt.show() @@ -83,35 +86,32 @@ def custom_data(l_args): """, ) parser.add_argument( - "-id", dest="series_id", - required=True, - type=str, - help="FRED Series ID" + "-id", dest="series_id", required=True, type=str, help="FRED Series ID" ) parser.add_argument( "-s", dest="start_date", - type=str, - default="1/1/2020", + type=valid_date, + default="2015-01-01", required=False, help="Date to Start", ) parser.add_argument( "-p", dest="plot", - type=bool, + type=str_to_bool, default=True, required=False, - help="Plot data" + help="Plot data", ) parser.add_argument( "-disp", dest="disp", - type=bool, + type=str_to_bool, default=False, required=False, - help="Print data" + help="Print data", ) try: @@ -127,7 +127,7 @@ def custom_data(l_args): try: if ns_parser.plot: plt.figure() - data.plot(style="ok") + data.plot(style="-ok") plt.xlabel("Time") plt.ylabel("DATA") plt.show() @@ -135,6 +135,7 @@ def custom_data(l_args): print(e) print("") return + except Exception as e: print(e) print("") diff --git a/gamestonk_terminal/helper_funcs.py b/gamestonk_terminal/helper_funcs.py index cd1c92d2a25..f8653eb4a4a 100644 --- a/gamestonk_terminal/helper_funcs.py +++ b/gamestonk_terminal/helper_funcs.py @@ -353,3 +353,12 @@ def get_flair() -> str: return flair[gtff.USE_FLAIR] return "" + +def str_to_bool(value): + if isinstance(value, bool): + return value + if value.lower() in {"false", "f", "0", "no", "n"}: + return False + elif value.lower() in {"true", "t", "1", "yes", "y"}: + return True + raise ValueError(f"{value} is not a valid boolean value") diff --git a/gamestonk_terminal/main_helper.py b/gamestonk_terminal/main_helper.py index c0c0d5e6e89..180b4d73266 100644 --- a/gamestonk_terminal/main_helper.py +++ b/gamestonk_terminal/main_helper.py @@ -52,7 +52,9 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open): print( " sen sentiment of the market, \t from: reddit, stocktwits, twitter" ) - print(" fred economic data, \t\t\t from: Federal Reserve Bank of St. Louis ") + print( + " fred economic data, \t\t\t from: Federal Reserve Bank of St. Louis " + ) if s_ticker: print( From 97d15e2dd2a90c57a50545920a6e95c7d93ac9b9 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 17:44:07 -0400 Subject: [PATCH 10/18] readme update --- gamestonk_terminal/fred/README.md | 40 ++++++++++++++++++++++++++---- gamestonk_terminal/helper_funcs.py | 1 + 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/gamestonk_terminal/fred/README.md b/gamestonk_terminal/fred/README.md index a394a9b0ca6..2343af81ae0 100644 --- a/gamestonk_terminal/fred/README.md +++ b/gamestonk_terminal/fred/README.md @@ -65,9 +65,39 @@ usage: cust [-id] [-s START_DATE] [-p PLOT] [-disp DISP] * -p : Option to plot. Defaults to True * -disp : Option to print data to console. Defaults to False. -The GDP is specifically defined in this menu, but to reproduce it with the custom function, it would be -```` -cust -id GDP -s 2020-01-01 -p True -```` +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 -The plot flag allows for plotting and the disp flag tells whether to print data to the console. \ No newline at end of file +```` +cust -id UNRATE -s 2019-01-01 -disp True +```` +This will plot and display: + + +```` +Date: 01-01-2019, DATA: 4.0 +Date: 02-01-2019, DATA: 3.8 +Date: 03-01-2019, DATA: 3.8 +Date: 04-01-2019, DATA: 3.7 +Date: 05-01-2019, DATA: 3.7 +Date: 06-01-2019, DATA: 3.6 +Date: 07-01-2019, DATA: 3.6 +Date: 08-01-2019, DATA: 3.7 +Date: 09-01-2019, DATA: 3.5 +Date: 10-01-2019, DATA: 3.6 +Date: 11-01-2019, DATA: 3.6 +Date: 12-01-2019, DATA: 3.6 +Date: 01-01-2020, DATA: 3.5 +Date: 02-01-2020, DATA: 3.5 +Date: 03-01-2020, DATA: 4.4 +Date: 04-01-2020, DATA: 14.8 +Date: 05-01-2020, DATA: 13.3 +Date: 06-01-2020, DATA: 11.1 +Date: 07-01-2020, DATA: 10.2 +Date: 08-01-2020, DATA: 8.4 +Date: 09-01-2020, DATA: 7.8 +Date: 10-01-2020, DATA: 6.9 +Date: 11-01-2020, DATA: 6.7 +Date: 12-01-2020, DATA: 6.7 +Date: 01-01-2021, DATA: 6.3 +Date: 02-01-2021, DATA: 6.2 +```` \ No newline at end of file diff --git a/gamestonk_terminal/helper_funcs.py b/gamestonk_terminal/helper_funcs.py index f8653eb4a4a..b6cc6118132 100644 --- a/gamestonk_terminal/helper_funcs.py +++ b/gamestonk_terminal/helper_funcs.py @@ -354,6 +354,7 @@ def get_flair() -> str: return "" + def str_to_bool(value): if isinstance(value, bool): return value From 3ea287f8844d7b7c4f3aaf6680eab028ac71e629 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 17:50:00 -0400 Subject: [PATCH 11/18] linting error --- gamestonk_terminal/helper_funcs.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gamestonk_terminal/helper_funcs.py b/gamestonk_terminal/helper_funcs.py index b6cc6118132..deb9b4ed8af 100644 --- a/gamestonk_terminal/helper_funcs.py +++ b/gamestonk_terminal/helper_funcs.py @@ -358,8 +358,10 @@ def get_flair() -> str: def str_to_bool(value): if isinstance(value, bool): return value - if value.lower() in {"false", "f", "0", "no", "n"}: - return False - elif value.lower() in {"true", "t", "1", "yes", "y"}: - return True + else: + if value.lower() in {"false", "f", "0", "no", "n"}: + return False + else value.lower() in {"true", "t", "1", "yes", "y"}: + return True + raise ValueError(f"{value} is not a valid boolean value") From ce8de70f8dd6fef0a0dabc3d56fa3b6e22587403 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 21:10:39 -0400 Subject: [PATCH 12/18] catch exception if required argument not given --- gamestonk_terminal/fred/fred_api.py | 3 ++- gamestonk_terminal/helper_funcs.py | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py index b96aceb8a94..bb3f87a31f0 100644 --- a/gamestonk_terminal/fred/fred_api.py +++ b/gamestonk_terminal/fred/fred_api.py @@ -135,7 +135,8 @@ def custom_data(l_args): print(e) print("") return - + except SystemExit: + print("") except Exception as e: print(e) print("") diff --git a/gamestonk_terminal/helper_funcs.py b/gamestonk_terminal/helper_funcs.py index deb9b4ed8af..9e243ff2b4a 100644 --- a/gamestonk_terminal/helper_funcs.py +++ b/gamestonk_terminal/helper_funcs.py @@ -358,10 +358,9 @@ def get_flair() -> str: def str_to_bool(value): if isinstance(value, bool): return value + elif value.lower() in {"false", "f", "0", "no", "n"}: + return False + elif value.lower() in {"true", "t", "1", "yes", "y"}: + return True else: - if value.lower() in {"false", "f", "0", "no", "n"}: - return False - else value.lower() in {"true", "t", "1", "yes", "y"}: - return True - - raise ValueError(f"{value} is not a valid boolean value") + raise ValueError(f"{value} is not a valid boolean value") From 76ebd3031d989137be251635d68c3f4fef09724e Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 21:25:35 -0400 Subject: [PATCH 13/18] lint --- gamestonk_terminal/fred/fred_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py index bb3f87a31f0..1f4ac4479d7 100644 --- a/gamestonk_terminal/fred/fred_api.py +++ b/gamestonk_terminal/fred/fred_api.py @@ -136,7 +136,7 @@ def custom_data(l_args): print("") return except SystemExit: - print("") + print("") except Exception as e: print(e) print("") From df8ec83b3b91a237fe63c9bc1c64ae3bdffc4d1e Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 21:26:29 -0400 Subject: [PATCH 14/18] rebase + lint --- gamestonk_terminal/helper_funcs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gamestonk_terminal/helper_funcs.py b/gamestonk_terminal/helper_funcs.py index f18c6f4f6af..e0c97197290 100644 --- a/gamestonk_terminal/helper_funcs.py +++ b/gamestonk_terminal/helper_funcs.py @@ -367,6 +367,7 @@ def str_to_bool(value): else: raise ValueError(f"{value} is not a valid boolean value") + def get_screeninfo(): screens = get_monitors() # Get all available monitors if len(screens) - 1 < cfgPlot.MONITOR: # Check to see if chosen monitor is detected From b27987606b3b8e3abd42afeb841a0046d167dfa4 Mon Sep 17 00:00:00 2001 From: Jamie Date: Tue, 16 Mar 2021 21:31:07 -0400 Subject: [PATCH 15/18] pylint --- gamestonk_terminal/helper_funcs.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/gamestonk_terminal/helper_funcs.py b/gamestonk_terminal/helper_funcs.py index e0c97197290..1f0ab039d11 100644 --- a/gamestonk_terminal/helper_funcs.py +++ b/gamestonk_terminal/helper_funcs.py @@ -360,12 +360,11 @@ def get_flair() -> str: def str_to_bool(value): if isinstance(value, bool): return value - elif value.lower() in {"false", "f", "0", "no", "n"}: + if value.lower() in {"false", "f", "0", "no", "n"}: return False - elif value.lower() in {"true", "t", "1", "yes", "y"}: + if value.lower() in {"true", "t", "1", "yes", "y"}: return True - else: - raise ValueError(f"{value} is not a valid boolean value") + raise ValueError(f"{value} is not a valid boolean value") def get_screeninfo(): From 4ff3a0cd39d5a9b9a53209606e6e1fdf866efa99 Mon Sep 17 00:00:00 2001 From: Jamie Date: Wed, 17 Mar 2021 12:25:36 -0400 Subject: [PATCH 16/18] Plotting changes, flag updates. --- gamestonk_terminal/fred/README.md | 119 ++++++++++++++------------- gamestonk_terminal/fred/fred_api.py | 109 +++++++++++++++--------- gamestonk_terminal/fred/fred_menu.py | 4 +- 3 files changed, 131 insertions(+), 101 deletions(-) diff --git a/gamestonk_terminal/fred/README.md b/gamestonk_terminal/fred/README.md index 2343af81ae0..504412b7457 100644 --- a/gamestonk_terminal/fred/README.md +++ b/gamestonk_terminal/fred/README.md @@ -9,12 +9,13 @@ The purpose of fred is to have the ability to look at economic data. ## gdp ```text -usage: gdp [-n N_TO_GET] [-s START_DATE] [-p PLOT]] +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 -* -p : Option to plot. Defaults to False +* --noplot : Flag to hide plot +* --hidedata : Flag to suppress printing output To get and plot the last 20 reported GDP values: ```` @@ -22,34 +23,32 @@ gdp -n 20 ```` To show all GDP data since 1/1/2016, with no plot. ```` -gdp -s 2016-01-01 -p False +gdp -s 2016-01-01 --noplot ```` +Outputs: ```` -Date: 01-01-2015, GDP: 18003.399 -Date: 04-01-2015, GDP: 18223.577 -Date: 07-01-2015, GDP: 18347.425 -Date: 10-01-2015, GDP: 18378.803 -Date: 01-01-2016, GDP: 18470.156 -Date: 04-01-2016, GDP: 18656.207 -Date: 07-01-2016, GDP: 18821.359 -Date: 10-01-2016, GDP: 19032.58 -Date: 01-01-2017, GDP: 19237.435 -Date: 04-01-2017, GDP: 19379.232 -Date: 07-01-2017, GDP: 19617.288 -Date: 10-01-2017, GDP: 19937.963 -Date: 01-01-2018, GDP: 20242.215 -Date: 04-01-2018, GDP: 20552.653 -Date: 07-01-2018, GDP: 20742.723 -Date: 10-01-2018, GDP: 20909.853 -Date: 01-01-2019, GDP: 21115.309 -Date: 04-01-2019, GDP: 21329.877 -Date: 07-01-2019, GDP: 21540.325 -Date: 10-01-2019, GDP: 21747.394 -Date: 01-01-2020, GDP: 21561.139 -Date: 04-01-2020, GDP: 19520.114 -Date: 07-01-2020, GDP: 21170.252 -Date: 10-01-2020, GDP: 21487.896 - + GDP +Date +2016-01-01 18470.156 +2016-04-01 18656.207 +2016-07-01 18821.359 +2016-10-01 19032.580 +2017-01-01 19237.435 +2017-04-01 19379.232 +2017-07-01 19617.288 +2017-10-01 19937.963 +2018-01-01 20242.215 +2018-04-01 20552.653 +2018-07-01 20742.723 +2018-10-01 20909.853 +2019-01-01 21115.309 +2019-04-01 21329.877 +2019-07-01 21540.325 +2019-10-01 21747.394 +2020-01-01 21561.139 +2020-04-01 19520.114 +2020-07-01 21170.252 +2020-10-01 21487.896 ```` @@ -58,46 +57,48 @@ Date: 10-01-2020, GDP: 21487.896 The fred database has many different datasets freely available. They each have their own custom SERIES_ID which can be obtained through the website. ```` -usage: cust [-id] [-s START_DATE] [-p PLOT] [-disp DISP] +usage: cust [-i --id] [-s START_DATE] [--noplot] [--hidedata] ```` -* -id : Series ID for FRED data. Required argument +* -i/--id : Series ID for FRED data. Required argument * -s : Start Date. Format YYYY-mm-dd. First point to get. Defaults to Jan 1 2015. -* -p : Option to plot. Defaults to True -* -disp : Option to print data to console. Defaults to False. +* --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 ```` -cust -id UNRATE -s 2019-01-01 -disp True +cust --id UNRATE -s 2019-01-01 ```` This will plot and display: ```` -Date: 01-01-2019, DATA: 4.0 -Date: 02-01-2019, DATA: 3.8 -Date: 03-01-2019, DATA: 3.8 -Date: 04-01-2019, DATA: 3.7 -Date: 05-01-2019, DATA: 3.7 -Date: 06-01-2019, DATA: 3.6 -Date: 07-01-2019, DATA: 3.6 -Date: 08-01-2019, DATA: 3.7 -Date: 09-01-2019, DATA: 3.5 -Date: 10-01-2019, DATA: 3.6 -Date: 11-01-2019, DATA: 3.6 -Date: 12-01-2019, DATA: 3.6 -Date: 01-01-2020, DATA: 3.5 -Date: 02-01-2020, DATA: 3.5 -Date: 03-01-2020, DATA: 4.4 -Date: 04-01-2020, DATA: 14.8 -Date: 05-01-2020, DATA: 13.3 -Date: 06-01-2020, DATA: 11.1 -Date: 07-01-2020, DATA: 10.2 -Date: 08-01-2020, DATA: 8.4 -Date: 09-01-2020, DATA: 7.8 -Date: 10-01-2020, DATA: 6.9 -Date: 11-01-2020, DATA: 6.7 -Date: 12-01-2020, DATA: 6.7 -Date: 01-01-2021, DATA: 6.3 -Date: 02-01-2021, DATA: 6.2 + 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 diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py index 1f4ac4479d7..e5fce3a148a 100644 --- a/gamestonk_terminal/fred/fred_api.py +++ b/gamestonk_terminal/fred/fred_api.py @@ -1,12 +1,18 @@ -from fredapi import Fred import argparse +import pandas as pd +from pandas.plotting import register_matplotlib_converters import matplotlib.pyplot as plt +from fredapi import Fred from gamestonk_terminal.helper_funcs import ( parse_known_args_and_warn, valid_date, - str_to_bool, + plot_autoscale, ) +from gamestonk_terminal.config_plot import PLOT_DPI from gamestonk_terminal.config_terminal import API_FRED_KEY +from gamestonk_terminal import feature_flags as gtff + +register_matplotlib_converters() def get_GDP(l_args): @@ -37,12 +43,19 @@ def get_GDP(l_args): ) parser.add_argument( - "-p", - dest="plot", - type=str_to_bool, + "--noplot", + action="store_false", default=True, - required=False, - help="Plot GDP", + dest="noplot", + help="Suppress output plot", + ) + + parser.add_argument( + "--hidedata", + action="store_false", + default=True, + dest="hidedata", + help="Suppress data display plot", ) try: @@ -52,22 +65,30 @@ def get_GDP(l_args): 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 - for date, val in lastn.iteritems(): - print(f'Date: {date.strftime("%m-%d-%Y")}, GDP: {val} ') + if ns_parser.hidedata: + print(lastn) + print("") - if ns_parser.plot: - plt.figure() - lastn.plot(style="-ok") + if ns_parser.noplot: + plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI) + plt.plot(lastn.index, lastn.GDP, "-ok") plt.xlabel("Time") - plt.ylabel("GDP") + plt.xlim(lastn.index[0], lastn.index[-1]) + plt.ylabel("GDP (bn $)") + plt.title("FRED GDP Data (in Billions of USD)") + 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.show() + print("") except Exception as e: print(e) @@ -86,7 +107,7 @@ def custom_data(l_args): """, ) parser.add_argument( - "-id", dest="series_id", required=True, type=str, help="FRED Series ID" + "-i", "--id", dest="series_id", required=True, type=str, help="FRED Series ID" ) parser.add_argument( @@ -95,23 +116,23 @@ def custom_data(l_args): type=valid_date, default="2015-01-01", required=False, - help="Date to Start", + help="Starting date (YYYY-MM-DD) of data", ) + parser.add_argument( - "-p", - dest="plot", - type=str_to_bool, + "--noplot", + action="store_false", default=True, - required=False, - help="Plot data", + dest="noplot", + help="Suppress output plot", ) + parser.add_argument( - "-disp", - dest="disp", - type=str_to_bool, - default=False, - required=False, - help="Print data", + "--hidedata", + action="store_false", + default=True, + dest="hidedata", + help="Suppress data display plot", ) try: @@ -121,20 +142,28 @@ def custom_data(l_args): return data = fred.get_series(ns_parser.series_id, ns_parser.start_date) - if ns_parser.disp: - for date, val in data.iteritems(): - print(f'Date: {date.strftime("%m-%d-%Y")}, DATA: {val} ') - try: - if ns_parser.plot: - plt.figure() - data.plot(style="-ok") - plt.xlabel("Time") - plt.ylabel("DATA") - plt.show() - except Exception as e: - print(e) + + data = pd.DataFrame(data, columns=[f"{ns_parser.series_id}"]) + data.index.name = "Date" + if ns_parser.hidedata: + print(data) print("") - return + if ns_parser.noplot: + plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI) + plt.plot(data.index, data.iloc[:, 0], "-ok") + plt.xlabel("Time") + plt.xlim(data.index[0], data.index[-1]) + plt.ylabel(f"{ns_parser.series_id}") + 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(f"FRED {ns_parser.series_id} Series") + plt.show() + print("") + + if gtff.USE_ION: + plt.ion() + except SystemExit: print("") except Exception as e: diff --git a/gamestonk_terminal/fred/fred_menu.py b/gamestonk_terminal/fred/fred_menu.py index f7f2d427fad..6c554fd0322 100644 --- a/gamestonk_terminal/fred/fred_menu.py +++ b/gamestonk_terminal/fred/fred_menu.py @@ -1,9 +1,8 @@ import argparse - +from prompt_toolkit.completion import NestedCompleter from gamestonk_terminal import feature_flags as gtff from gamestonk_terminal.helper_funcs import get_flair from gamestonk_terminal.menu import session -from prompt_toolkit.completion import NestedCompleter from gamestonk_terminal.fred import fred_api @@ -17,6 +16,7 @@ def print_fred(): print(" ") print(" gdp get GDP") print(" cust User Specified FRED Data") + print("") return From 1d4ca8065115ac65ffd207b8c3513edcee1fe8d3 Mon Sep 17 00:00:00 2001 From: Jamie Date: Wed, 17 Mar 2021 13:57:01 -0400 Subject: [PATCH 17/18] added more options for available series - more user friendly? --- gamestonk_terminal/fred/README.md | 109 +++++++++++++++------------ gamestonk_terminal/fred/fred_api.py | 75 +++++++++++------- gamestonk_terminal/fred/fred_menu.py | 31 ++++++-- 3 files changed, 134 insertions(+), 81 deletions(-) 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) From 69745672605f841fef97268c40da32bbc45d9575 Mon Sep 17 00:00:00 2001 From: Jamie Date: Wed, 17 Mar 2021 14:50:05 -0400 Subject: [PATCH 18/18] change options + README --- gamestonk_terminal/fred/README.md | 9 +++++++-- gamestonk_terminal/fred/fred_api.py | 18 ++++++++++-------- gamestonk_terminal/fred/fred_menu.py | 16 ++++++++++------ 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/gamestonk_terminal/fred/README.md b/gamestonk_terminal/fred/README.md index 51b71a957fb..f781a1ac1e4 100644 --- a/gamestonk_terminal/fred/README.md +++ b/gamestonk_terminal/fred/README.md @@ -14,8 +14,9 @@ The current predefined options are * 1,5,10,30 Year Treasury Rates * 30 Year Mortgage Rates * Unemployment Rate -* 3 Month LIBOR +* Effective Federal Funds rate * Moody's AAA Corporate Bond +* CAD to USD Conversion. ## predefined ```text @@ -31,6 +32,9 @@ To plot the 30-Year Mortgage rates since 2018-01-01 suppressing the output. ```` mort30 -s 2018-01-01 --hidedata ```` + +![mort30](https://user-images.githubusercontent.com/18151143/111521185-3d80dc80-872f-11eb-989d-c2bb256aa213.png) + To show all GDP data since 1/1/2016, with no plot. ```` gdp -s 2016-01-01 --noplot @@ -78,9 +82,10 @@ 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 2021-02-01 +cust --id DEXUSEU -s 2021-02-01 ```` This will plot and display: +![cust](https://user-images.githubusercontent.com/18151143/111521481-92bcee00-872f-11eb-8a02-e7346e56e462.png) ```` DEXUSEU diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py index 490c152c7f8..1b90ca10e87 100644 --- a/gamestonk_terminal/fred/fred_api.py +++ b/gamestonk_terminal/fred/fred_api.py @@ -17,23 +17,25 @@ register_matplotlib_converters() api_map = { "gdp": "GDP", "t10": "DGS10", - "t01": "DGS1", - "t05": "DGS5", + "t1": "DGS1", + "t5": "DGS5", "t30": "DGS30", "mort30": "MORTGAGE30US", - "libor3m": "USD3MTD156N", + "fedrate": "FEDFUNDS", "moodAAA": "AAA", + "usdcad": "DEXCAUS", "unemp": "UNRATE", } title_map = { - "gdp": "GDP", + "gdp": "Gross Domestic Product", "t10": "10-Year Treasury Constant Maturity Rate", - "t01": "1-Year Treasury Constant Maturity Rate", - "t05": "5-Year Treasury Constant Maturity Rate", + "t1": "1-Year Treasury Constant Maturity Rate", + "t5": "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", + "mort30": "30-Year Mortgage Rate", + "fedrate": "Effective Federal Funds Rate", "moodAAA": "Moody's Seasoned AAA Corporate Bond Yield", + "usdcad": "Canada / U.S. Foreign Exchange Rate", "unemp": "Unemployment Rate", } diff --git a/gamestonk_terminal/fred/fred_menu.py b/gamestonk_terminal/fred/fred_menu.py index 1c0137d740b..5a7734835be 100644 --- a/gamestonk_terminal/fred/fred_menu.py +++ b/gamestonk_terminal/fred/fred_menu.py @@ -1,4 +1,5 @@ import argparse +from matplotlib import pyplot as plt from prompt_toolkit.completion import NestedCompleter from gamestonk_terminal import feature_flags as gtff from gamestonk_terminal.helper_funcs import get_flair @@ -16,13 +17,14 @@ def print_fred(): print(" ") print(" gdp GDP") print(" unemp Unemployment Rate") - print(" t01 1-Year Treasury Constant Maturity Rate") - print(" t05 5-Year Treasury Constant Maturity Rate") + print(" t1 1-Year Treasury Constant Maturity Rate") + print(" t5 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(" fedrate Effective Federal Funds Rate") print(" moodAAA Moody's Seasoned AAA Corporate Bond Yield") + print(" usdcad Canada / U.S. Foreign Exchange Rate (CAD per 1 USD)") print("") print(" cust User Specified FRED Data - Please Specify --id") print("") @@ -30,17 +32,19 @@ def print_fred(): def fred_menu(): + plt.close("all") fred_parser = argparse.ArgumentParser(prog="fred", add_help=False) defined_choices = [ "gdp", "unemp", - "t01", - "t05", + "t1", + "t5", "t10", "t30", "mort30", - "libor3m", + "fedrate", "moodAAA", + "usdcad", ] choices = ["help", "q", "quit", "cust"] + defined_choices