Monthly cash forecasts hide the week that breaks: two payroll runs in one month, a tax payment, a customer who pays late. A 13-week forecast fixes that by stepping one week at a time. Here is the whole thing in plain Python, with every amount in integer cents so nothing drifts.

def forecast(cash, weekly_in, weekly_out, payroll, payroll_every, first_payroll, lumps, weeks=13): """All amounts in integer cents. lumps: {week: signed cents}.""" rows = [] for w in range(1, weeks + 1): cash += weekly_in - weekly_out if w >= first_payroll and (w - first_payroll) % payroll_every == 0: cash -= payroll cash += lumps.get(w, 0) rows.append(cash) return rows def report(rows, reserve): low = min(rows) low_week = rows.index(low) + 1 first_under = next((i + 1 for i, c in enumerate(rows) if c < reserve), None) short = max(0, reserve - low) return low, low_week, first_under, short rows = forecast(4_200_000, 1_750_000, 720_000, 2_100_000, 2, 1, {5: -1_600_000, 8: 950_000}) print([r // 100 for r in rows]) print(report(rows, 1_500_000)) 

Output:

[31300, 41600, 30900, 41200, 14500, 24800, 14100, 33900, 23200, 33500, 22800, 33100, 22400] (1410000, 7, 5, 90000) 

Reading it: the account starts at $42,000 with a $15,000 reserve. Cash first goes under the reserve in week 5, when a $16,000 tax payment lands in a payroll week. The lowest point is week 7 at $14,100, which is $900 short of the reserve. Week 13 closes at $22,400. A monthly view of the same numbers never gets near zero and looks merely "a bit tight".

A few design choices worth copying:

  • Integer cents everywhere. 1_750_000 is $17,500.00. Weekly additions repeated 13 times never accumulate float error.
  • Payroll as a schedule, not an average. first_payroll and payroll_every put each run in its real week. Averaging payroll over the month is exactly what hides the bad week.
  • One dict for lumps. Signed cents keyed by week: payments negative, receipts positive. Adding a new known bill is one entry.
  • Report the shortfall, not just the low point. short is what you need to find (or delay) before the low week, which is the actionable number.

If you would rather not run code, the same arithmetic is in a free browser tool: 13-Week Cash Flow Calculator (free, no sign-up).