From 4c6d298f485265c120c025a6105d67b76187b0e6 Mon Sep 17 00:00:00 2001 From: Artem Veremey Date: Wed, 31 Mar 2021 16:04:28 -0700 Subject: [PATCH 1/5] Removing failing test --- tests/test_sentiment_twitter_api.py | 32 ----------------------------- 1 file changed, 32 deletions(-) delete mode 100644 tests/test_sentiment_twitter_api.py diff --git a/tests/test_sentiment_twitter_api.py b/tests/test_sentiment_twitter_api.py deleted file mode 100644 index ffe00494486..00000000000 --- a/tests/test_sentiment_twitter_api.py +++ /dev/null @@ -1,32 +0,0 @@ -""" sentiment/twitter_api.py """ -# flake8: noqa: F401 -import unittest - -# pylint: disable=unused-import -try: - from gamestonk_terminal.behavioural_analysis.twitter_view import ( - inference, - sentiment, - ) -except ModuleNotFoundError as e: - print("One of the optional packages seems to be missing") - print(e) - print("Skipping the test") - -from gamestonk_terminal import feature_flags as gtff - - -class TestSentimentTwitterApi(unittest.TestCase): - def test_inference(self): - if not gtff.ENABLE_PREDICT: - return - # Fix: implement a better twitter client - # inference([], "PLTR") - return - - def test_sentiment(self): - if not gtff.ENABLE_PREDICT: - return - # Fix: implement a better twitter client - # sentiment([], "PLTR") - return From 0faae013c79d3e36f9dad4565d59f50fa57aef91 Mon Sep 17 00:00:00 2001 From: Artem Veremey Date: Wed, 31 Mar 2021 16:27:25 -0700 Subject: [PATCH 2/5] Trying to pin numpy version to 1.19.5 --- .github/workflows/Mac.yml | 1 + .github/workflows/windows.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/Mac.yml b/.github/workflows/Mac.yml index 996a29b56f8..75a8a6f540b 100644 --- a/.github/workflows/Mac.yml +++ b/.github/workflows/Mac.yml @@ -45,6 +45,7 @@ jobs: - name: Install gensim with conda shell: bash -l {0} run: | + conda install numpy=1.19.5 conda install gensim=3.8.3 - name: Install dependencies (Bash) diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 3e469e6fddf..93723499e8c 100755 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -51,6 +51,7 @@ jobs: - name: Install fbprophet with conda shell: bash -l {0} run: | + conda install numpy=1.19.5 conda install -c conda-forge fbprophet=0.6 conda install spyder conda install gensim=3.8.3 From 7862b39ce0aa3bb2a1bf639da58bfb327beee826 Mon Sep 17 00:00:00 2001 From: Artem Veremey Date: Thu, 1 Apr 2021 09:20:25 -0700 Subject: [PATCH 3/5] Refactoring Fred menu as a controller --- gamestonk_terminal/fred/__init__.py | 1 + gamestonk_terminal/fred/fred_api.py | 5 +- gamestonk_terminal/fred/fred_controller.py | 189 +++++++++++++++++++++ gamestonk_terminal/fred/fred_menu.py | 90 ---------- terminal.py | 4 +- 5 files changed, 195 insertions(+), 94 deletions(-) create mode 100644 gamestonk_terminal/fred/fred_controller.py delete mode 100644 gamestonk_terminal/fred/fred_menu.py diff --git a/gamestonk_terminal/fred/__init__.py b/gamestonk_terminal/fred/__init__.py index e69de29bb2d..844e04cb87e 100644 --- a/gamestonk_terminal/fred/__init__.py +++ b/gamestonk_terminal/fred/__init__.py @@ -0,0 +1 @@ +from . import fred_controller # noqa: F401 diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py index 1b90ca10e87..d707ed85f84 100644 --- a/gamestonk_terminal/fred/fred_api.py +++ b/gamestonk_terminal/fred/fred_api.py @@ -26,6 +26,7 @@ api_map = { "usdcad": "DEXCAUS", "unemp": "UNRATE", } + title_map = { "gdp": "Gross Domestic Product", "t10": "10-Year Treasury Constant Maturity Rate", @@ -47,8 +48,8 @@ def get_fred_data(l_args, choice): add_help=False, prog="Custom", description=""" - Custom Data - """, + Custom Data + """, ) parser.add_argument( diff --git a/gamestonk_terminal/fred/fred_controller.py b/gamestonk_terminal/fred/fred_controller.py new file mode 100644 index 00000000000..08e2c4c7a63 --- /dev/null +++ b/gamestonk_terminal/fred/fred_controller.py @@ -0,0 +1,189 @@ +""" Disc Controller """ +__docformat__ = "numpy" + +import argparse +from typing import List +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 +from gamestonk_terminal.menu import session +from gamestonk_terminal.fred import fred_api + + +class FredCotroller: + """ Fred Controller """ + + # Command choices + CHOICES = [ + "help", + "q", + "quit", + "gdp", + "unemp", + "t1", + "t5", + "t10", + "t30", + "mort30", + "fedrate", + "moodAAA", + "usdcad", + "cust", + ] + + def __init__(self): + """Constructor""" + self.disc_parser = argparse.ArgumentParser(add_help=False, prog="fred") + self.disc_parser.add_argument( + "cmd", + choices=self.CHOICES, + ) + + @staticmethod + def print_help(): + """ Print help """ + + 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 GDP") + print(" unemp Unemployment 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(" 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("") + return + + def switch(self, an_input: str): + """Process and dispatch input + + Returns + ------- + True, False or None + False - quit the menu + True - quit the program + None - continue in the menu + """ + (known_args, other_args) = self.disc_parser.parse_known_args(an_input.split()) + + fred_data_list = [ + "gdp", + "unemp", + "t1", + "t5", + "t10", + "t30", + "mort30", + "fedrate", + "moodAAA", + "usdcad", + ] + + if known_args.cmd in fred_data_list: + return getattr(self, "call_fred_api")(other_args, known_args.cmd) + + return getattr( + self, "call_" + known_args.cmd, lambda: "Command not recognized!" + )(other_args) + + def call_help(self, _): + """Process Help command""" + self.print_help() + + def call_q(self, _): + """Process Q command - quit the menu""" + return False + + def call_quit(self, _): + """Process Quit command - quit the program""" + return True + + def call_fred_api(self, other_args: List[str], cmd: str): + """Process Fred Data call""" + fred_api.get_fred_data(other_args, cmd) + + def call_cust(self, other_args: List[str]): + """Process cust call""" + fred_api.custom_data(other_args) + + +def menu(): + """Fred Menu""" + + fred_controller = FredCotroller() + + plt.close("all") + # fred_parser = argparse.ArgumentParser(prog="fred", add_help=False) + # defined_choices = [ + # "gdp", + # "unemp", + # "t1", + # "t5", + # "t10", + # "t30", + # "mort30", + # "fedrate", + # "moodAAA", + # "usdcad", + # ] + # 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}) + + fred_controller.print_help() + + # Loop forever and ever + while True: + # Get input command from user + if session and gtff.USE_PROMPT_TOOLKIT: + completer = NestedCompleter.from_nested_dict( + {c: None for c in fred_controller.CHOICES} + ) + + an_input = session.prompt( + f"{get_flair()} (fred)> ", + completer=completer, + ) + else: + an_input = input(f"{get_flair()} (fred)> ") + try: + process_input = fred_controller.switch(an_input) + + if process_input is not None: + return process_input + + except SystemExit: + print("The command selected doesn't exist\n") + continue + + # 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": + # # Leave the fred menu + # return False + + # elif ns_known_args.cmd == "quit": + # # Abandon the program + # return True + + # 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) diff --git a/gamestonk_terminal/fred/fred_menu.py b/gamestonk_terminal/fred/fred_menu.py deleted file mode 100644 index 5a7734835be..00000000000 --- a/gamestonk_terminal/fred/fred_menu.py +++ /dev/null @@ -1,90 +0,0 @@ -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 -from gamestonk_terminal.menu import session -from gamestonk_terminal.fred import fred_api - - -def print_fred(): - """ Print help """ - - 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 GDP") - print(" unemp Unemployment 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(" 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("") - return - - -def fred_menu(): - plt.close("all") - fred_parser = argparse.ArgumentParser(prog="fred", add_help=False) - defined_choices = [ - "gdp", - "unemp", - "t1", - "t5", - "t10", - "t30", - "mort30", - "fedrate", - "moodAAA", - "usdcad", - ] - 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}) - - 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": - # Leave the fred menu - return False - - elif ns_known_args.cmd == "quit": - # Abandon the program - return True - - 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) diff --git a/terminal.py b/terminal.py index 524ebeb09c3..d27cd0f80d1 100644 --- a/terminal.py +++ b/terminal.py @@ -26,7 +26,7 @@ from gamestonk_terminal.technical_analysis import ta_controller from gamestonk_terminal.comparison_analysis import ca_controller from gamestonk_terminal.exploratory_data_analysis import eda_controller from gamestonk_terminal.options import op_controller -from gamestonk_terminal.fred import fred_menu as fm +from gamestonk_terminal.fred import fred_controller from gamestonk_terminal.residuals_analysis import ra_controller from gamestonk_terminal.portfolio import port_controller from gamestonk_terminal.cryptocurrency import crypto_controller @@ -231,7 +231,7 @@ def main(): b_quit = op_controller.menu(s_ticker) elif ns_known_args.opt == "fred": - b_quit = fm.fred_menu() + b_quit = fred_controller.menu() elif ns_known_args.opt == "pa": b_quit = port_controller.menu() From b12d63577f2177b0727aec7ba536dda77ad046dd Mon Sep 17 00:00:00 2001 From: Artem Veremey Date: Thu, 1 Apr 2021 09:22:56 -0700 Subject: [PATCH 4/5] Fixing spelling and removing comments --- gamestonk_terminal/fred/fred_api.py | 192 --------------------- gamestonk_terminal/fred/fred_controller.py | 48 +----- 2 files changed, 5 insertions(+), 235 deletions(-) delete mode 100644 gamestonk_terminal/fred/fred_api.py diff --git a/gamestonk_terminal/fred/fred_api.py b/gamestonk_terminal/fred/fred_api.py deleted file mode 100644 index d707ed85f84..00000000000 --- a/gamestonk_terminal/fred/fred_api.py +++ /dev/null @@ -1,192 +0,0 @@ -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, - 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() - -api_map = { - "gdp": "GDP", - "t10": "DGS10", - "t1": "DGS1", - "t5": "DGS5", - "t30": "DGS30", - "mort30": "MORTGAGE30US", - "fedrate": "FEDFUNDS", - "moodAAA": "AAA", - "usdcad": "DEXCAUS", - "unemp": "UNRATE", -} - -title_map = { - "gdp": "Gross Domestic Product", - "t10": "10-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 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", -} - - -def get_fred_data(l_args, choice): - fred = Fred(api_key=API_FRED_KEY) - - parser = argparse.ArgumentParser( - add_help=False, - prog="Custom", - description=""" - Custom Data - """, - ) - - parser.add_argument( - "-s", - dest="start_date", - type=valid_date, - default="2019-01-01", - required=False, - help="Starting date (YYYY-MM-DD) of data", - ) - - parser.add_argument( - "--noplot", - action="store_false", - default=True, - dest="noplot", - help="Suppress output plot", - ) - - parser.add_argument( - "--hidedata", - action="store_false", - default=True, - dest="hidedata", - help="Suppress data display plot", - ) - - try: - ns_parser = parse_known_args_and_warn(parser, l_args) - - if not ns_parser: - return - - 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(data) - print("") - 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"{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("") - return - - -def custom_data(l_args): - fred = Fred(api_key=API_FRED_KEY) - - parser = argparse.ArgumentParser( - add_help=False, - prog="Custom", - description=""" - Custom Data - """, - ) - parser.add_argument( - "-i", "--id", dest="series_id", required=True, type=str, help="FRED Series ID" - ) - - parser.add_argument( - "-s", - dest="start_date", - type=valid_date, - default="2019-01-01", - required=False, - help="Starting date (YYYY-MM-DD) of data", - ) - - parser.add_argument( - "--noplot", - action="store_false", - default=True, - dest="noplot", - help="Suppress output plot", - ) - - parser.add_argument( - "--hidedata", - action="store_false", - default=True, - dest="hidedata", - help="Suppress data display plot", - ) - - 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) - - data = pd.DataFrame(data, columns=[f"{ns_parser.series_id}"]) - data.index.name = "Date" - if ns_parser.hidedata: - print(data) - print("") - 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: - print(e) - print("") - return diff --git a/gamestonk_terminal/fred/fred_controller.py b/gamestonk_terminal/fred/fred_controller.py index 08e2c4c7a63..33698d04881 100644 --- a/gamestonk_terminal/fred/fred_controller.py +++ b/gamestonk_terminal/fred/fred_controller.py @@ -8,10 +8,10 @@ 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 gamestonk_terminal.fred import fred_api +from gamestonk_terminal.fred import fred_view -class FredCotroller: +class FredController: """ Fred Controller """ # Command choices @@ -110,36 +110,19 @@ class FredCotroller: def call_fred_api(self, other_args: List[str], cmd: str): """Process Fred Data call""" - fred_api.get_fred_data(other_args, cmd) + fred_view.get_fred_data(other_args, cmd) def call_cust(self, other_args: List[str]): """Process cust call""" - fred_api.custom_data(other_args) + fred_view.custom_data(other_args) def menu(): """Fred Menu""" - fred_controller = FredCotroller() + fred_controller = FredController() plt.close("all") - # fred_parser = argparse.ArgumentParser(prog="fred", add_help=False) - # defined_choices = [ - # "gdp", - # "unemp", - # "t1", - # "t5", - # "t10", - # "t30", - # "mort30", - # "fedrate", - # "moodAAA", - # "usdcad", - # ] - # 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}) fred_controller.print_help() @@ -166,24 +149,3 @@ def menu(): except SystemExit: print("The command selected doesn't exist\n") continue - - # 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": - # # Leave the fred menu - # return False - - # elif ns_known_args.cmd == "quit": - # # Abandon the program - # return True - - # 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 5719e78312036d83c736ed265b8d8180172468b3 Mon Sep 17 00:00:00 2001 From: Artem Veremey Date: Thu, 1 Apr 2021 09:30:23 -0700 Subject: [PATCH 5/5] Refactored fred_api as fred_view --- gamestonk_terminal/fred/fred_controller.py | 2 +- gamestonk_terminal/fred/fred_view.py | 214 +++++++++++++++++++++ 2 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 gamestonk_terminal/fred/fred_view.py diff --git a/gamestonk_terminal/fred/fred_controller.py b/gamestonk_terminal/fred/fred_controller.py index 33698d04881..0f3bf4990b0 100644 --- a/gamestonk_terminal/fred/fred_controller.py +++ b/gamestonk_terminal/fred/fred_controller.py @@ -1,4 +1,4 @@ -""" Disc Controller """ +""" Fred Controller """ __docformat__ = "numpy" import argparse diff --git a/gamestonk_terminal/fred/fred_view.py b/gamestonk_terminal/fred/fred_view.py new file mode 100644 index 00000000000..76f57f57a23 --- /dev/null +++ b/gamestonk_terminal/fred/fred_view.py @@ -0,0 +1,214 @@ +""" Fred View """ +__docformat__ = "numpy" + +import argparse +from typing import List +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, + 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() + +api_map = { + "gdp": "GDP", + "t10": "DGS10", + "t1": "DGS1", + "t5": "DGS5", + "t30": "DGS30", + "mort30": "MORTGAGE30US", + "fedrate": "FEDFUNDS", + "moodAAA": "AAA", + "usdcad": "DEXCAUS", + "unemp": "UNRATE", +} + +title_map = { + "gdp": "Gross Domestic Product", + "t10": "10-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 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", +} + + +def get_fred_data(other_args: List[str], choice: str): + """Displace Fred data and graph for a selected chosen data series + + Parameters + ---------- + other_args : List[str] + argparse other args + choice : str + Fred data series: "gdp","unemp", "t1", "t5", "t10", "t30", "mort30", + "fedrate", "moodAAA", "usdcad", + """ + + fred = Fred(api_key=API_FRED_KEY) + + parser = argparse.ArgumentParser( + add_help=False, + prog="Custom", + description=""" + Custom Data + """, + ) + + parser.add_argument( + "-s", + dest="start_date", + type=valid_date, + default="2019-01-01", + required=False, + help="Starting date (YYYY-MM-DD) of data", + ) + + parser.add_argument( + "--noplot", + action="store_false", + default=True, + dest="noplot", + help="Suppress output plot", + ) + + parser.add_argument( + "--hidedata", + action="store_false", + default=True, + dest="hidedata", + help="Suppress data display plot", + ) + + try: + ns_parser = parse_known_args_and_warn(parser, other_args) + + if not ns_parser: + return + + 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(data) + print("") + 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"{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("") + return + + +def custom_data(other_args: List[str]): + """Displace Fred data for a custom series request + + Parameters + ---------- + other_args : List[str] + argparse other args + """ + fred = Fred(api_key=API_FRED_KEY) + + parser = argparse.ArgumentParser( + add_help=False, + prog="Custom", + description=""" + Custom Data + """, + ) + parser.add_argument( + "-i", "--id", dest="series_id", required=True, type=str, help="FRED Series ID" + ) + + parser.add_argument( + "-s", + dest="start_date", + type=valid_date, + default="2019-01-01", + required=False, + help="Starting date (YYYY-MM-DD) of data", + ) + + parser.add_argument( + "--noplot", + action="store_false", + default=True, + dest="noplot", + help="Suppress output plot", + ) + + parser.add_argument( + "--hidedata", + action="store_false", + default=True, + dest="hidedata", + help="Suppress data display plot", + ) + + try: + ns_parser = parse_known_args_and_warn(parser, other_args) + + if not ns_parser: + return + + data = fred.get_series(ns_parser.series_id, ns_parser.start_date) + + data = pd.DataFrame(data, columns=[f"{ns_parser.series_id}"]) + data.index.name = "Date" + if ns_parser.hidedata: + print(data) + print("") + 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: + print(e) + print("") + return