Skip to content

Add ODDFPRICE and ODDLPRICE functions - #1850

Merged
Tobiadefami merged 53 commits into
developfrom
feat/hf-442-oddfprice-oddlprice
Nov 19, 2026
Merged

Tobiadefami merged 53 commits into
developfrom
feat/hf-442-oddfprice-oddlprice

Conversation

@Tobiadefami

@Tobiadefami Tobiadefami commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Context

This PR adds the Excel functions ODDFPRICE and ODDLPRICE, the price per 100 face value of a security with an odd
(short or long) first or last coupon period.

Important

Stacked on #1812 (ACCRINT), which is stacked on #1804 (the coupon functions). The odd periods share #1812's
and #1804's coupon schedule module, so this branch is based on feature/HF-453. Until those PRs merge, this diff
also shows their commits. Once they merge, develop will be merged into this branch and only these changes will
remain in the diff.

  • ODDFPRICE(settlement, maturity, issue, first_coupon, rate, yld, redemption, frequency, [basis])
  • ODDLPRICE(settlement, maturity, last_interest, rate, yld, redemption, frequency, [basis])

Behavior, checked against Excel:

  • Validation order (both): left to right, each argument in full before the next (an error, an empty argument
    #N/A, text or a boolean #VALUE!, a value out of range #NUM!): the dates, rate, yld, redemption,
    frequency (1, 2 or 4, truncated), basis. Then a negative rate or yld and redemption ≤ 0 (#NUM!), then
    the order of the dates (issue < settlement < first_coupon < maturity; last_interest < settlement < maturity),
    each rule on its own.
  • A number outside the date range is #NUM!, not #VALUE! as Microsoft's pages say; only text and booleans give
    #VALUE!.
  • ODDFPRICE:
    • first_coupon must be a coupon date of maturity's schedule (the coupon functions' schedule), otherwise #NUM!.
    • A first period exactly one regular period long (issue on the quasi-coupon date) is #NUM!; shorter and longer
      ones use Microsoft's short and long formulas. Under basis 1, the period length E is the actual length of
      settlement's quasi-coupon period.
    • The quasi-coupon dates of a long first period are stepped back from first_coupon one period at a time, so the
      day can drift (31 August, 28 February, 28 August). With a month-end first_coupon and settlement in the last
      quasi-coupon period, not on a month end, Excel discounts by one more period; HyperFormula does the same.
    • #NUM! when a discount factor is too large for a number (a large yld over many periods).
  • ODDLPRICE:
    • The quasi-coupon periods are stepped forward from last_interest one period at a time (the day can drift), and
      their number is the number of maturity's coupon dates after last_interest.
    • Bases 1, 2 and 3 give the same price (actual days over actual period lengths). Under basis 0 the period lengths
      count the 31st and the last day of February as day 30 at either end.
    • A quasi-coupon date after 31 December 9999 is #NUM!.
  • Number format: a plain number (Excel shows General).
  • Dates before 1 March 1900: HyperFormula's date serials differ from Excel's there, as for every date function.

Implementation

  • oddfprice and oddlprice in SecuritiesPlugin, through one private runner, oddCouponPeriodBond, that
    validates the shared arguments in Excel's order and hands the dates to each function's last step. This is the
    pattern couponFunction and discountedSecurity already use.
  • The maths is in CouponSchedule.ts: two exported functions, oddFirstPeriodPrice and oddLastPeriodPrice, built
    on the existing couponPeriodIndex and couponDate, plus private helpers (stepMonths for the stepped
    quasi-coupon dates, quasiCouponsBeforeFirstCoupon, periodLength). Terms are added in Excel's order (redemption,
    the odd coupon, the other coupons, then the accrued interest), which gives Excel's last digit.
  • Two existing private helpers now call the new ones instead of repeating them: accruedDays calls dayCount,
    thirtyDayMonthDay calls isFebruaryEnd. ACCRINT's and the coupon functions' results are unchanged (their specs
    pass).
  • O(N) in the coupons and quasi-coupon periods, as ACCRINT.
  • Two new error messages, FirstCouponDate and OddPeriodLength.
  • Catalogue entries in categories/financial.ts; both added to UNGROUPED_FUNCTIONS in functionCapabilities.ts.
  • Names in all 18 language packs, from Microsoft's Excel function reference in each language and, for Polish,
    checked in Microsoft Excel Online (CENA.PIERW.OKR, CENA.OST.OKR). csCZ and idID keep the English names, as
    for ACCRINT.
  • Changelog entry under Added.

How did you test your changes?

  • Expected values come from Microsoft Excel Online. Each test is one measured case, with the measured formula on
    the same fixture layout: the docs examples, every basis and frequency, short and long odd periods, first coupons
    off the schedule, regular-length first periods, month-end and end-of-February dates, settlement on and next to
    quasi-coupon dates, large and tiny rates and yields, overflowing discount factors, the date bounds, coercion of
    every argument, empty arguments, error precedence, arrays and argument counts. Values are compared at Excel's 15
    significant digits with smartRounding: false. Text dates use dateFormats: ['MM/DD/YYYY', 'YYYY-MM-DD'], array
    constants useArrayArithmetic: true.
  • 658 new tests in hyperformula-tests: function-oddfprice (364), function-oddlprice (293), and
    function-oddfprice-date-bounds (1, a stepped quasi-coupon date before the first date under nullDate
    31 December 1899). All failed before the engine change.
  • Full Jest suite with the private tests, after merging the current feature/HF-453: 549 suites, 12,377 passed, 3
    skipped (pre-existing). The ODDFPRICE and ODDLPRICE specs pass unchanged with Add ACCRINT function #1812's reworked ACCRINT code.
  • Mutation checks: dropping the month-end extra period fails 34 tests; dropping the end-of-February rule of the
    basis-0 period length fails 18; discounting the redemption by one more period in the short first period fails
    64.
  • npm run lint (no new warnings in src/), npm run verify:typings, npm run docs:generate-function-docs (both
    listed), git diff --check.

AI assistance

Claude Code wrote the code, tests and docs. I reviewed it.

Compatibility with Excel and Google Sheets

Excel: Microsoft Excel Online. Google Sheets has no ODDFPRICE or ODDLPRICE function.

Formula Excel Google Sheets HyperFormula
=ODDFPRICE(DATE(2008,11,11),DATE(2021,3,1),DATE(2008,10,15),DATE(2009,3,1),0.0785,0.0625,100,2,1) 113.597717474079 No such function 113.597717474079
=ODDFPRICE(DATE(2009,3,15),DATE(2019,8,31),DATE(2008,11,30),DATE(2009,8,31),0.0785,0.0625,100,2,0) 108.627603828733 No such function 108.627603828733
=ODDFPRICE(DATE(2008,11,11),DATE(2021,3,1),DATE(2008,9,1),DATE(2009,3,1),0.0785,0.0625,100,2,0) #NUM! No such function #NUM!
=ODDFPRICE(DATE(2008,11,11),DATE(2009,3,2),DATE(2008,10,15),DATE(2009,3,1),0.0785,0.0625,100,2,1) #NUM! No such function #NUM!
=ODDLPRICE(DATE(2008,2,7),DATE(2008,6,15),DATE(2007,10,15),0.0375,0.0405,100,2,0) 99.8782860147213 No such function 99.8782860147213
=ODDLPRICE(DATE(2008,6,30),DATE(2008,10,31),DATE(2008,4,30),0.0375,0.0405,100,2,1) 99.9031163311686 No such function 99.9031163311686
=ODDLPRICE(DATE(9999,8,1),DATE(9999,12,31),DATE(9999,6,15),0.0375,0.0405,100,2,0) #NUM! No such function #NUM!

HyperFormula matches Excel at 15 significant digits on every measured case, except the general differences of all
date functions before 1 March 1900 and of argument counts. No new rows in the list of differences.

Public API changes

None. Two new built-in functions and two new error messages.

Out of scope and follow-ups

YIELD, ODDFYIELD and ODDLYIELD come in a later PR.

Types of changes

  • Breaking change (existing functionality no longer works as before) – agreed with the maintainers
  • New feature or improvement (a non-breaking change that adds functionality)
  • Bug fix (a non-breaking change that fixes an issue)
  • Additional language file, or a change to an existing language file (translations)
  • Change to the documentation

Related issues

  1. HF-442 (ODDFPRICE), HF-444 (ODDLPRICE).
  2. Depends on Add ACCRINT function #1812, which depends on Add COUPDAYBS, COUPDAYS, COUPDAYSNC, COUPNCD, COUPNUM and COUPPCD functions #1804 and Add ACCRINTM, DISC, INTRATE, PRICEDISC, RECEIVED and YIELDDISC functions #1799.
  3. Tests: handsontable/hyperformula-tests#107

Checklist

🤖 Generated with Claude Code


Note

Medium Risk
Large, Excel-sensitive financial and day-count logic with many date edge cases; mistakes would affect bond pricing results but stay confined to new securities functions.

Overview
Adds ODDFPRICE and ODDLPRICE so HyperFormula can price bonds with odd first or last coupon periods per Excel, including short vs long first-period formulas, stepped quasi-coupon dates (with month-end / February edge cases), and basis-specific day counts.

The pricing logic is in oddFirstPeriodPrice and oddLastPeriodPrice in CouponSchedule.ts, exposed through SecuritiesPlugin via a shared oddCouponPeriodBond validator (Excel-style argument order, date ordering, frequency 1/2/4, and new #NUM! cases for a bad first_coupon or a first period that is exactly one regular coupon long).

The diff also introduces the shared securities stack those functions build on: a new SecuritiesPlugin (discounted-security and coupon helpers such as ACCRINT, COUP*, DISC, etc.), dayCountByBasis / daysIn30DayMonths on DateTimeHelper (with YEARFRAC refactored to use it), function metadata and license entries, locale names, and changelog / compatibility doc updates.

Reviewed by Cursor Bugbot for commit 36d16b9. Bugbot is set up for automated code reviews on this repo. Configure here.

Tobiadefami and others added 23 commits October 7, 2026 22:12
DateTimeHelper.dayCountByBasis(startDate, endDate, basis) returns the
day count and the days in the year for day-count bases 0-4. Basis 0
applies toBasisUS to copies of the dates, basis 1 uses
yearLengthForBasis, and basis 4 uses toBasisEU.

YEARFRAC now returns dayCount / yearDays from the helper. Its results
are unchanged. DAYS360 keeps its own days360Core and is not touched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nctions

Six financial functions for discounted and interest-at-maturity
securities, built on DateTimeHelper.dayCountByBasis.

- Every argument is a SCALAR and is converted in the method, so booleans
  and the empty text give #VALUE! and invalid arguments are reported in
  Excel's order (dates, basis, then the amounts for the DISC-like
  functions; left to right for ACCRINTM).
