Skip to content

Commit

Permalink
fixed asserts that failed on 3.12 because of changed sum() numerical …
Browse files Browse the repository at this point in the history
…accuracy (python/cpython#100425)
  • Loading branch information
enzbus committed Nov 9, 2023
1 parent d23b648 commit 717d20e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cvxportfolio/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ def _rhs(self):


class LongCash(MinCashBalance):
"""Require that post-trade cash account is non-negative.
r"""Require that post-trade cash account is non-negative.
In our notation, this is
Expand Down
8 changes: 4 additions & 4 deletions cvxportfolio/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def simulate(self, t, t_next, h, policy, past_returns, current_returns,
policy_time = time.time() - s

# for safety recompute cash
z.iloc[-1] = -sum(z.iloc[:-1])
assert sum(z) == 0.
z.iloc[-1] = -np.sum(z.iloc[:-1])
assert np.isclose(np.sum(z), 0.)

# trades in dollars
u = z * current_portfolio_value
Expand All @@ -200,8 +200,8 @@ def simulate(self, t, t_next, h, policy, past_returns, current_returns,
u = self._round_trade_vector(u, current_prices)

# recompute cash
u.iloc[-1] = -sum(u.iloc[:-1])
assert sum(u) == 0.
u.iloc[-1] = -np.sum(u.iloc[:-1])
assert np.isclose(np.sum(u), 0.)

# compute post-trade holdings (including cash balance)
h_plus = h + u
Expand Down

0 comments on commit 717d20e

Please sign in to comment.