From 0f46ddbfa71efb725b168c2f2181c8050cc3edd3 Mon Sep 17 00:00:00 2001 From: sklbancor <109073706+sklbancor@users.noreply.github.com> Date: Thu, 23 May 2024 23:57:42 +0100 Subject: [PATCH] Optimizer: raise ConvergenceError when prices wander off --- fastlane_bot/tools/optimizer/margpoptimizer.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fastlane_bot/tools/optimizer/margpoptimizer.py b/fastlane_bot/tools/optimizer/margpoptimizer.py index eb207f7e9..ff1df4e20 100644 --- a/fastlane_bot/tools/optimizer/margpoptimizer.py +++ b/fastlane_bot/tools/optimizer/margpoptimizer.py @@ -373,6 +373,13 @@ def dtknfromp_f(p, *, islog10=True, asdct=False, quiet=False): p = np.exp(plog10 * np.log(10)) criterium = np.linalg.norm(dplog10) + # this fix could cut down on some of the logging noise by raising a ConvergenceError early + if max(p) > 1e50: + raise self.ConvergenceError(f"price vector component exceeds maximum price [p={p}]") + if min(p) < 1e-50: + raise self.ConvergenceError(f"price vector component below minimum price [p={p}]") + + # ...print out some info if requested... if P("verbose"): print(f"\n[margp_optimizer] ========== cycle {i} =======>>>")