Skip to content

Commit

Permalink
added cPython 3.12 guard, cfr. python/cpython#111933
Browse files Browse the repository at this point in the history
  • Loading branch information
enzbus committed Nov 10, 2023
1 parent 6eba397 commit 9a48304
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cvxportfolio/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import copy
import logging
import sys
import time
from itertools import starmap
from pathlib import Path
Expand Down Expand Up @@ -181,7 +182,10 @@ def simulate(self, t, t_next, h, policy, past_returns, current_returns,

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

# bug in cPython 3.12, https://github.com/python/cpython/issues/111933
if sys.version.split(' ')[0] < '3.12':
assert sum(z) == 0.

# trades in dollars
u = z * current_portfolio_value
Expand All @@ -201,7 +205,10 @@ def simulate(self, t, t_next, h, policy, past_returns, current_returns,

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

# bug in cPython 3.12, https://github.com/python/cpython/issues/111933
if sys.version.split(' ')[0] < '3.12':
assert sum(u) == 0.

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

0 comments on commit 9a48304

Please sign in to comment.