#931

[BUG] Breakeven analysis silently returns the wrong boundary for decreasing outputs

OpenBichengWangopened 9d ago

Affected Notebook/File

skills/custom_skills/creating-financial-models/sensitivity_analysis.py, SensitivityAnalyzer.breakeven_analysis()

Bug Description

The solver assumes the output increases with the input, without documenting or checking that restriction. For a decreasing function with a unique, bracketed solution, it silently returns a boundary far from the target. This affects uses such as finding the cost level at which profit reaches a target.

For profit = 100 - 10 * cost, a target of 40 on [0, 10] has the exact solution cost = 6. The function returns 0.0048828125, where profit is 99.951171875.

Expected: find the decreasing function's bracketed solution within the requested tolerance, or explicitly reject unsupported monotonic direction rather than returning an incorrect result.

Steps to Reproduce

From the repository root at a162e0184e71b60290808a43961a6cbc8060123c, with NumPy and pandas installed, run:

import sys
from types import SimpleNamespace

sys.path.insert(0, "skills/custom_skills/creating-financial-models")
from sensitivity_analysis import SensitivityAnalyzer

model = SimpleNamespace(cost=0.0)
solver = SensitivityAnalyzer(model)
result = solver.breakeven_analysis(
    variable_name="cost",
    variable_update=lambda value: setattr(model, "cost", value),
    output_func=lambda: 100 - 10 * model.cost,
    target_value=40,
    min_search=0,
    max_search=10,
)
print(result)              # 0.0048828125; expected approximately 6
print(100 - 10 * result)   # 99.951171875; target is 40
assert abs(result - 6) < 0.01

Error Message

The final assertion fails. There is no exception from the solver itself: when output exceeds the target it always lowers high, which discards the solution for a decreasing function.

As a control, the increasing function 10 * model.cost - 20 with the same target and bounds returns 6.0009765625 (output 40.009765625).

Environment

macOS 27.0.1 (arm64), Python 3.11.17, NumPy 2.4.6, pandas 3.0.6. Reproduced offline without API calls. This report leaves the defect unfixed; it is separate from #904's one-way sensitivity baseline fix and #902's DCF sensitivity state restoration.

Activity

0

No activity yet.