- Basis is truncated, but a negative basis is #NUM!, as in Excel.
- Dates are truncated; dates outside the supported range give #NUM!.
- The arithmetic follows the operation order that reproduces Excel's
  results to the 15th significant digit.
- An empty or omitted ACCRINTM par is 1000. Excel rejects the
  3-argument form; this is added to the list of differences.

Adds catalogue entries, names in all language packs and a changelog
entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the CHANGELOG conflict and lists ACCRINTM, DISC, INTRATE, PRICEDISC,
RECEIVED and YIELDDISC in the ungrouped function capabilities, as the license
capability completeness invariant requires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
coerceToSecurityDate truncated before checking the range, so a date
such as -0.5 became serial 0, a valid date. Excel returns #NUM! for any
negative date, before looking at the later arguments. Reject a negative
value before truncating, as coerceToDayCountBasis already does for the
basis.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An empty required argument was coerced to 0, so
DISC(,DATE(2008,2,16),97.975,100) returned a result for a settlement of
serial 0. Excel returns #N/A. Check for an empty argument in its own
place of the validation order, with a shared isArgumentEmpty helper. An
empty basis is still 0 and an empty ACCRINTM par is still 1000.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merging develop after the 3.5.0 release left the entry for the new
securities functions under the 3.5.0 heading. These functions are not in
3.5.0, so the entry belongs under Unreleased.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the coupon functions that return a date or a count from the coupon
schedule, with the runner and schedule helpers the day-count functions
build on.

- couponFunction validates the arguments in Excel's order: settlement,
  maturity, settlement before maturity, an empty settlement, maturity or
  frequency argument (#N/A), frequency, then basis. Dates and basis use
  the securities helpers (strictNumber, coerceToSecurityDate,
  coerceToDayCountBasis) unchanged; frequency is truncated and must be
  1, 2 or 4 (new message ErrorMessage.CouponFrequency).
- couponDate steps from maturity by 12 / frequency months. A month-end
  maturity gives month-end coupon dates; otherwise maturity's day is
  clamped to the month, leap years included, and never drifts.
- couponsAfter counts the coupon dates after settlement in constant
  time, without stepping through the periods.
- A previous coupon date before the earliest supported date is #NUM!.

Adds catalogue entries, names in all language packs, the license
capability entries and a changelog entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the coupon day-count functions on top of the coupon schedule.

- COUPDAYBS counts from the previous coupon date to settlement with the
  day-count helper for every basis.
- COUPDAYSNC uses the same helper for bases 1 to 4. For basis 0 it is
  the 30/360 length of the coupon period, with day 31 and the last day
  of February counted as 30 at both ends, minus COUPDAYBS, as in Excel.
  The three functions do not always add up, in Excel or here.
- COUPDAYS is 360 / frequency for bases 0, 2 and 4 and 365 / frequency
  for basis 3. For basis 1 it is Excel's period length, which is not
  always the next coupon date minus the previous one: a walk back from
  maturity whose day can drift down at month ends, followed by an
  end-of-month step back. Computed in constant time.

Adds catalogue entries, names in all language packs, the license
capability entries and the changelog entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A financial function for securities that pay periodic interest, built on
DateTimeHelper.dayCountByBasis and the coupon schedule of the COUP*
functions, anchored at first_interest.

- Every argument is a SCALAR and is converted in the method. Invalid
  arguments are reported in Excel's order: calc_method first, then
  issue, first_interest, settlement, rate, par, frequency and basis,
  then the #NUM! checks (rate and par greater than 0, issue before
  settlement).
- An empty required argument is #N/A. An empty par is 1000, an empty or
  omitted basis is 0, and an empty or omitted calc_method is TRUE;
  calc_method does not accept text.
- Interest accrues from issue through each coupon period to settlement.
  first_interest may be on or before issue. With calc_method FALSE and
  settlement after first_interest, the time from the start of the period
  that ends on first_interest to settlement counts as one span. With
  settlement in a period before first_interest's, the result is the time
  from issue to first_interest minus the time from settlement to
  first_interest, as Excel computes it.
- Under basis 1 a period ends on first_interest's day of the month,
  rolled over into the next month when that day does not exist. The
  length of the issue's period before first_interest's follows Excel's
  documented DAYS360 US rule under bases 0 and 2 (a private days360
  helper).
- For a first_interest on the 29th or 30th whose schedule has a clamped
  28 February, with settlement before first_interest's period, the
  result differs from Excel. This is added to the list of differences.
