Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make the get_equal_weights handle portfolio's with stock's filtered out, due to the stocks having to many NaNs.
  • Loading branch information
northern-64bit committed Jan 14, 2023
1 parent 86fd7ae commit 4ae5c62
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4ae5c62

Please sign in to comment.