The Data Layer is a versioned, relational database that serves as the immutable system of record for all modeling activities. Every input, execution, and output is permanently archived with full audit trails.
Core Principle: Nothing is ever overwritten. All data is append-only, creating perfect reproducibility and temporal analysis capabilities.
-- Compare actual vs. projected for year 2024SELECT actual.repurchase_amount as actual_repurchases, simulated.repurchase_amount as projected_repurchases, (actual.repurchase_amount - simulated.repurchase_amount) as varianceFROM annual_trust_states actualJOIN annual_trust_states simulated ON actual.year = simulated.yearWHERE actual.source_type = 'actual' AND simulated.source_type = 'simulated' AND actual.year = 2024;
The immutable architecture enables sophisticated temporal queries:
Forecast Evolution
Track how your forecasts changed over time:
Copy
Ask AI
-- How did our 2028 repurchase forecast evolve?SELECT sr.completed_at as forecast_date, ats.repurchase_amount as projected_2028_repurchasesFROM simulation_runs srJOIN annual_trust_states ats ON sr.id = ats.simulation_run_idWHERE ats.year = 2028 AND ats.source_type = 'simulated'ORDER BY sr.completed_at;
Assumption Impact
Identify which assumption changes drove result differences:
Copy
Ask AI
-- What changed between runs?SELECT jsonb_diff( old_run.operating_assumptions, new_run.operating_assumptions ) as assumption_changesFROM scenarios old_run, scenarios new_runWHERE old_run.id = 'acme_v1' AND new_run.id = 'acme_v2';
Accuracy Analysis
Compare forecasts to actuals to measure model accuracy:
Copy
Ask AI
-- How accurate was our 2024 forecast made in 2023?SELECT projected.repurchase_amount as forecast, actual.repurchase_amount as actual, ABS(projected.repurchase_amount - actual.repurchase_amount) / actual.repurchase_amount as error_percentageFROM annual_trust_states projectedJOIN annual_trust_states actual ON projected.year = actual.yearWHERE projected.source_type = 'simulated' AND projected.simulation_run_id = 'run_2023_forecast' AND actual.source_type = 'actual' AND actual.year = 2024;
-- Fast simulation run lookupsCREATE INDEX idx_runs_scenario ON simulation_runs(scenario_id, completed_at);-- Fast year-based queriesCREATE INDEX idx_trust_year ON annual_trust_states(simulation_run_id, year);-- Fast participant lookupsCREATE INDEX idx_participant ON annual_participant_snapshots(participant_id, year);
Partitioning
Large tables partitioned by simulation_run_id for faster queries and easier archival.
Materialized Views
Pre-computed aggregations for common dashboard queries (e.g., total repurchase obligations by year).