From 83bfffe0996a24b00047f8f4e33e424c7dbe1062 Mon Sep 17 00:00:00 2001 From: northern-64bit <75195383+northern-64bit@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:12:34 +0100 Subject: [PATCH 1/6] Fix portfolio and benchmark length matching --- openbb_terminal/portfolio/portfolio_helper.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_helper.py b/openbb_terminal/portfolio/portfolio_helper.py index 4022bbb84623..29530da8028f 100644 --- a/openbb_terminal/portfolio/portfolio_helper.py +++ b/openbb_terminal/portfolio/portfolio_helper.py @@ -173,10 +173,14 @@ def make_equal_length(df1: pd.DataFrame, df2: pd.DataFrame): Both DataFrames returned """ # Match the DataFrames so they share a similar length - if len(df1.index) > len(df2.index): - df1 = df1.loc[df2.index] - elif len(df2.index) > len(df1.index): - df2 = df2.loc[df1.index] + if len(df1) > len(df2): + df1 = df1[ + df1.index.isin(df2.index) + ] + elif len(df1) < len(df2): + df2 = df2[ + df2.index.isin(df1.index) + ] return df1, df2 From 1018249de23003152ac27cc7cf720124e20d1199 Mon Sep 17 00:00:00 2001 From: northern-64bit <75195383+northern-64bit@users.noreply.github.com> Date: Sat, 11 Feb 2023 10:20:12 +0100 Subject: [PATCH 2/6] Fix linting --- openbb_terminal/portfolio/portfolio_helper.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_helper.py b/openbb_terminal/portfolio/portfolio_helper.py index 29530da8028f..ed4f9a1b0ac4 100644 --- a/openbb_terminal/portfolio/portfolio_helper.py +++ b/openbb_terminal/portfolio/portfolio_helper.py @@ -174,13 +174,9 @@ def make_equal_length(df1: pd.DataFrame, df2: pd.DataFrame): """ # Match the DataFrames so they share a similar length if len(df1) > len(df2): - df1 = df1[ - df1.index.isin(df2.index) - ] + df1 = df1[df1.index.isin(df2.index)] elif len(df1) < len(df2): - df2 = df2[ - df2.index.isin(df1.index) - ] + df2 = df2[df2.index.isin(df1.index)] return df1, df2 From 2389d4f835de78a3b8c1f78ca5bcb0951b8fecb7 Mon Sep 17 00:00:00 2001 From: northern-64bit <75195383+northern-64bit@users.noreply.github.com> Date: Sun, 19 Feb 2023 16:25:30 +0100 Subject: [PATCH 3/6] Fix make_equal_length --- openbb_terminal/portfolio/portfolio_helper.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_helper.py b/openbb_terminal/portfolio/portfolio_helper.py index ed4f9a1b0ac4..d65acbd0bacc 100644 --- a/openbb_terminal/portfolio/portfolio_helper.py +++ b/openbb_terminal/portfolio/portfolio_helper.py @@ -173,10 +173,14 @@ def make_equal_length(df1: pd.DataFrame, df2: pd.DataFrame): Both DataFrames returned """ # Match the DataFrames so they share a similar length - if len(df1) > len(df2): - df1 = df1[df1.index.isin(df2.index)] - elif len(df1) < len(df2): - df2 = df2[df2.index.isin(df1.index)] + df2.columns = [i + "2" for i in df2.columns] + df_merged = df1.join(df2, how="outer") + df_merged = df_merged.fillna(0) + + df1 = df_merged[df1.columns] + df2 = df_merged[df2.columns] + + df2.columns = [i[:-2] for i in df2.columns] return df1, df2 From 549a02379c77c6327cc981d4b4c481111c19509d Mon Sep 17 00:00:00 2001 From: northern-64bit <75195383+northern-64bit@users.noreply.github.com> Date: Mon, 20 Feb 2023 06:04:28 +0100 Subject: [PATCH 4/6] Handling pd.Series input --- openbb_terminal/portfolio/portfolio_helper.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openbb_terminal/portfolio/portfolio_helper.py b/openbb_terminal/portfolio/portfolio_helper.py index d65acbd0bacc..0acf1fd92d8d 100644 --- a/openbb_terminal/portfolio/portfolio_helper.py +++ b/openbb_terminal/portfolio/portfolio_helper.py @@ -173,14 +173,18 @@ def make_equal_length(df1: pd.DataFrame, df2: pd.DataFrame): Both DataFrames returned """ # Match the DataFrames so they share a similar length - df2.columns = [i + "2" for i in df2.columns] + if isinstance(df1, pd.Series): + df1 = df1.to_frame() + if isinstance(df2, pd.Series): + df2 = df2.to_frame() + df2.columns = [str(i) + "2" for i in df2.columns] df_merged = df1.join(df2, how="outer") df_merged = df_merged.fillna(0) df1 = df_merged[df1.columns] df2 = df_merged[df2.columns] - df2.columns = [i[:-2] for i in df2.columns] + df2.columns = [i[:-1] for i in df2.columns] return df1, df2 From 04a49d839e80b5b2832a66e52b0d9abeee4f535a Mon Sep 17 00:00:00 2001 From: northern-64bit <75195383+northern-64bit@users.noreply.github.com> Date: Fri, 24 Feb 2023 07:14:20 +0100 Subject: [PATCH 5/6] Fix alloc command --- openbb_terminal/portfolio/allocation_model.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/openbb_terminal/portfolio/allocation_model.py b/openbb_terminal/portfolio/allocation_model.py index 3ade26bd9b3e..14232e355851 100644 --- a/openbb_terminal/portfolio/allocation_model.py +++ b/openbb_terminal/portfolio/allocation_model.py @@ -77,6 +77,16 @@ def get_assets_allocation( benchmark_assets_allocation = stockanalysis_model.get_etf_holdings( benchmark_ticker ).reset_index() + if benchmark_assets_allocation.empty: # if not an etf or no data is available + benchmark_assets_allocation = pd.DataFrame( + data={ + "symbol": [benchmark_ticker], + "Name": [benchmark_ticker], + "% Of Etf": ["100%"], + "Shares": [1], + }, + index=[0], + ) benchmark_assets_allocation.rename( columns={"symbol": "Symbol", "% Of Etf": "Benchmark"}, inplace=True ) From 4523ffa7ed2cad81775432ca75a28ea5eab31490 Mon Sep 17 00:00:00 2001 From: northern-64bit <75195383+northern-64bit@users.noreply.github.com> Date: Fri, 24 Feb 2023 08:03:51 +0100 Subject: [PATCH 6/6] Fix metrics, yret and summary errors --- openbb_terminal/portfolio/portfolio_helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbb_terminal/portfolio/portfolio_helper.py b/openbb_terminal/portfolio/portfolio_helper.py index 0acf1fd92d8d..2f74ecadf869 100644 --- a/openbb_terminal/portfolio/portfolio_helper.py +++ b/openbb_terminal/portfolio/portfolio_helper.py @@ -186,7 +186,7 @@ def make_equal_length(df1: pd.DataFrame, df2: pd.DataFrame): df2.columns = [i[:-1] for i in df2.columns] - return df1, df2 + return df1.iloc[:, 0], df2.iloc[:, 0] def get_region_from_country(country: str) -> str: