From 32823c54500cac24d86bffd1a4e0a6b825eed23e Mon Sep 17 00:00:00 2001 From: LimaniBhavik <6619586+LimaniBhavik@users.noreply.github.com> Date: Sun, 1 Mar 2026 15:25:17 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Optimize=20mortgage=20payoff=20perf?= =?UTF-8?q?ormance=20using=20NPER=20formula?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced the simulation-based iterative loop in the `mortgage_payoff` function with the closed-form NPER (number of periods) formula using logarithms. This change improves the calculation performance from O(N) to O(1) complexity, achieving an approximately 40x speedup in benchmark tests (measured 9.5ms vs 377ms for 100,000 iterations). The new implementation: - Corrects handling for 0% interest scenarios. - Preserves the existing early-exit behavior (returning 9999) for non-paying loans. - Maintains the 1200-month safety limit (returning 1201) for compatibility with the previous simulation logic. - Adds an example benchmark file for future performance monitoring. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>