Create high-quality, auditable Excel models and audit trails for CP2 exams
You are an actuarial model developer sitting the CP2 (Modelling Practice) exam. Your task is to build a high-quality, robust, and auditable Excel model using Python and openpyxl, and to produce the required audit trail and summary report.
Build a Professional Excel Model:
Generate an Audit Trail (Paper 1):
Produce a Summary Report (Paper 2):
You will use Python with openpyxl to construct the Excel file programmatically. This ensures precision and reproducibility.
exams/<SUBJECT>/<SITTING>/question-paper.md).scripts/excel_helper.py.Plan your Excel workbook structure before writing code. A standard CP2 model should have:
Documentation / Index sheet: Model name, author (Candidate Number), date, description, colour key.Parameters sheet: All assumptions and inputs (e.g., interest rates, mortality params). Nothing hard-coded elsewhere!Data sheet: The raw data, clearly labelled.Calculations / Workings sheet(s): The detailed step-by-year calculations.Results / Summary sheet: Key outputs, charts, and checks.Audit Trail sheet (if required by the specific question, otherwise strictly in the Word/Markdown doc).Write a Python script (model_builder.py) using openpyxl to generate the .xlsx file.
openpyxl.styles (Font, PatternFill, Border, Alignment).0.00% for rates, #,##0 for currency).Summary or Calculations sheet.IF(ABS(Sum_Calculated - Sum_Data) < 0.01, "OK", "ERROR").model_builder.pyfrom openpyxl import Workbook
from openpyxl.styles import Font, PatternFill, Border, Side, Alignment
# --- Styles ---
header_font = Font(bold=True, color="FFFFFF")
header_fill = PatternFill(start_color="4F81BD", end_color="4F81BD", fill_type="solid")
input_font = Font(color="0000FF") # Blue for inputs
check_ok_fill = PatternFill(start_color="C6EFCE", end_color="C6EFCE", fill_type="solid") # Light Green
check_err_fill = PatternFill(start_color="FFC7CE", end_color="FFC7CE", fill_type="solid") # Light Red
wb = Workbook()
# --- 1. Parameters Sheet ---
ws_params = wb.active
ws_params.title = "Parameters"
ws_params.append(["Parameter", "Value", "Description"])
# Apply styles...
# --- 2. Data Sheet ---
ws_data = wb.create_sheet("Data")
# Load data from source and write here...
# --- 3. Calculations Sheet ---
ws_calc = wb.create_sheet("Calculations")
# Build formulae...
# Example: =Parameters!B2 * Data!B2
# --- 4. Checks ---
# Add explicit check cells
ws_calc["E1"] = "Check: Assets = Liabilities"
ws_calc["E2"] = '=IF(ABS(C10-D10)<0.01, "OK", "FAIL")'
# Save
wb.save("results/<MODEL>/<SUBJECT>/<SITTING>/CP2_Model.xlsx")
Paper 1 specifically asks for an Audit Trail. This documents what you did, how you did it, and why.
Structure:
Output: Save this as audit_trail.md (or part of attempt.md).
Paper 2 asks for a Summary Report.
Structure:
Output: Save this as summary_report.md (or part of attempt.md).
results/ folderCP2_Model.xlsx - The working, audited Excel model.attempt.md - Containing the Audit Trail (Paper 1) OR Summary Report (Paper 2).model_builder.py - The script used to generate the model.