- The arithmetic follows the operation order that reproduces Excel's
  results to the 15th significant digit.
- Constant time except for the whole periods between issue and a
  settlement after first_interest, which are added one at a time; under
  basis 1 a period's dates are computed only when its end rolls over.

The coupon schedule's couponsAfter is generalized into couponPeriodIndex
(the period of any date, on either side of the anchor), which the COUP*
functions use with unchanged results, and couponDate builds its result
without object spread. daysIn30DayMonths is exported from
DateTimeHelper.

Adds a catalogue entry, names in all language packs, the license table
entry and a changelog entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ACCRINTM, DISC, INTRATE, PRICEDISC, RECEIVED and YIELDDISC move from
FinancialPlugin into a new SecuritiesPlugin, together with the private
helpers only they use (discountedSecurity, isArgumentEmpty,
coerceToSecurityDate, coerceToDayCountBasis, strictNumber). The code is
moved unchanged, so the functions behave as before.

These functions share argument handling and day-count logic that the
rest of FinancialPlugin does not use. A plugin of their own keeps
FinancialPlugin readable as more securities functions are added.
The JSDoc of the six public methods in SecuritiesPlugin now gives each
@PARAM a type and a description, in the style the private helpers
already use. Comments only; no code changes.
The coupon schedule (CouponSchedule) and the computations on it move from
SecuritiesPlugin into a new CouponSchedule.ts: the coupon date k periods from
an anchor, the number of coupons after settlement, the days from the previous
coupon to settlement, the 30/360 period length, and the basis-1 period length
with its drifted coupon dates. They become plain functions that take the
engine's DateTimeHelper as their first argument, in place of reading
this.dateTimeHelper.

SecuritiesPlugin keeps the functions and their argument validation and
coercion, and calls the module. The date arithmetic of the schedule can now be
read and reused apart from the plugin. Behaviour is unchanged.
…odule

The quasi-coupon schedule (QuasiCouponSchedule, FIRST_INTEREST_PERIOD) and the
date computations from couponPeriodIndex to isMonthEnd move from SecuritiesPlugin
into CouponSchedule.ts, next to the coupon schedule maths they build on. They become
plain functions that take the engine's DateTimeHelper as their first parameter, like
the rest of the module; couponPeriodIndex and accruedCouponPeriods are exported for
the plugin, the others stay private to the module. ODDFPRICE and ODDLPRICE need the
same quasi-coupon periods.

Argument handling (accrint, coerceToCalcMethod) stays in the plugin. Behaviour is
unchanged.
ODDFPRICE and ODDLPRICE return the price per 100 face value of a
security with an odd (short or long) first or last coupon period. Both
live in SecuritiesPlugin and run through one private runner,
oddCouponPeriodBond, which validates their shared arguments in Excel's
order: left to right, each argument in full, then the amounts and the
order of the dates.

CouponSchedule.ts gains oddFirstPeriodPrice and oddLastPeriodPrice,
built on couponPeriodIndex and couponDate. Their quasi-coupon dates are
stepped one period at a time, as Excel steps them. accruedDays and
thirtyDayMonthDay now call the new dayCount and isFebruaryEnd helpers;
ACCRINT's and the coupon functions' results are unchanged.

Also: two error messages (FirstCouponDate, OddPeriodLength), catalogue
entries in categories/financial.ts, UNGROUPED_FUNCTIONS, names in all
18 language packs, and the changelog entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
hyperformula-docs 7cdfe9f Commit Preview URL

Branch Preview URL
Nov 19 2026, 01:28 PM

…o feature/HF-373

# Conflicts:
#	CHANGELOG.md
#	hyperformula/src/license/functionCapabilities.ts
develop's tree equals 6f288a8 (the HF-454 head squash-merged as #1799), which this branch already merged.
# Conflicts:
#	CHANGELOG.md
#	docs/guide/list-of-differences.md
#	hyperformula/src/license/functionCapabilities.ts
…-oddfprice-oddlprice

# Conflicts:
#	hyperformula/src/license/functionCapabilities.ts

@handsontable-pr-review handsontable-pr-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Medium risk: The change edits runtime i18n dictionaries (localized function-name parsing) and error-message strings across all languages, plus documentation; a wrong or missing translation makes localized Excel formulas unparseable for affected locales, but nothing existing is removed or redefined.

Incremental review: 2 potential issue(s).

hyperformula/src/i18n/languages/ruRU.ts:62

ruRU: CONCAT left untranslated; Russian Excel name is СЦЕП

Medium severity

The new entry maps CONCAT to 'CONCAT' while every other function added in this batch for ruRU is properly localized (ВЗЯТЬ, ТИП.ОШИБКИ, ВЫБОРСТОЛБЦ, etc.). Microsoft Excel's Russian name for CONCAT is СЦЕП (СЦЕПИТЬ is CONCATENATE, which this file already maps correctly). Russian-locale spreadsheets imported or typed into HyperFormula with =СЦЕП(...) will produce #NAME? even though the ruRU locale is supposed to accept Excel's Russian names.

Suggestion: Set CONCAT: 'СЦЕП' in ruRU.ts.

hyperformula/src/i18n/languages/deDE.ts:269

deDE: VALUETOTEXT left untranslated; German Excel name is WERTINTEXT

Low severity

The new entry maps VALUETOTEXT to 'VALUETOTEXT' while the surrounding new German entries (TEXTKETTE for CONCAT, ÜBERNEHMEN for TAKE, FEHLER.TYP for ERROR.TYPE) are localized. German Excel localizes the new text functions (TEXTVOR/TEXTNACH/TEXTKETTE), and its name for VALUETOTEXT is WERTINTEXT, so German-locale formulas using =WERTINTEXT(...) will fail with #NAME? under the deDE locale.

Suggestion: Set VALUETOTEXT: 'WERTINTEXT' in deDE.ts.

Want a deeper review? Comment /review improve on its own line: a full review of the latest commit with an extra fix-oriented pass (about 2x the cost).

Tobiadefami and others added 7 commits November 18, 2026 14:45
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… Excel

With settlement in February 1900 the previous coupon falls in 1899, before
Excel's date range. HyperFormula and Google Sheets return 181 for
=COUPDAYS(DATE(1900,2,15), DATE(1900,8,31), 2, 1), Microsoft Excel 184.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/guide/list-of-differences.md
ACCRINT now accrues from the last coupon date before settlement (calc_method
TRUE, settlement after first_interest) or from the coupon date before
first_interest, over first_interest's period length, and adds the periods back
to issue one at a time: each whole period counts 1, or 0 for calc_method FALSE,
and issue's period counts its days over its own length (30-day months for bases
0, 2 and 4). Coupon dates are stepped from one to the next. It matches all 800
random formulas measured in Excel Online at 15 significant digits, and the
first_interest-late-in-the-month difference is gone from the list of
differences.

The changelog entry formats the name as code and says what it returns.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The last coupon date before settlement and the coupon date on or before issue
are found from the months between the dates, corrected by a period, instead of
stepping one period at a time; chainedCouponDate generalizes driftedCouponDate
to both directions and month-end schedules. Results are bit-identical on 3,800
formulas, and a schedule from 1900 to 9999 takes 0.06 ms per cell instead of
0.63 ms. The day counts reuse toBasisUS and thirtyDayMonthDay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-oddfprice-oddlprice

# Conflicts:
#	CHANGELOG.md
#	hyperformula/src/interpreter/plugin/CouponSchedule.ts
@Tobiadefami

Copy link
Copy Markdown
Collaborator Author

Both points were addressed on 16 Nov: the description has the AI assistance section, and the changelog entry formats ODDFPRICE and ODDLPRICE as code and says what they return. The branch now merges the current feature/HF-453, with #1812's reworked ACCRINT code; the ODDFPRICE and ODDLPRICE specs pass unchanged.

@marcin-kordas-hoc marcin-kordas-hoc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At 7c06db0 with hyperformula-tests at b5c8828737, ODDFPRICE and ODDLPRICE still match Excel Online on all 298 cases from my first review, now on top of the reworked ACCRINT code. The description has the AI assistance section and the template's other sections, and the changelog entry formats both names as code and says what they return. The ODDFPRICE, ODDLPRICE and ACCRINT specs pass, 1,101 tests. This approval covers the ODDFPRICE and ODDLPRICE commits; the #1804 and #1812 code in this branch has its own reviews.

# Conflicts:
#	CHANGELOG.md
#	hyperformula/src/interpreter/plugin/CouponSchedule.ts
#	hyperformula/src/interpreter/plugin/SecuritiesPlugin.ts
# Conflicts:
#	hyperformula/src/license/functionCapabilities.ts
# Conflicts:
#	CHANGELOG.md
#	hyperformula/src/interpreter/plugin/CouponSchedule.ts
#	hyperformula/src/interpreter/plugin/SecuritiesPlugin.ts
# Conflicts:
#	hyperformula/src/interpreter/plugin/SecuritiesPlugin.ts
#	hyperformula/src/license/functionCapabilities.ts
…ice-oddlprice

# Conflicts:
#	CHANGELOG.md
#	hyperformula/src/interpreter/plugin/CouponSchedule.ts
#	hyperformula/src/interpreter/plugin/SecuritiesPlugin.ts
@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.40120% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.59%. Comparing base (8225c50) to head (7cdfe9f).

Files with missing lines Patch % Lines
...erformula/src/interpreter/plugin/CouponSchedule.ts 99.18% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1850      +/-   ##
===========================================
+ Coverage    97.57%   97.59%   +0.01%     
===========================================
  Files          211      211              
  Lines        17656    17821     +165     
  Branches      4084     4122      +38     
===========================================
+ Hits         17228    17392     +164     
- Misses         420      421       +1     
  Partials         8        8              
Files with missing lines Coverage Δ
hyperformula/src/error-message.ts 100.00% <100.00%> (ø)
hyperformula/src/i18n/languages/csCZ.ts 100.00% <ø> (ø)
hyperformula/src/i18n/languages/daDK.ts 100.00% <ø> (ø)
hyperformula/src/i18n/languages/deDE.ts 100.00% <ø> (ø)
hyperformula/src/i18n/languages/enGB.ts 100.00% <ø> (ø)
hyperformula/src/i18n/languages/esES.ts 100.00% <ø> (ø)
hyperformula/src/i18n/languages/fiFI.ts 100.00% <ø> (ø)
hyperformula/src/i18n/languages/frFR.ts 100.00% <ø> (ø)
hyperformula/src/i18n/languages/huHU.ts 100.00% <ø> (ø)
hyperformula/src/i18n/languages/idID.ts 100.00% <ø> (ø)
... and 12 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@handsontable-pr-review handsontable-pr-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

High risk: Adds new financial functions (ODDFPRICE/ODDLPRICE/PRICE/DURATION) on the calculation core path and edits the license capability table, so wrong math or gating would surface directly in user results.

Incremental review: 1 potential issue(s).

hyperformula/src/interpreter/plugin/CouponSchedule.ts:523

Settlement quasi-coupon period built with couponDate, not the stepped dates

Medium severity

oddFirstPeriodPrice computes settlement's quasi-coupon period with couponDate anchored at firstCoupon (L523, L527), but the PR defines the quasi-coupon schedule of a long first period as stepped back one period at a time via stepMonths, where the day drifts down and never recovers. couponDate re-clamps from the anchor each time, so the day recovers (e.g. firstCoupon 30 Aug semiannual: stepped dates are 28 Feb, 28 Aug; couponDate gives 28 Feb, 30 Aug). When settlement lies two or more quasi-coupon periods before firstCoupon and the day clamps in an intermediate month, periodStart differs from the stepped date, so E under basis 1 (periodEnd - periodStart) and DSC for bases 0, 1 and 4 (periodDays - dayCount(periodStart, settlement) in longFirstPeriodPrice L613-615) are computed from the wrong period start, yielding a price that differs from Excel's stepped schedule.

Suggestion: Derive settlement's quasi-coupon period from the stepped schedule (stepMonths from firstCoupon, or forward from settlement as quasiCouponsBeforeFirstCoupon does) instead of couponDate.

Want a deeper review? Comment /review improve on its own line: a full review of the latest commit with an extra fix-oriented pass (about 2x the cost).

@Tobiadefami
Tobiadefami merged commit 584e0ac into develop Nov 19, 2026
36 checks passed
@Tobiadefami
Tobiadefami deleted the feat/hf-442-oddfprice-oddlprice branch November 19, 2026 13:43
@Tobiadefami

Copy link
Copy Markdown
Collaborator Author

Not the case for Microsoft Excel Online: we measured 50 ODDFPRICE formulas with a long first period, first_coupon on 30 August (semiannual) or 31 May (quarterly), settlement two or more quasi-coupon periods before first_coupon (including between the 28th and the 30th), in all five bases. Excel returns the values HyperFormula returns, e.g. =ODDFPRICE(DATE(2010,8,29),DATE(2015,8,30),DATE(2009,1,15),DATE(2011,8,30),0.05,0.06,100,2,0) = 95.2240953557123, so Excel's quasi-coupon dates are re-clamped from first_coupon, as couponDate does, not stepped.

Tobiadefami added a commit that referenced this pull request Nov 20, 2026
### Context

This PR adds the Excel functions `YIELD`, `ODDFYIELD` and `ODDLYIELD`,
the yield of a security that pays periodic
interest, with a regular, an odd first or an odd last coupon period.
They are the inverses of `PRICE`, `ODDFPRICE`
and `ODDLPRICE`.

> [!IMPORTANT]
> **Stacked on #1850 (`ODDFPRICE`, `ODDLPRICE`) and #1848 (`PRICE`,
`DURATION`).** Each yield inverts its price
> function, so this branch is #1850's branch with #1848's branch merged
in (the commit `Merge feat/hf-438-price-duration
> (PRICE, DURATION) into the yields branch`). Both are stacked on #1812,
#1804 and #1799. Until they merge, this diff
> also shows their commits. The changes in this PR are the commit `Add
the YIELD, ODDFYIELD and ODDLYIELD functions`
> (and, once the PR exists, `Link the pull request in the changelog`).
Once the parents merge, `develop` will be
> merged into this branch and only these changes will remain in the
diff.

- `YIELD(settlement, maturity, rate, pr, redemption, frequency,
[basis])`
- `ODDFYIELD(settlement, maturity, issue, first_coupon, rate, pr,
redemption, frequency, [basis])`
- `ODDLYIELD(settlement, maturity, last_interest, rate, pr, redemption,
frequency, [basis])`

Behavior, checked against Excel:

- **Validation:** each yield checks its arguments in the same order as
its price function: `YIELD` as `PRICE`
(`basis` first, then left to right), `ODDFYIELD` and `ODDLYIELD` as
`ODDFPRICE` and `ODDLPRICE` (left to right). `pr`
takes the place of `yld`: `pr` ≤ 0 is `#NUM!`. The odd-period date rules
(the first coupon on `maturity`'s schedule,
  no regular-length first period) are the price functions'.
