#935

[BUG] Ratio trend analysis labels all changes from a zero baseline as Stable

OpenBichengWangopened 7d ago

Affected Notebook/File

skills/custom_skills/analyzing-financial-statements/interpret_ratios.py, RatioInterpreter.analyze_trend()

Bug Description

When the first ratio value is zero, pct_change is set to zero regardless of the last value. The stability check then reports Stable for every such series. For example, ROE falling from 0% to -20% is described as having "decreased by 0.0%" and produces no trend-based warning in perform_comprehensive_analysis(). ROE rising from 0% to 20% and debt-to-equity rising from 0 to 2 are also reported as stable.

Expected: distinguish a real change from an unchanged zero series, preserve the direction of the change, and explicitly handle the undefined relative percentage rather than report a 0% change. Deteriorating series should reach the existing trend-warning path.

Steps to Reproduce

From the repository root at a162e0184e71b60290808a43961a6cbc8060123c, run this offline Python example:

import importlib.util

path = "skills/custom_skills/analyzing-financial-statements/interpret_ratios.py"
spec = importlib.util.spec_from_file_location("ratios", path)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)

interpreter = module.RatioInterpreter("technology")
periods = ["2024", "2025"]
for ratio, values in [
    ("roe", [0.0, -0.20]),
    ("roe", [0.0, 0.20]),
    ("debt_to_equity", [0.0, 2.0]),
]:
    result = interpreter.analyze_trend(ratio, values, periods)
    print(ratio, values, result["trend"], result["pct_change"])

analysis = module.perform_comprehensive_analysis(
    {"profitability": {"roe": -0.20}},
    "technology",
    {"roe": {"values": [0.0, -0.20], "periods": periods}},
)
print(analysis["recommendations"])

Actual Output

roe [0.0, -0.2] Stable 0
roe [0.0, 0.2] Stable 0
debt_to_equity [0.0, 2.0] Stable 0

The recommendations contain the current-ROE priority message, but omit Monitor: roe showing negative trend; the same example starting at 0.10 includes that warning.

Environment

Python 3.11.17, macOS 27.0.1 arm64. The reproduction uses only the standard library; no API calls or notebook execution are needed.

Would you be willing to submit a PR to fix this?

No, I'm just reporting.

Activity

0

No activity yet.