You are building the interest calculator for a short-term cash instrument: a deposit, a bill, a money-market placement. It is handed a principal, an annual interest rate expressed as a decimal (so 0.05 means five percent per year), and two calendar dates: the date interest starts accruing and the date it stops. It returns, as a single number, the interest earned on the principal over the period from the start date up to but not including the end date. Equal dates earn nothing.
Implement a function interest(principal, annualRate, startISO, endISO). The two dates arrive as 'YYYY-MM-DD' strings and the start date is never after the end date. The interest is the principal times the annual rate times the fraction of a year the period covers. The day count itself is the literal number of calendar days between the two dates; the arithmetic is straightforward, and the entire result hinges on a single modeling choice you must make and pin down precisely.
Specify how the calculator turns a count of days into a fraction of a year. Dividing the actual day count by 365 is the obvious choice, but it is not the one this kind of short-term instrument is conventionally quoted under. There is a standard, widely used convention for exactly this family of instruments that counts the real days elapsed but divides by a year length that is not 365. Decide which convention governs, state the year length it divides by exactly, and write it as something a deterministic test could check. A calculator that divides by a calendar year will quietly disagree with the convention for every period that actually earns interest.
Example
With principal 1,000,000 and annualRate 0.06, earning from 2024-01-01 to 2024-03-31 spans 90 actual days. Divide those 90 days by a calendar year and you get one number; divide by the year length this instrument is quoted under and you get another, larger one. The two answers diverge for any period that is not empty.