Prepaid Amortization by Days, With Claude
How do you amortize a prepaid invoice by days?
On 5 Nov 2026 we gave Claude five written rules and one file of 80 invoices, and it wrote the program. The file holds services that cross a leap day, services of one day and amounts that land on half a cent.
Which CSV columns does it use?
| Column | What the script does with it |
|---|---|
service_start, service_end | Both days count. These set every day count |
amount | Split in proportion to the days in each month |
invoice_id | Row key, named in every error |
The invoice date and the account columns are in the file and the script ignores them. Every invoice in this file is dated on or before the day its service starts, so no month needs catching up.
What plan does Claude give first?
I work in the accounting team. I want a small tool that spreads each prepaid invoice over its service months by day count. I have one file, prepaid_invoices.csv (invoice_id, vendor, description, invoice_date, amount, service_start, service_end, expense_account, prepaid_account). Every invoice is dated on or before the day its service starts, so nothing needs catching up. Our policy: 1. Both service_start and service_end count as service days. A service from 1 Jan to 31 Jan is 31 days. 2. A month's expense is the amount times the days of service in that month, divided by the total days of service. 3. Round each month to the cent. The last month of the service takes whatever is left, so the months add up to the amount exactly. 4. A service can run for several years. Write one row for every month of the service, whatever the year. 5. If a date or an amount cannot be read, or service_end is before service_start, stop, say which line is wrong, and write no output file. Do not write code yet. Break the job into numbered steps. For each step say what could go wrong. Then list anything in the policy that is unclear.
Claude gave nine steps. In step 7 it said that over 36 months the drift in the last month can reach about 17 cents, and that the script should check each invoice adds up. PD-080, a 36 month invoice, drifts 2 cents: 1,018.25 in the other 31-day months and 1,018.23 in the last.
Under the unclear points it asked whether a half cent rounds up or to the nearest even cent, and said the two give different cents. A second run, started with no memory of the first, asked the same question. We did not answer either.
What script does Claude write?
Good. Use that plan. Write one Python script, standard library only, that reads the file and writes prepaid_months.csv with one row for every invoice and service month: invoice_id, month (YYYY-MM), service_days, expense. Use exact decimal arithmetic for money. Never change my file. Run it, then show me the total of the expense column, say whether it equals the total of the amount column, and show the rows of every invoice whose service lasts one day or runs through February 2028.
In Claude Code on 5 Nov 2026, Claude Sonnet 5.5 (claude-sonnet-5-5) got the plan prompt and the build prompt as separate messages. It wrote a 156 line standard library script with money in Decimal, Python's exact decimal type.
It produced 615 month rows for 80 invoices. The expense column and the amount column both added to 2,927,142.04. The second run wrote a 134 line script and reached the same two totals. Both took the half cent up.
How does the day count work on real invoices?
The rule as we wrote it: Round each month to the cent. The last month of the service takes whatever is left, so the months add up to the amount exactly. Eight of the 80 services contain 29 Feb 2028. Four last one day. Five run from the first to the last day of a month.
| Invoice | Amount and dates | What the script wrote |
|---|---|---|
| PD-047 | 3,150.00, 28 Feb 2026, one day | One row, 1 day, 3,150.00. |
| PD-021 | 2,000.00, 29 Feb 2028, one day | One row, 1 day, 2,000.00. The date exists only in a leap year. |
| PD-030 | 5,800.00, 1 to 29 Feb 2028 | One row, 29 days, 5,800.00. |
| PD-004 | 5,000.00, 1 Dec 2027 to 31 Mar 2028, 122 days | Dec 1,270.49, Jan 1,270.49, Feb 1,188.52 (29 days), Mar 1,270.50. March takes the leftover cent. |
| PD-074 | 18,250.00, 29 Feb 2028 to 28 Feb 2029, 366 days | 13 rows. The first month is one day, 49.86, and the last is 1,396.15. |
| PD-080 | 36,000.00, 1 Nov 2026 to 31 Oct 2029, 1,096 days | 36 rows. Every other 31-day month is 1,018.25. The last month, also 31 days, is 1,018.23. |
In the first run's reply to the second message, Claude said twelve invoices run through February 2028. The rows it printed were ten, plus four one-day invoices, one of them in both lists, which makes 13 in all. The second run said 13. The script was right in both runs.
What happens when an amount lands on half a cent?
Ten of the 80 invoices contain a month where the unrounded figure ends in exactly half a cent. In both runs Claude rounded half up, which is what our key assumes, so every one of the 1,230 cells matched. Against a key built with half to even, 26 cells differ:
| Invoice | Amount and dates | Half up (Claude) | Half to even | Last month |
|---|---|---|---|---|
| PD-012 | 29,317.22, 16 Sep 2027 to 13 Jan 2028, 120 days | Nov 2027: 7,329.31 | Nov 2027: 7,329.30 | Jan 2028: 3,176.02 and 3,176.03 |
| PD-026 | 22,325.40, 9 Apr 2026 to 13 May 2027, 400 days | Four 30-day months at 1,674.41 | Four 30-day months at 1,674.40 | May 2027: 725.54 and 725.58 |
We also made 3,000 random invoices: 42 of them would show different months under half to even.
What happens in awkward cases?
Eighteen single invoices went through the first script, each against a reference written from the same rules.
They covered a year-end rollover, a service that starts on 29 Feb 2028, three days across the leap day, 0.01 over three months, 9,999,999.99 over three years and an amount with no cents.
Every case the script accepted matched the reference. Then 3,000 random invoices, 26,610 month rows, with services from one day to just over three years: no differences.
What happens with bad data?
| What we sent | What happened |
|---|---|
| End before start, a blank amount, 5,000.00 with a comma, a date typed 01/03/2026, a 29 Feb 2027 date | All stopped at the line, in both scripts, and neither wrote a file |
| A bad amount on the second invoice | Stopped and named line 3, where that invoice sits in the file |
| An amount of 0.00 and a credit note of -2,000.00 | The first script stopped on both. The second took both |
| An amount with three decimals, 1000.005 | The first script stopped. The second wrote months that add to 1000.00 and dropped the half cent |
| The same invoice_id twice | The first script went on and wrote both. The second stopped on a sum check that named X1 but did not say the id was repeated |
Rule 5 named an unreadable date or amount and an end before the start. Both scripts stopped on those. The policy said nothing about zero, negative or three decimal amounts or repeated ids, and the two scripts disagreed.
Questions about prepaid amortization by days
What do you need to amortize prepaid invoices by days with Claude?
How well did Claude amortize prepaid invoices?
How does Claude round a half cent?
Book a demo
Use the message box to tell us your ERP and the process you want to start with.