Skip to content

Commit

Permalink
Handle crash with zero inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
miohtama committed Jan 13, 2025
1 parent d3a4f80 commit 52e9ba9
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tradeexecutor/analysis/weights.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def sort_key_reserve_first(col_name):


def calculate_weights_statistics(
weights: pd.Series,
weights: pd.Series,
) -> pd.DataFrame:
"""Get statistics of weights during the portfolio construction.
Expand All @@ -160,6 +160,11 @@ def calculate_weights_statistics(
# Filter out zero values
weights = weights[weights != 0]

if len(weights.index) == 0:
return pd.DataFrame([
{"Error": "No trades or weights assigned"}
])

max_idx = weights.idxmax()
at, pair = max_idx
value = weights[max_idx]
Expand Down

0 comments on commit 52e9ba9

Please sign in to comment.