Sub topic 14
Optional: Scripting the Tie-Out Checks
This chapter assumes you can use basic Python, pandas, and spreadsheet formulas. You should also understand the balance sheet, cash flow statement, and the historical tab’s row and column structure.
A scripted check repeats the same tests across several periods. It does not replace a review of the annual report. It helps you find extraction errors such as a missing row, a swapped sign, or a value entered in the wrong year.
What to check
A useful script tests accounting relationships that should hold after the data has been extracted:
- Balance sheet check: total assets minus total liabilities minus total equity should be zero.
- Cash check: ending cash on the cash flow statement should equal cash on the balance sheet.
- Period coverage: every required fiscal year should have values for key rows.
- Tolerance: small differences caused by rounding may be acceptable, but larger differences require investigation.
Treat noncontrolling interest consistently. If the balance sheet reports it outside stockholders’ equity, include it in the equity value used by the check, or add it as a separate term.
| Check | Expected result | Typical investigation |
|---|---|---|
| Assets − liabilities − equity | Near 0 | Missing liability, sign error, or wrong period |
| Cash flow ending cash − balance sheet cash | Near 0 | Cash definition or period mismatch |
| Required input is present | True | Extraction or report-layout issue |
A small pandas tie-out
The following example stores each fiscal year as a column and each accounting measure as a row. The figures are illustrative. In a real model, load values from a reviewed extraction rather than copying them directly into the script.
import pandas as pd
bs = pd.DataFrame(
{
"FY2022": {
"total_assets": 1000.0,
"total_liabilities": 600.0,
"total_equity": 400.0,
},
"FY2023": {
"total_assets": 1120.0,
"total_liabilities": 655.0,
"total_equity": 465.0,
},
}
)
diff = (
bs.loc["total_assets"]
- bs.loc["total_liabilities"]
- bs.loc["total_equity"]
)
print(diff)
print("Within tolerance:")
print(diff.abs().lt(0.5))The first output shows the difference for each year. The second output returns True when the absolute difference is less than 0.5. This tolerance is an example, not a universal rule. Use a tolerance that matches the report’s units and rounding. A report stated in millions may need a larger tolerance than a detailed data set stated in whole dollars.
Make failures actionable
A Boolean result tells you whether a check passed, but a useful validation also reports the failing periods and the measured difference.
tolerance = 0.5
failures = diff[diff.abs() >= tolerance]
if failures.empty:
print("Balance sheet check passed.")
else:
print("Balance sheet check failed:")
for period, amount in failures.items():
print(f" {period}: difference = {amount:.2f}")Do not automatically “fix” a failing check by forcing a balancing plug. A plug hides the cause and can corrupt the forecast handoff. Trace the failure to the source statement, footnote, sign convention, or period label.
Connect the script to the workbook
Keep sourced inputs separate from formulas in the spreadsheet. The script should read the same normalized values that the historical tab uses, then compare its results with workbook checks. This creates two independent controls:
- Spreadsheet formulas expose the issue while the model is open.
- Python checks can test every year consistently and can run after a new extraction.
A check that passes is evidence of internal consistency, not proof that every number was classified correctly. Review unusual movements, restatements, acquisitions, and changes in presentation separately.
The validation flow
Exercise
A balance sheet check fails by 25.0 in FY2023, while FY2022 passes. What should you investigate before adding a plug?
Show answer
Compare FY2023 row by row with the report. Check for a missing liability or equity item, a sign error, a restatement, a unit mismatch, or a value assigned to the wrong fiscal year.