Skip to content

Commit 6844ef0

Browse files
author
saket3395
committed
fix: guard None lambda in CLA._solve case-b comparison
Fixes #738. CLA.max_sharpe() raised TypeError: '>' not supported between instances of 'NoneType' and 'float' whenever all expected returns were equal. _compute_lambda returns (None, None) when its denominator c is exactly zero, which is guaranteed when all expected returns are identical. The case-a) branch of _solve already guards against this by comparing CLA._infnone(lam) instead of the raw lam, but the case-b) branch compared the raw lam directly, causing the crash. Wraps lam with CLA._infnone(...) in both comparisons of the case-b) branch, mirroring the existing case-a) pattern. When lam is None this now resolves to -inf, so the candidate is simply never selected as i_out/l_out, and the algorithm falls through to the minimum-variance solution instead of crashing.
1 parent a6638d2 commit 6844ef0

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎pypfopt/cla.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ def _solve(self):
364364
self.w[-1][i],
365365
)
366366
if (
367-
self.ls[-1] is None or lam < self.ls[-1]
368-
) and lam > CLA._infnone(l_out):
367+
self.ls[-1] is None or CLA._infnone(lam) < self.ls[-1]
368+
) and CLA._infnone(lam) > CLA._infnone(l_out):
369369
l_out, i_out = lam, i
370370
if (l_in is None or l_in < 0) and (l_out is None or l_out < 0):
371371
# 3) compute minimum variance solution

0 commit comments

Comments
 (0)