diff --git a/openbb_terminal/portfolio/portfolio_optimization/optimizer_model.py b/openbb_terminal/portfolio/portfolio_optimization/optimizer_model.py index 594c70356ffd..31333b1da61b 100644 --- a/openbb_terminal/portfolio/portfolio_optimization/optimizer_model.py +++ b/openbb_terminal/portfolio/portfolio_optimization/optimizer_model.py @@ -225,7 +225,10 @@ def get_equal_weights( method=method, ) - weights = {stock: value * round(1 / len(symbols), 5) for stock in symbols} + weights = { + stock: value * round(1 / len(stock_returns.columns), 5) + for stock in stock_returns.columns + } return weights, stock_returns diff --git a/openbb_terminal/portfolio/portfolio_optimization/yahoo_finance_model.py b/openbb_terminal/portfolio/portfolio_optimization/yahoo_finance_model.py index baa20f422940..a0d0ae5697e7 100644 --- a/openbb_terminal/portfolio/portfolio_optimization/yahoo_finance_model.py +++ b/openbb_terminal/portfolio/portfolio_optimization/yahoo_finance_model.py @@ -334,6 +334,16 @@ def process_returns( # Select stocks with low number of nans selected_stocks = np.isnan(stock_returns).sum(axis=0) selected_stocks = np.where(selected_stocks <= maxnan * stock_returns.shape[0])[0] + filtered_out = [ + s + for s in stock_returns.columns + if s not in stock_returns.iloc[:, selected_stocks] + ] + if filtered_out: + print( + "The following stocks were filtered out, due to too many NaNs: " + + ", ".join(filtered_out) + ) stock_returns = stock_returns.iloc[:, selected_stocks] # Replace values above and below threshold