diff --git a/gamestonk_terminal/econometrics/econometrics_controller.py b/gamestonk_terminal/econometrics/econometrics_controller.py index e0597f8650d..dc6fd40fc4a 100644 --- a/gamestonk_terminal/econometrics/econometrics_controller.py +++ b/gamestonk_terminal/econometrics/econometrics_controller.py @@ -479,15 +479,6 @@ Tests help="The name of the database you want to show data for", ) - parser.add_argument( - "-l", - "--limit", - type=int, - dest="limit", - help="The amount of data you wish to show", - default=10, - ) - parser.add_argument( "-s", "--sortcol", @@ -509,7 +500,7 @@ Tests if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-n") ns_parser = parse_known_args_and_warn( - parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED + parser, other_args, EXPORT_ONLY_RAW_DATA_ALLOWED, limit=10 ) if ns_parser: @@ -779,19 +770,9 @@ Tests default="", ) - parser.add_argument( - "-l", - "--limit", - help="The max amount of columns/rows backward filled or forward filled that have NaNs or " - "the max amount of columns/rows that have NaNs before being dropped.", - dest="limit", - type=int, - default=5, - ) - if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-n") - ns_parser = parse_known_args_and_warn(parser, other_args, NO_EXPORT) + ns_parser = parse_known_args_and_warn(parser, other_args, NO_EXPORT, limit=5) if ns_parser: if not ns_parser.name or ns_parser.name not in self.datasets: diff --git a/gamestonk_terminal/economy/econdb_model.py b/gamestonk_terminal/economy/econdb_model.py index 2198620dc85..ed49f05b10a 100644 --- a/gamestonk_terminal/economy/econdb_model.py +++ b/gamestonk_terminal/economy/econdb_model.py @@ -429,3 +429,29 @@ def get_treasuries( ) return treasury_data + + +@log_start_end(log=logger) +def obtain_treasury_maturities(treasuries: Dict) -> pd.DataFrame: + """Obtain treasury maturity options [Source: EconDB] + + Parameters + ---------- + treasuries: dict + A dictionary containing the options structured {instrument : {maturities: {abbreviation : name}}} + + Returns + ---------- + df: pd.DataFrame + Contains the name of the instruments and a string containing all options. + """ + + instrument_maturities = { + instrument: ", ".join(values["maturities"].keys()) + for instrument, values in treasuries["instruments"].items() + } + + df = pd.DataFrame.from_dict(instrument_maturities, orient="index") + df.loc["average"] = "Defined by function" + + return df diff --git a/gamestonk_terminal/economy/econdb_view.py b/gamestonk_terminal/economy/econdb_view.py index 5c41c8ef652..6e710f50525 100644 --- a/gamestonk_terminal/economy/econdb_view.py +++ b/gamestonk_terminal/economy/econdb_view.py @@ -12,6 +12,7 @@ from gamestonk_terminal.config_terminal import theme from gamestonk_terminal.decorators import log_start_end from gamestonk_terminal.economy import econdb_model from gamestonk_terminal.helper_funcs import plot_autoscale, print_rich_table +from gamestonk_terminal.rich_config import console logger = logging.getLogger(__name__) @@ -195,3 +196,30 @@ def show_treasuries( if external_axes is None: theme.visualize_output() + + +@log_start_end(log=logger) +def show_treasury_maturities(treasuries: Dict): + """Obtain treasury maturity options [Source: EconDB] + + Parameters + ---------- + treasuries: dict + A dictionary containing the options structured {instrument : {maturities: {abbreviation : name}}} + + Returns + ---------- + A table containing the instruments and maturities. + """ + + instrument_maturities = econdb_model.obtain_treasury_maturities(treasuries) + + print_rich_table( + instrument_maturities, + headers=list(["Maturities"]), + show_index=True, + index_name="Instrument", + title="Maturity options per instrument", + ) + + console.print() diff --git a/gamestonk_terminal/economy/economy_controller.py b/gamestonk_terminal/economy/economy_controller.py index a97974f6bba..c9a474b146a 100644 --- a/gamestonk_terminal/economy/economy_controller.py +++ b/gamestonk_terminal/economy/economy_controller.py @@ -34,7 +34,6 @@ from gamestonk_terminal.helper_funcs import ( parse_known_args_and_warn, print_rich_table, valid_date, - check_positive, ) from gamestonk_terminal.menu import session from gamestonk_terminal.parent_classes import BaseController @@ -426,17 +425,8 @@ Index default="USD", ) - parser.add_argument( - "-r", - "--raw", - dest="raw", - help="Show raw data", - action="store_true", - default=False, - ) - ns_parser = parse_known_args_and_warn( - parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED + parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED, raw=True ) if ns_parser: if ns_parser.show_parameters: @@ -496,27 +486,14 @@ Index help="Query the FRED database to obtain Series IDs given the query seaarch term.", ) - parser.add_argument( - "-l", - "--limit", - dest="limit", - help="Number of rows to show for limit", - type=check_positive, - default=5, - ) - - parser.add_argument( - "--raw", - help="Flag to show raw data", - dest="raw", - action="store_true", - default=False, - ) - if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-p") ns_parser = parse_known_args_and_warn( - parser, other_args, export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES + parser, + other_args, + export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES, + raw=True, + limit=5, ) if ns_parser: if ns_parser.query: @@ -633,28 +610,14 @@ Index help="Search for indices with given keyword", ) - parser.add_argument( - "-l", - "--limit", - type=str, - dest="limit", - help="Takes into account the amount of rows you wish to see for your query ('-q').", - default=10, - ) - - parser.add_argument( - "-r", - "--raw", - dest="raw", - help="Show raw data", - action="store_true", - default=False, - ) - if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-i") ns_parser = parse_known_args_and_warn( - parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED + parser, + other_args, + export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED, + raw=True, + limit=10, ) if ns_parser: if ns_parser.query and ns_parser.limit: @@ -697,7 +660,16 @@ Index type=str, dest="maturity", help="The preferred maturity which is dependent on the type of the treasury", - default="1y", + default=["1y"], + ) + + parser.add_argument( + "-sm", + "--show_maturities", + dest="show_maturities", + help="Show the maturities available for every instrument.", + action="store_true", + default=False, ) parser.add_argument( @@ -719,14 +691,14 @@ Index choices=econdb_model.TREASURIES["instruments"], help="Whether to select nominal, inflation indexed, average inflation indexed or " "secondary market treasury rates", - default="nominal", + default=["nominal"], ) parser.add_argument( "-s", "--start_date", dest="start_date", - help="The start date of the data (format: YEAR-DAY-MONTH, i.e. 2010-31-12)", + help="The start date of the data (format: YEAR-MONTH-DAY, i.e. 2010-12-31)", default="1934-01-31", ) @@ -734,43 +706,32 @@ Index "-e", "--end_date", dest="end_date", - help="The end date of the data (format: YEAR-DAY-MONTH, i.e. 2021-20-06)", + help="The end date of the data (format: YEAR-DAY-MONTH, i.e. 2021-06-02)", default=date.today(), ) - parser.add_argument( - "-l", - "--limit", - type=str, - dest="limit", - help="Takes into account the amount of rows you wish to see for your query ('-q').", - default=10, - ) - - parser.add_argument( - "-r", - "--raw", - dest="raw", - help="Show raw data", - action="store_true", - default=False, - ) - if other_args and "-" not in other_args[0][0]: other_args.insert(0, "-m") ns_parser = parse_known_args_and_warn( - parser, other_args, export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED + parser, + other_args, + export_allowed=EXPORT_ONLY_RAW_DATA_ALLOWED, + raw=True, + limit=10, ) - if ns_parser and ns_parser.maturity and ns_parser.type: - econdb_view.show_treasuries( - types=ns_parser.type, - maturities=ns_parser.maturity, - frequency=ns_parser.frequency, - start_date=ns_parser.start_date, - end_date=ns_parser.end_date, - raw=ns_parser.raw, - ) + if ns_parser: + if ns_parser.show_maturities: + econdb_view.show_treasury_maturities(econdb_model.TREASURIES) + elif ns_parser.maturity and ns_parser.type: + econdb_view.show_treasuries( + types=ns_parser.type, + maturities=ns_parser.maturity, + frequency=ns_parser.frequency, + start_date=ns_parser.start_date, + end_date=ns_parser.end_date, + raw=ns_parser.raw, + ) @log_start_end(log=logger) def call_map(self, other_args: List[str]): @@ -971,14 +932,12 @@ Index S&P500 incumbents. Pops plot in terminal. [Source: Alpha Vantage] """, ) - parser.add_argument( - "--raw", - action="store_true", - dest="raw", - help="Only output raw data", - ) + ns_parser = parse_known_args_and_warn( - parser, other_args, export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES + parser, + other_args, + export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES, + raw=True, ) if ns_parser: alphavantage_view.realtime_performance_sector( @@ -1012,15 +971,12 @@ Index default="USA", type=nasdaq_model.check_country_code_type, ) - parser.add_argument( - "--raw", - action="store_true", - default=False, - help="Show raw data", - dest="raw", - ) + ns_parser = parse_known_args_and_warn( - parser, other_args, export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES + parser, + other_args, + export_allowed=EXPORT_BOTH_RAW_DATA_AND_FIGURES, + raw=True, ) if ns_parser: if ns_parser.codes: