diff --git a/openbb_terminal/portfolio/portfolio_controller.py b/openbb_terminal/portfolio/portfolio_controller.py index 66fc00e1ec8..1d212f05f53 100644 --- a/openbb_terminal/portfolio/portfolio_controller.py +++ b/openbb_terminal/portfolio/portfolio_controller.py @@ -276,13 +276,49 @@ class PortfolioController(BaseController): if OPTIMIZATION_TOOLKIT_ENABLED: if self.portfolio is None: tickers = [] + categories = None else: tickers = self.portfolio.tickers_list + transactions = self.portfolio.get_transactions() + + categories = { + "ASSET_CLASS": {}, + "SECTOR": {}, + "INDUSTRY": {}, + "COUNTRY": {}, + "CURRENT_INVESTED_AMOUNT": {}, + "CURRENCY": {}, + } + for _, transaction in transactions.iterrows(): + if transaction["Ticker"] not in categories["ASSET_CLASS"]: + categories["ASSET_CLASS"][transaction["Ticker"]] = transaction[ + "Type" + ] + categories["SECTOR"][transaction["Ticker"]] = transaction[ + "Sector" + ] + categories["INDUSTRY"][transaction["Ticker"]] = transaction[ + "Industry" + ] + categories["COUNTRY"][transaction["Ticker"]] = transaction[ + "Country" + ] + categories["CURRENT_INVESTED_AMOUNT"][ + transaction["Ticker"] + ] = transactions[ + transactions["Ticker"] == transaction["Ticker"] + ][ + "Investment" + ].sum() + categories["CURRENCY"][transaction["Ticker"]] = transaction[ + "Currency" + ] + self.queue = self.load_class( po_controller.PortfolioOptimizationController, tickers, None, - None, + categories, self.queue, ) else: diff --git a/openbb_terminal/portfolio/portfolio_optimization/po_controller.py b/openbb_terminal/portfolio/portfolio_optimization/po_controller.py index 43b08df479a..f7953aa82b9 100644 --- a/openbb_terminal/portfolio/portfolio_optimization/po_controller.py +++ b/openbb_terminal/portfolio/portfolio_optimization/po_controller.py @@ -236,6 +236,9 @@ class PortfolioOptimizationController(BaseController): if categories: self.categories = dict(categories) self.available_categories = list(self.categories.keys()) + + if "CURRENT_INVESTED_AMOUNT" in self.available_categories: + self.available_categories.remove("CURRENT_INVESTED_AMOUNT") else: self.categories = dict() self.available_categories = list() diff --git a/website/content/terminal/guides/intros/portfolio/index.md b/website/content/terminal/guides/intros/portfolio/index.md index 575f1dc17b5..13dbeaa7021 100644 --- a/website/content/terminal/guides/intros/portfolio/index.md +++ b/website/content/terminal/guides/intros/portfolio/index.md @@ -26,7 +26,7 @@ Note that the Excel sheet requires the following columns: - **Date** - The date the trade occurred - **Name** - The name of the security -- **Type** - The type of the security. Use Cash/Stock/Crypto/ETF as appropriate +- **Type** - The type of the security. Use Stock/Crypto/ETF as appropriate - **Price** - The price the security was added or removed at, on a per-unit basis - **Quantity** - How much of the security in question was added or removed