Skip to content

Fix Amount __sub__ and __eq__ referencing removed currency_type - #424

Closed
harshajv7981 wants to merge 1 commit into
domokane:masterfrom
harshajv7981:fix/amount-sub-eq-ccy-name
Closed

harshajv7981 wants to merge 1 commit into
domokane:masterfrom
harshajv7981:fix/amount-sub-eq-ccy-name

Conversation

@harshajv7981

Copy link
Copy Markdown
Contributor

Problem

Amount(100, "CAD") - Amount(40, "CAD") and Amount(1, "CAD") == Amount(1, "CAD") raise AttributeError: 'Amount' object has no attribute 'currency_type'. Commit 48562de renamed the attribute to ccy_name but __sub__ and __eq__ still read currency_type.

Change

Use ccy_name in those two places, matching __add__, __truediv__ and _check_currency. Two identifiers changed, nothing else.

Verification

  • New regression test tests/unit/test_FinAmount.py::test_amount_sub_and_eq fails before this change (the AttributeError above) and passes after.
  • tests/unit/test_FinAmount.py: 2 passed. Amount isn't used elsewhere in the package.

I found this with patchwork, an automated code-audit tool I run, and verified the reproduction test in an isolated sandbox. If tool-assisted reports aren't welcome here, let me know and I won't send more.

Commit 48562de renamed the attribute to ccy_name but left these two
references behind, so subtracting or comparing Amounts raised
AttributeError.
@harshajv7981

Copy link
Copy Markdown
Contributor Author

The failing unit test action check isn't from this change. master fails the same 9 tests in tests/unit/test_fx_forward_black76.py (9 failed, 1372 passed on the latest master run), and both new test_FinAmount.py tests pass here.

In case it's useful, the cause: 5710283 added the currency_pair argument to FXVanillaOption.value(), but test_fx_forward_black76.py still uses the old call. If "EURUSD" is passed there, 7 of the 9 pass. The two test_fx_black76_matches_spot_model_under_interest_parity cases still fail (call 0.098952 vs 0.098879). The Black-Scholes branch now discounts over the spot and delivery dates, while the Black-76 branch still uses expiry_dt, so the two models no longer agree. I've left it alone because which convention the Black-76 branch should follow is your call.

@domokane domokane closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants