Settlement Date
Adding a number of days to a date is the easy part the model gets for free. The hidden test is which days count: settlement advances by business days, skipping weekends and a specific set of market holidays a vague spec never names, so a plain calendar offset lands a day or more early.
You are building the settlement-date calculator for a trading system. When a trade executes on a given date, it settles a fixed number of days later. The function is handed the trade date and the settlement offset and returns the date on which the trade settles. This date drives when cash and securities actually move, so it must land on a day the market is open.
Implement a function settlementDate(tradeISO, daysT). The trade date arrives as a 'YYYY-MM-DD' string and daysT is a positive integer, the settlement offset (a T-plus-N convention). The naive answer adds daysT calendar days to the trade date, but settlement does not advance over days the market is closed. The entire result hinges on which days are allowed to count toward the offset, a choice you must make and pin down precisely.
Specify exactly which days advance the settlement count and what happens at the boundary. Settlement advances only over business days: weekends never count, and neither do a specific set of market holidays. Counting only weekday-versus-weekend is the obvious partial answer, but it ignores the holidays, which a real settlement calendar must skip. State which days are holidays (embed a concrete list the test can rely on), state that the offset is counted in business days rather than calendar days, and state what happens if the landing date itself is a non-business day (it rolls forward to the next business day). Write this as something a deterministic test could check. A calculator that adds calendar days, or that skips only weekends, will settle a trade earlier than the market actually allows whenever a holiday falls in the window.
A trade on 2024-07-03 settling T+1 does not settle on 2024-07-04, because that day is a market holiday: settlement rolls to the next business day, 2024-07-05. A calculator that only skips weekends would wrongly settle on the 4th.
- settlementDate(tradeISO, daysT) returning a 'YYYY-MM-DD' string.
- tradeISO is a 'YYYY-MM-DD' string; daysT is a positive integer offset.
- A trade whose offset lands on a plain weekday settles on that weekday.
The functional tests are shown, and the model usually clears them on its own. The hidden tests are the twists this kind of system is full of. They are not listed. Your spec only passes them if it already knows where this domain breaks.
204 chars