- **`YIELD`**:
- With one coupon period left, Microsoft's closed form; under bases 2
and 3 the period length is the actual one,
    so bases 1, 2 and 3 give the same yield.
- With more, Newton's method as Excel runs it: Excel's starting guess,
stopping when the next step is below 1E-10,
and after 100 steps returning the last yield rather than an error (Excel
does the same, for example with a
    redemption of 1E+50).
- With one coupon left and no 30/360 days from settlement to maturity
(settlement on the 30th, maturity on the 31st),
Excel keeps a non-finite value that shows as 0; HyperFormula returns
`#DIV/0!`. Added to the list of differences.
- Where Excel's iteration leaves the valid range it returns `#NUM!` (for
example `pr` of 3E+4 and more over nine
years), and a root below −`frequency` when every exponent is whole;
HyperFormula does the same.
- **`ODDFYIELD`**: Newton's method on `ODDFPRICE`, with the same guess
and stopping rule. HyperFormula returns the
yield at which `ODDFPRICE` gives `pr`, with `ODDFPRICE`'s exact
derivative. Excel steps with `PRICE`'s derivative instead of
`ODDFPRICE`'s and stops up to
about 1E-10 away from it, so some results agree with Excel to fewer than
15 digits (all within about 1E-10).
- **`ODDLYIELD`**: Microsoft's closed form, as Excel computes it (exact
round trips through `ODDLPRICE`). With no
30/360 days from settlement to maturity, `#DIV/0!` as for `YIELD` (also
in the list of differences).
- All three return negative yields.
- **Number format:** a plain number (Excel shows General).
- Dates before 1 March 1900: HyperFormula's date serials differ from
Excel's there, as for every date function.

### Implementation

- `yield`, `oddfyield` and `oddlyield` in `SecuritiesPlugin`. `YIELD`
shares a new private runner,
`periodicCouponBond`, with `PRICE` (PRICE's validation moves there
unchanged); the odd yields use #1850's
`oddCouponPeriodBond`, which now knows whether its second amount is a
yield or a price.
- In `CouponSchedule.ts`, each price function is split so its yield can
call it unchanged: `PRICE`'s maths into
`bondPrice` (with `bondPriceAndDerivative`, the price and its derivative
in one pass), `ODDFPRICE`'s into the
yield-independent `oddFirstPeriodTerms` and the formula over them,
`ODDLPRICE`'s into `oddLastPeriodTerms`.
`PRICE`, `DURATION`, `ODDFPRICE` and `ODDLPRICE` give bit-identical
results on all their measured cases before and
  after.
- The solver is a private Newton loop next to the yields (`solveYield`,
`yieldGuess`). `IRR`'s solver is not reused:
it starts from a given guess, stops on a small value and fails after 50
steps, which would not give Excel's
  yields; `IRR` is unchanged.
- One new error message, `NoDaysToMaturity`.
- Cost: O(N) in the coupons per Newton step, usually 3 to 10 steps.
- Catalogue entries in `categories/financial.ts`; the three added to
`UNGROUPED_FUNCTIONS` in `functionCapabilities.ts`.
- Names in all 18 language packs, from Microsoft's Excel function
reference in each language and, for Polish,
checked in Microsoft Excel Online. `csCZ` and `idID` keep the English
names, as for `PRICE`.
- `list-of-differences.md`: rows for `YIELD` and `ODDLYIELD` (above).
Changelog entry under Added.

### How did you test your changes?

- **Expected values come from Microsoft Excel Online.** Each test is one
measured case, with the measured formula on
the same fixture layout: the docs examples, every basis and frequency,
one coupon left, round trips through the
price functions, prices far from par, negative yields, the iteration
limits (very large redemptions, rates and
prices), short and long odd periods, the date bounds, coercion of every
argument, empty arguments, error
precedence, arrays and argument counts. Values are compared at Excel's
15 significant digits with
`smartRounding: false`. Where an iterative result's last digits are
below the solver's resolution, the test
compares fewer digits and its title says so (`YIELD` 37 cases at 13 or
14 digits; `ODDFYIELD` 73 at 7 to 13, see
above; `ODDLYIELD` 1 at 14). Text dates use `dateFormats: ['MM/DD/YYYY',
'YYYY-MM-DD']`, array constants
  `useArrayArithmetic: true`.
- **682 new tests** in hyperformula-tests: `function-yield` (317),
`function-oddfyield` (196), `function-oddlyield`
  (169). All failed before the engine change.
- **Full Jest suite** with the private tests: 541 suites, 12,426 passed,
3 skipped (pre-existing).
- **Mutation checks:** a solver tolerance of 1E-6 instead of 1E-10 fails
182 tests (`YIELD` and `ODDFYIELD`);
`ODDLYIELD` subtracting the accrued interest from the price instead of
adding it fails 72.
- `npm run lint` (no new warnings in `src/`), `npm run verify:typings`,
`npm run docs:generate-function-docs` (all
  three listed), `git diff --check`.

### AI assistance

Claude Code wrote the code, tests and docs. I reviewed it.

### Compatibility with Excel and Google Sheets

Excel: Microsoft Excel Online. Google Sheets: not checked.

