From 3d0a032a763319bceb39ff524d77e393408ebd5a Mon Sep 17 00:00:00 2001 From: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Date: Tue, 1 Nov 2022 01:45:54 +0100 Subject: [PATCH] Fix Some Econometrics Bugs (#3210) * Added suggestions for load * Fixed a command * Fixed panel Co-authored-by: Henrique Joaquim Co-authored-by: James Maslek --- .../econometrics/econometrics_controller.py | 40 +++++++++++++++---- .../terminal/econometrics/coint/_index.md | 2 +- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/openbb_terminal/econometrics/econometrics_controller.py b/openbb_terminal/econometrics/econometrics_controller.py index 4fbaae83d43..f76d8414df9 100644 --- a/openbb_terminal/econometrics/econometrics_controller.py +++ b/openbb_terminal/econometrics/econometrics_controller.py @@ -174,7 +174,14 @@ class EconometricsController(BaseController): if session and obbff.USE_PROMPT_TOOLKIT: choices: dict = {c: {} for c in self.controller_choices} - choices["load"]["-f"] = {c: {} for c in self.DATA_FILES.keys()} + choices["load"] = { + "--file": {c: {} for c in self.DATA_FILES.keys()}, + "-f": "--file", + "-alias": None, + "-a": "-alias", + "--examples": None, + "-e": "--examples", + } for feature in ["export", "show", "desc", "clear", "index"]: choices[feature] = {c: {} for c in self.files} @@ -351,6 +358,7 @@ class EconometricsController(BaseController): and "-e" not in other_args and "-f" not in other_args and "-h" not in other_args + and "--file" not in other_args ): other_args.insert(0, "-f") @@ -1283,12 +1291,12 @@ class EconometricsController(BaseController): ) if ns_parser and ns_parser.column: - column, dataset = self.choices["norm"][ns_parser.column].keys() + dataset, column = ns_parser.column.split(".") if isinstance(self.datasets[dataset][column].index, pd.MultiIndex): return console.print( - f"The column '{column}' from the dataset '{dataset}' is a MultiIndex. To test for normality in a " - "timeseries, make sure to set a singular time index.\n" + f"The column '{column}' in '{dataset}' is a MultiIndex. To test for normality" + ", make sure to set a singular time index.\n" ) if dataset in self.datasets: @@ -1352,7 +1360,12 @@ class EconometricsController(BaseController): ) if ns_parser and ns_parser.column: - column, dataset = self.choices["root"][ns_parser.column].keys() + if "." in ns_parser.column: + dataset, column = ns_parser.column.split(".") + else: + console.print( + "[red]Column must be formatted as 'dataset.column'[/red]\n" + ) if isinstance(self.datasets[dataset][column].index, pd.MultiIndex): console.print( @@ -1464,7 +1477,12 @@ class EconometricsController(BaseController): if regression_vars and len(regression_vars) > 1: for variable in regression_vars: - column, dataset = self.choices["regressions"][variable].keys() + if "." not in variable: + console.print( + "[red]Please follow the format 'dataset.column'[/red]\n" + ) + continue + dataset, column = variable.split(".") if not isinstance( self.datasets[dataset][column].index, pd.MultiIndex ): @@ -1732,8 +1750,14 @@ class EconometricsController(BaseController): if len(ns_parser.ts) > 1: datasets = {} for stock in ns_parser.ts: - column, dataset = self.choices["coint"][stock].keys() - datasets[stock] = self.datasets[dataset][column] + if "." not in stock: + console.print( + "[red]Invalid time series format. Should be dataset.column, " + "e.g. historical.open[/red]\n" + ) + else: + dataset, column = stock.split(".") + datasets[stock] = self.datasets[dataset][column] econometrics_view.display_cointegration_test( datasets, diff --git a/website/content/terminal/econometrics/coint/_index.md b/website/content/terminal/econometrics/coint/_index.md index f2cbb2320e4..8d48b61ed37 100644 --- a/website/content/terminal/econometrics/coint/_index.md +++ b/website/content/terminal/econometrics/coint/_index.md @@ -21,7 +21,7 @@ optional arguments: Example: ``` -2022 Feb 24, 06:03 (✨) /econometrics/ $ coint msft.adj_close aapl.adj_close tsla.adj_close googl.adj_close -p +2022 Feb 24, 06:03 (✨) /econometrics/ $ coint msft.adj_close,aapl.adj_close,tsla.adj_close,googl.adj_close -p Cointegration Tests ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━┓ ┃ Pairs ┃ Constant ┃ Gamma ┃ Alpha ┃ Dickey-Fuller ┃ P Value ┃