Skip to content

Harden kink detection in Affine.price_elasticity#163

Open
alexanderthclark wants to merge 1 commit into
mainfrom
codex/harden-kink-detection-in-price-elasticity
Open

Harden kink detection in Affine.price_elasticity#163
alexanderthclark wants to merge 1 commit into
mainfrom
codex/harden-kink-detection-in-price-elasticity

Conversation

@alexanderthclark
Copy link
Copy Markdown
Owner

Motivation

  • Avoid brittle float-equality when detecting kink points so that true kinks reliably raise an error while nearby floating-point-noisy inputs do not.
  • Make kink detection configurable via tolerances so callers can control sensitivity for FP edge cases.

Description

  • Replaced exact pt == self.intersections matching with np.isclose checks on both price and quantity coordinates against self.intersections, converting intersections to np.asarray for safe checks.
  • Exposed tolerance parameters on Affine.price_elasticity as atol and rtol with sensible defaults 1e-12 and 1e-9, and threaded them through recursive above/below probes so diagnostics use the same tolerances.
  • Added shape/size guards when inspecting self.intersections so detection only runs for properly-shaped intersection arrays.
  • Added regression tests in tests/test_curves.py (TestAffinePriceElasticityKinks) covering exact-kink input (should raise), near-kink input (should not raise), and a floating-point representation edge case that should still be treated as a kink.

Testing

  • Ran pytest -q tests/test_curves.py -k kink and observed 3 passed for the kink-focused tests.
  • Ran pytest -q tests/test_curves.py and observed 32 passed indicating the module-level test suite succeeded.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant