13-Week Cash Flow Forecast in Python — Built From Open Invoices and Marked Against Actuals
A thirteen-week cash flow forecast is the report that tells a business whether it can pay its people next month. The useful version is not a spreadsheet of guesses: every line of it comes from something already in the books — the invoices open tonight, the day each customer actually pays rather than the day the contract says, the payment run that goes out on Mondays, and the tax, payroll and loan dates already in the treasury diary. This notebook writes that whole forecast as one function of the year, which is why its hardest question can point the same code at last year and measure how wrong it was.
By findi360 · Updated November 2026
- Format
- Jupyter notebook (.ipynb), outputs saved
- Data
- DATA DARE DD-CFP-001 · 20,346 bank rows · 21,319 invoices · a treasury calendar
- Covers
- 30 questions, easy to very hard
- Needs
- Python 3.9+, pandas, numpy, openpyxl
What goes into a direct cash forecast
Three streams and a balance. Receipts: every customer invoice open on the day the forecast is made, expected on its due date plus that customer's habitual delay. Payments: every supplier invoice open that day, paid in the first payment run on or after its due date. The calendar: payroll, tax, interest and dividends, which treasury already knows the dates of. Add them week by week to the bank balance on the night the forecast is made, and the closing balance of each week is the answer the business cares about.
The day a customer pays, not the day the contract says
This is the difference between a forecast that holds and one that does not. For every customer, the notebook averages the days between the due date and the day the money actually arrived, across the invoices it settled during the year just closed, and rounds that to whole days. A customer with no history is assumed to pay on time. One question in the notebook rebuilds the forecast on contractual terms instead and shows how much cash that version imagines arriving which never does.
Written once, as a function of the year
The forecast is a single function taking the year it is made in. That is what makes the last question possible: build the same forecast for 1 January 2025, with delays learnt from 2024, then compare each of its thirteen weeks against what the bank actually did, and average the differences. Backtesting a forecast is how a treasury team learns whether to trust it, and it costs almost nothing once the forecast is code rather than a worksheet.
Where forecasts go wrong
Two answers in the notebook show it plainly. First, the forecast made on 1 January can only see invoices that exist on 1 January — and a large share of the cash that arrived in the next thirteen weeks came from invoices raised after it was made. Second, the low point matters more than the end point: the closing balance at week thirteen looks comfortable, while the tightest week is the first one. A forecast read only at its final number hides exactly the week that needed managing.
Python or Excel?
Most treasury teams build this in Excel, and for one forecast that is reasonable. The trouble starts when you want last year's forecast marked against actuals, or the same forecast on contractual terms instead of real behaviour, or a rebuild every Monday morning. Each of those is a new worksheet in Excel and an argument to a function here.
Inside the notebook
- Libraries — A cell that tells you which libraries are missing before anything else runs.
- Load the sheets — The bank account, the invoices, the treasury calendar, the counterparties and the calendar.
- First look — What each category of bank row is worth, and the shape of the invoice book.
- Fix the data — The bank balance at a date, and what counts as an open invoice at the close of a day.
- The working tables — The bank by month, each customer's real delay, and the whole forecast as one function of the year.
- The answers, Q01 to Q30 — One cell per question, each ending with the answer, and a final list of all thirty.
Excel + Python — the Power of Plus
Excel does this model well when all five of these are true. When two or more are not, you add Python — not instead of Excel, beside it. That is the Power of Plus.
- One-off — you build it once, not again every month.
- Fixed structure — the same accounts, entities and layout each time.
- Small enough to check by eye — thousands of rows, not millions.
- One source — one ledger or one plan, not data scattered across systems and files.
- No live link needed — nobody expects it to update from the ledger by itself.
What next Monday's forecast really costs in Excel
- Export the open invoices again and rebuild the week columns around a new start date.
- Recalculate each customer's payment delay, or give up and use contractual terms.
- Re-point the treasury calendar rows into the new thirteen weeks.
- Marking last quarter's forecast against actuals means rebuilding the old forecast from scratch, so in practice nobody does it.
The same work, once it repeats
In Python the forecast is a function of the year: this week's run is one call, and last year's backtest is another.
Python still needs your judgement where the data is new — but everything after that repeats by itself.
Learn it on findi360: Python for Finance — Advanced Analytics & Reporting
Notify me when it opensWant to see what scattered data looks like? Three ERPs, three currencies and one consolidated group: DD-CON-004 — Diversified Group Close: Acquisition, Goodwill & Multi-ERP Consolidation
Who this model is for
- Treasury and finance teams who build or review a rolling 13-week cash forecast
- CFOs and controllers who want to know how accurate last quarter's forecast actually was
- Finance people learning Python on a report they already produce by hand
Frequently asked questions
What is a 13-week cash flow forecast?
A direct forecast of money in and money out, week by week, for the next quarter. It is built from open invoices and known commitments rather than from the profit and loss account, which is why it is the report used when cash is tight.
How does it decide when a customer will pay?
From that customer's own history: the average days between due date and settlement over the invoices it paid during the year just closed, rounded to whole days. A customer with no history is assumed to pay on its due date.
Can I run it on my own data?
Yes, once the column names match. It expects bank rows with a date and a signed amount, invoices with a posting date, a due date, an amount and a settled date, and optionally a calendar of known payments.
Can it tell me how good my last forecast was?
That is the final question in the file. The forecast is a function of the year, so it is run for the previous year and each of its thirteen weeks is compared with what the bank actually did; the answer is the average weekly difference.
Are the answers correct?
All thirty were compared with the Expected_Result_Value in the dataset's Question Bank, on pandas 2.2.3 and 3.0.5, before the file was published.
Keep going on findi360
- DATA DARE Mizan Manufacturing: The 13-Week Cash Forecast — Cash Flow Planning DD-CFP-001 · L1 — XLSX / ~10,000 rows Mizan Group: How Good Is the Treasury's Forecast? — Cash Flow Planning DD-CFP-002 · L2 — CSV / ~30,000 rows
- DATA DRILL Test yourself — Power BI practice questions One question at a time, or a 50-question timed simulation.
- GUIDE 13-week cash flow forecast in Python with pandas The same work in Python, with tested code and its real output.
- COURSE Courses and free recordings Power BI, Python and finance courses for finance professionals.
Related models
-
Accounts Payable in Python — Jupyter Notebook
The purchase ledger worked end to end: what is owed at any date, how much of it is overdue, how long suppliers really wait for their money, and the invoices that were posted twice and are still sitting in the balance.
-
AR Analysis in Python — Jupyter Notebook
A complete receivables working file in pandas: load four file formats, append the new quarter, build six working tables, then answer forty graded questions — from the ageing bucket to the overdue book corrected for cash nobody could place.
-
Trial Balance in Python — Jupyter Notebook
The general ledger worked end to end in pandas: a trial balance that proves it balances, a profit and loss account by reporting line, actuals against budget, and a gross profit bridge that explains why profit grew less than sales.
Need a model we have not built yet?
Tell us what you need. Members vote, and the most-requested models are built first — free to download.
Educational model on illustrative data. Not investment, accounting or tax advice. © findi360 — share freely with attribution.
