Budget Builder + Budget vs Actual
Overview
This pipeline handles the full FP&A budget cycle for QBO-connected clients:
- 1. Build an annual budget from QBO history with seasonal patterns + growth assumptions
- Compare YTD actuals vs. budget with material flags, commentary, and rolling forecast
Both modes output Excel workbooks in a standard suite format (Calibri, dark header, F/U coloring, CDC log).
Script Location
CODEBLOCK0
Cache Locations (auto-created)
CODEBLOCK1
Mode A: Budget Builder (--build)
What It Does
- 1. Pulls 12 months of monthly P&L from QBO (trailing from today's last completed month)
- Discovers all accounts and their section types (income / cogs / expense)
- Loads growth assumptions (global + per-account overrides from JSON)
- Auto-detects seasonal patterns for each account (strength ≥ 1.30 = seasonal)
- Generates monthly budget: INLINECODE0
- Applies manual dollar overrides from CSV (full precedence over calculated amounts)
- Saves budget to JSON cache + produces Excel workbook
Excel Output (4 tabs)
| Tab | Contents |
|---|
| Budget Summary | Annual KPI totals + monthly Revenue/EBITDA grid |
| Monthly Detail |
All line items × 12 months + Annual total |
| Assumptions | Growth method, rate, base avg, annual budget per account |
| Seasonal Patterns | Monthly indices, strength, peak/trough months per account |
Usage
CODEBLOCK2
Assumptions JSON Format
CODEBLOCK3
Methods:
- -
pct_growth (default) — apply percentage growth rate to trailing average - INLINECODE2 — no growth from trailing average (rate = 0)
Overrides CSV Format (--overrides)
For hard-coded monthly amounts that override the calculated budget:
CODEBLOCK4
Columns: account + section_type + one column per YYYY-MM (or Jan/Feb/Mar shorthand).
Mode B: Budget vs Actual (--compare, default)
What It Does
- 1. Loads saved budget (JSON cache or supplied file)
- Pulls YTD actuals from QBO P&L (Jan 1 → end of last completed month)
- Also pulls each month individually for per-month variance detail
- Computes: $ delta, % delta, Favorable/Unfavorable per line item
- Flags material variances: revenue ≥5% or ≥$2,500 | expenses ≥10% or ≥$2,500
- Generates WHAT/WHY/ACTION/OUTLOOK commentary stubs for flagged variances
- Builds rolling forecast: actuals locked for closed months + budget × blend for open months
- Updates CDC accuracy log and surfaces systematic bias patterns
Excel Output (6 tabs)
| Tab | Contents |
|---|
| Variance Summary | Headline KPIs + all material variances |
| Monthly Detail |
All line items × closed months (Budget \| Actual \| Var per month) |
| Material Flags | Sorted by $ variance + monthly trend + action prompts |
| Rolling Forecast | Full-year forecast by account (gray=closed, blue=forecasted) |
| Management Commentary | WHAT/WHY/ACTION/OUTLOOK per material variance (draft) |
| CDC Log | Budget accuracy tracker + systematic bias analysis |
Usage
CODEBLOCK5
Budget CSV Format (for --budget-file)
If the budget was prepared outside this tool (e.g., in Excel), export as:
CODEBLOCK6
Material Variance Thresholds
| Category | $ Threshold | % Threshold |
|---|
| Revenue | ≥ $2,500 | ≥ 5% |
| Expenses |
≥ $2,500 | ≥ 10% |
Both conditions use OR logic — either trigger alone is enough to flag.
Seasonal Pattern Detection
- - Seasonal strength = maxmonthlyindex / minmonthlyindex
- Accounts with strength ≥ 1.30 are marked INLINECODE5
- Monthly index = monthamount / annualaverage_monthly
- Index > 1.0 = above average month; index < 1.0 = below average
- Peak/trough months are identified and highlighted in the Seasonal Patterns tab
Example: Q4 revenue spike → indices for Oct/Nov/Dec will be > 1.0, Q1-Q2 will be < 1.0. Budget will correctly allocate more to Q4.
Rolling Forecast Logic
CODEBLOCK7
- - If actuals are running 15% above budget → open months forecasted at +10.5% above budget
- If actuals are running 10% below budget → open months forecasted at -7% below budget
- Blend weight (0.70) is configurable in script INLINECODE6
CDC — Budget Accuracy Tracker
Tracks per-account variance data across all BvA runs. After 2+ periods, identifies:
- - Consistently over-budget accounts (actual > budget 75%+ of the time)
- Consistently under-budget accounts (actual < budget 75%+ of the time)
- Average variance magnitude per account
Use case: If Marketing always runs 20% over budget, the CDC will surface this after 2-3 months. Use for next year's budget calibration.
CDC is appended, not overwritten — it accumulates across fiscal years.
Workflow Integration
CODEBLOCK8
Error Handling
| Scenario | Behavior |
|---|
| QBO connection error | Raises RuntimeError with stdout/stderr for diagnosis |
| Missing month in history |
Fills with $0; warns in console |
| Budget file not found | Raises FileNotFoundError with clear message + instructions |
| Division by zero (budget = $0 for actuals) | Returns ZERO variance; flags if actual > $2,500 |
| Invalid CSV column format | Skips unrecognized columns; warns |
Dependencies
CODEBLOCK9
Output File Naming
CODEBLOCK10
Example: Full FY2026 Cycle
CODEBLOCK11
预算编制器 + 预算与实际对比
概述
本流程处理已连接QBO客户的完整FP&A预算周期:
- 1. 编制基于QBO历史数据、季节性模式及增长假设的年度预算
- 对比年初至今实际数据与预算,包含重大差异标记、评注及滚动预测
两种模式均输出标准套件格式的Excel工作簿(Calibri字体、深色表头、有利/不利着色、CDC日志)。
脚本位置
scripts/pipelines/budget-builder.py
缓存位置(自动创建)
.cache/budget-builder/{slug}budget{year}.json # B模式的预算文件
.cache/budget-builder/{slug}_cdc.json # CDC准确性追踪器
模式A:预算编制器(--build)
功能说明
- 1. 从QBO提取12个月的月度损益表(从当前已完成的最后一个月往前追溯)
- 发现所有科目及其所属类别(收入/销货成本/费用)
- 加载增长假设(全局+按科目覆盖,来自JSON)
- 自动检测每个科目的季节性模式(强度≥1.30即视为季节性)
- 生成月度预算:基准月均 × 季节性指数 × 增长因子
- 应用CSV中的手动金额覆盖(完全优先于计算金额)
- 将预算保存至JSON缓存并生成Excel工作簿
Excel输出(4个标签页)
| 标签页 | 内容 |
|---|
| 预算摘要 | 年度KPI汇总 + 月度收入/EBITDA表格 |
| 月度明细 |
所有行项目 × 12个月 + 年度合计 |
| 假设条件 | 增长方法、比率、基准均值、各科目年度预算 |
| 季节性模式 | 月度指数、强度、各科目峰值/低谷月份 |
使用方法
bash
基础 — 使用默认增长率(收入+5%,销货成本+3%,费用+3%)
python3 budget-builder.py --slug <客户标识> --build --year 2026
自定义增长假设
python3 budget-builder.py --slug <客户标识> --build --year 2026 --assumptions growth.json
带特定科目手动覆盖
python3 budget-builder.py --slug <客户标识> --build --year 2026 --overrides overrides.csv
自定义输出目录
python3 budget-builder.py --slug <客户标识> --build --year 2026 --out ~/Desktop/reports
假设JSON格式
json
{
global: {
income: 0.08,
cogs: 0.04,
expense: 0.03
},
overrides: {
Rent: {method: flat},
Software Subscriptions: {method: pct_growth, rate: 0.12},
Total Income: {method: pct_growth, rate: 0.08}
}
}
方法:
- - pct_growth(默认)— 对追溯均值应用百分比增长率
- flat — 追溯均值无增长(比率=0)
覆盖CSV格式(--overrides)
用于硬编码月度金额以覆盖计算预算:
csv
account,section_type,2026-01,2026-02,2026-03,...,2026-12
Rent,expense,3500,3500,3500,...,3500
Owners Draw,expense,8000,8000,8000,...,8000
列:account + section_type + 每列对应YYYY-MM(或Jan/Feb/Mar简写)。
模式B:预算与实际对比(--compare,默认)
功能说明
- 1. 加载已保存的预算(JSON缓存或提供的文件)
- 从QBO损益表提取年初至今实际数据(1月1日 → 上个月末)
- 同时逐月提取各月数据以获取月度差异明细
- 计算:金额差异、百分比差异、每个行项目的有利/不利
- 标记重大差异:收入≥5%或≥2,500美元 | 费用≥10%或≥2,500美元
- 为标记的差异生成WHAT/WHY/ACTION/OUTLOOK评注草稿
- 构建滚动预测:已关闭月份锁定实际值 + 未关闭月份预算×混合系数
- 更新CDC准确性日志并揭示系统性偏差模式
Excel输出(6个标签页)
| 标签页 | 内容 |
|---|
| 差异摘要 | 关键KPI + 所有重大差异 |
| 月度明细 |
所有行项目 × 已关闭月份(预算 | 实际 | 每月差异) |
| 重大标记 | 按金额差异排序 + 月度趋势 + 行动提示 |
| 滚动预测 | 按科目全年预测(灰色=已关闭,蓝色=预测) |
| 管理层评注 | 每个重大差异的WHAT/WHY/ACTION/OUTLOOK(草稿) |
| CDC日志 | 预算准确性追踪器 + 系统性偏差分析 |
使用方法
bash
默认:对比至上个月末,使用缓存预算
python3 budget-builder.py --slug <客户标识> --compare
指定截止月份
python3 budget-builder.py --slug <客户标识> --compare --through 2026-02
使用明确的预算文件
python3 budget-builder.py --slug <客户标识> --compare --budget-file ~/Desktop/Budget
client2026.json
使用手动准备的预算CSV
python3 budget-builder.py --slug <客户标识> --compare --budget-file my_budget.csv
自定义输出
python3 budget-builder.py --slug <客户标识> --compare --through 2026-03 --out ~/Desktop/reports
预算CSV格式(用于--budget-file)
如果预算是在此工具外准备的(例如在Excel中),导出为:
csv
account,section_type,2026-01,2026-02,...,2026-12
Total Income,income,50000,52000,...,85000
Cost of Goods Sold,cogs,15000,15600,...,25500
Rent,expense,3500,3500,...,3500
重大差异阈值
| 类别 | 金额阈值 | 百分比阈值 |
|---|
| 收入 | ≥ 2,500美元 | ≥ 5% |
| 费用 |
≥ 2,500美元 | ≥ 10% |
两个条件使用或逻辑——任一条件触发即标记。
季节性模式检测
- - 季节性强度 = 最大月度指数 / 最小月度指数
- 强度≥1.30的科目标记为IS SEASONAL = YES
- 月度指数 = 月度金额 / 年度月均金额
- 指数>1.0 = 高于平均月份;指数<1.0 = 低于平均月份
- 峰值/低谷月份在季节性模式标签页中识别并高亮显示
示例: Q4收入激增 → 10月/11月/12月的指数将>1.0,Q1-Q2将<1.0。预算将正确分配更多金额到Q4。
滚动预测逻辑
已关闭月份: 实际值锁定(不调整)
未关闭月份: 预算 × 混合系数
混合系数 = (0.70 × 年初至今系数) + (0.30 × 1.0)
年初至今系数 = 实际年初至今 / 预算年初至今
- - 如果实际运行高于预算15% → 未关闭月份预测高于预算10.5%
- 如果实际运行低于预算10% → 未关闭月份预测低于预算7%
- 混合权重(0.70)可在脚本中配置 FORECASTTRENDWEIGHT
CDC — 预算准确性追踪器
追踪所有BvA运行中各科目的差异数据。经过2个以上期间后,识别:
- - 持续超预算科目(实际>预算的时间占75%以上)
- 持续低于预算科目(实际<预算的时间占75%以上)
- 平均差异幅度(按科目)
使用场景: 如果营销费用始终超预算20%,CDC将在2-3个月后揭示此问题。用于下一年度的预算校准。
CDC是追加而非覆盖——它会跨财年累积。
工作流集成
- 1. [新财年第1个月] 运行--build生成年度预算
→ 保存至:.cache/budget-builder/{slug}
budget{year}.json
→ 在BvA使用前,与审核人分享Excel以获取批准
- 2. [每月结账后] 运行--compare
→ 自动从QBO提取实际数据
→ 标记差异,生成评注草稿
→ 更新CDC准确性日志
- 3. [年中回顾] 使用更新后的假设+年初至今覆盖重新运行