mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-30 05:52:23 +00:00
Make the get_equal_weights handle portfolio's with stock's filtered out, due to the stocks having to many NaNs. Co-authored-by: James Maslek <jmaslek11@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user