| Formula | Excel | Google Sheets | HyperFormula |
|---|---|---|---|
| `=YIELD(DATE(2008,2,15),DATE(2016,11,15),0.0575,95.04287,100,2,0)` |
0.0650000068807314 | – | 0.0650000068807314 |
| `=YIELD(DATE(2008,2,15),DATE(2016,11,15),0.0575,155,100,2,0)` |
-0.0041552293507746 | – | -0.00415522935077461 |
| `=YIELD(DATE(2008,2,15),DATE(2016,11,15),0.0575,10^6,100,2,0)` |
`#NUM!` | – | `#NUM!` |
| `=YIELD(DATE(2008,1,30),DATE(2008,1,31),0.05,99,100,4,0)` | 0
(non-finite) | – | `#DIV/0!` |
|
`=ODDFYIELD(DATE(2008,11,11),DATE(2021,3,1),DATE(2008,10,15),DATE(2009,3,1),0.0575,84.5,100,2,0)`
| 0.0772455415972989 | – | 0.0772455415978175 |
|
`=ODDLYIELD(DATE(2008,4,20),DATE(2008,6,15),DATE(2007,12,24),0.0375,99.875,100,2,0)`
| 0.0451922356291692 | – | 0.0451922356291692 |
|
`=ODDLYIELD(DATE(2008,4,20),DATE(2008,6,15),DATE(2007,12,24),0.0375,150,100,2,0)`
| -2.13958265487612 | – | -2.13958265487612 |

HyperFormula matches Excel at 15 significant digits on every measured
case except: the last digits of iterative
results (above), the `YIELD` and `ODDLYIELD` rows with no 30/360 days to
maturity, and the general differences of all date functions
before 1 March 1900 and of argument counts.

### Public API changes

None. Three new built-in functions and one new error message.

### Out of scope and follow-ups

None.

### Types of changes

- [ ] Breaking change (existing functionality no longer works as before)
– agreed with the maintainers
- [x] New feature or improvement (a non-breaking change that adds
functionality)
- [ ] Bug fix (a non-breaking change that fixes an issue)
- [x] Additional language file, or a change to an existing language file
(translations)
- [x] Change to the documentation

### Related issues

1. HF-439 (`YIELD`), HF-443 (`ODDFYIELD`), HF-445 (`ODDLYIELD`).
2. Depends on #1850 and #1848, which depend on #1812, #1804 and #1799.
3. Tests: handsontable/hyperformula-tests#108

### Checklist

- [x] My pull request meets the [Definition of
Done](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DEFINITION-OF-DONE.md).
External contributors: see also [Contributing to
HyperFormula](https://handsontable.com/docs/hyperformula/guide/contributing.html).
- [ ] I have signed the [Contributor License
Agreement](https://goo.gl/forms/yuutGuN0RjsikVpM2).
- [ ] I read my own diff end to end before requesting a review.
- [x] I added a
[CHANGELOG.md](https://github.com/handsontable/hyperformula/blob/develop/CHANGELOG.md)
entry, written by [the changelog
rules](https://github.com/handsontable/hyperformula/blob/develop/dev-docs/DOC-STANDARDS.md#the-changelog)
– or none is needed (docs, tests or tooling only).
- [x] I updated the documentation and JSDoc to match the change.
- [ ] Breaking change only: I added a section to the migration guide.
- [x] I updated the `dev-docs/` pages this change affects – or none
needed it.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Large, numerically sensitive financial logic with iterative solvers
and many day-count edge cases; wrong yields/prices would affect
spreadsheet users even though there is no auth or external I/O.
> 
> **Overview**
> Adds a **securities/fixed-income function family** to
HyperFormula—coupon helpers (`COUPDAYBS`, `COUPDAYS`, `COUPNCD`, etc.),
accrual and discount math (`ACCRINT`, `ACCRINTM`, `DISC`, `INTRATE`,
`PRICEDISC`, `RECEIVED`, `YIELDDISC`), and bond **price/duration/yield**
(`PRICE`, `DURATION`, `YIELD`, `ODDFPRICE`/`ODDLPRICE`,
`ODDFYIELD`/`ODDLYIELD`)—implemented in a new **`SecuritiesPlugin`** and
a large shared **`CouponSchedule`** module (schedules, accrued interest,
Newton yield solver, odd first/last period pricing).
> 
> **Shared date infrastructure:** `DateTimeHelper.dayCountByBasis` and
`daysIn30DayMonths` centralize day-count conventions; **`YEARFRAC`** now
delegates to that helper instead of duplicating basis logic.
> 
> **Excel alignment notes:** docs list intentional gaps (e.g.
**`YIELD`/`ODDLYIELD`** return `#DIV/0!` when 30/360 gives zero days to
maturity, where Excel shows 0; some **`ACCRINT`/`YIELD`** cases differ
from Excel/Google). Polish **`PDURATION`** and Turkish **`VALUE`**
localized names were corrected so new **`DURATION`/`PRICE`** names match
Excel.
> 
> Catalog metadata, license **`UNGROUPED_FUNCTIONS`**, and all language
packs were updated for the new names.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
43f2507. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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