Repository navigation
Conversation
…issue (storytold#4093) Under basis 0, settlement-to-maturity is now issue-to-maturity less issue-to-settlement, so a 30th-to-31st span counts one day as in Excel.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Fixes #4093
Root cause
mat_termsincrates/functions/src/financial/securities.rs:168(the shared helper behind PRICEMAT and YIELDMAT) computed the settlement-to-maturity fraction (DSM) directly asyear_frac(settlement, maturity, basis). US 30/360 (basis 0) is not additive: once the start day is the 30th, a 31st end day becomes the 30th. So Jan 30 → Jan 31 counts 0 days, even though issue → maturity (Jan 29 → Jan 31) is 2 days and issue → settlement is 1. Excel's results match DSM = DIM − A: 1 day. With DSM = 0, PRICEMAT's discount term disappears (price 100), and YIELDMAT returns#NUM!because of itsdsm == 0guard.Fix
For basis 0 only,
mat_termsnow computes DSM as(days360(issue, maturity) − days360(issue, settlement)) / 360. It works in whole days, so the result has no extra floating-point error. Other bases are unchanged. Actual-day bases and European 30/360 (basis 4) are already additive, so DIM − A gives the same result there anyway. Basis 1 is tracked separately in #4054.Tests
New test
financial::tests::maturity_securities_count_us_30_360_from_issueincrates/functions/src/financial/tests.rs. It checks the three Excel values from the issue:It also checks the December repro and the two controls that already matched (basis 2, and a February 1 maturity).
Without the fix (run on the branch before the change to
securities.rswas applied):With the fix:
The existing PRICEMAT/YIELDMAT basis-0 checks (Microsoft documentation examples) still pass.
Checks run
cargo fmt -p gridcraft-functions: only the changed lines were affectedcargo clippy -p gridcraft-functions --all-targets -- -D warnings: cleancargo test -p gridcraft-functions: 182 passed, 0 failedNot run
cargo xtask ci(wasm, layers, assets, other crates) was not run locally; I'm relying on CI for those.Summary by CodeRabbit