# Orxaq Regulatory Demo

Run the complete CECL/CCAR filing workflow end-to-end with a single command.

## Quickstart

```bash
python -m orxaq demo regulatory
```

Expected output:

```
Orxaq Regulatory Demo — DEMO_BANK_001  2025Q4
Output directory: /path/to/demo_output
Compliance status: PASS  Duration: 1.23s
Audit entries: 12  Files generated: 8

  /path/to/demo_output/cecl_disclosure.json
  /path/to/demo_output/ccar_export.json
  /path/to/demo_output/schedule_h1.csv
  /path/to/demo_output/scenario_comparison.csv
  /path/to/demo_output/regulatory_report.html
  /path/to/demo_output/regulatory_report.md
  /path/to/demo_output/audit_trail.json
  /path/to/demo_output/manifest.json
```

## What the Demo Does

1. **Generates a synthetic portfolio** — 100 loans, fixed seed for reproducibility
2. **Fits a causal PD model** — backdoor-adjusted probability of default via WorldDAG
3. **Runs CECL engine** — lifetime expected credit loss per ASC 326
4. **Runs 3-scenario stress test** — baseline / adverse / severely_adverse (Fed CCAR scenarios)
5. **Generates the regulatory package** — 8 output files with SHA-256 manifest
6. **Validates outputs** — checks CECL and CCAR JSON against regulatory schemas

## Output Files

| File | Regulatory Purpose |
|------|-------------------|
| `cecl_disclosure.json` | CECL allowance disclosure per ASC 326-20 |
| `ccar_export.json` | Federal Reserve CCAR submission template |
| `schedule_h1.csv` | FR Y-14A Schedule H.1 (9-quarter stress horizon) |
| `scenario_comparison.csv` | Baseline / Adverse / Severely Adverse ECL comparison |
| `regulatory_report.html` | Full HTML report with executive summary and risk metrics |
| `regulatory_report.md` | Markdown version of the regulatory report |
| `audit_trail.json` | Timestamped audit log of every pipeline step |
| `manifest.json` | SHA-256 checksums + file sizes for all 7 output files |

## Customization

```bash
# Custom institution and period
python -m orxaq demo regulatory \
  --institution-id FIRST_NATIONAL_BANK_001 \
  --period 2026Q1 \
  --output-dir ./filings/2026q1

# JSON output for automation
python -m orxaq demo regulatory --json | jq '.compliance_status'

# Check all file paths
python -m orxaq demo regulatory --json | jq '.files[]'
```

## Options

| Flag | Default | Description |
|------|---------|-------------|
| `--output-dir` | `./demo_output` | Directory for output files |
| `--institution-id` | `DEMO_BANK_001` | Institution identifier in filings |
| `--period` | `2025Q4` | Reporting period (YYYYQN) |
| `--seed` | `42` | Random seed for synthetic data |
| `--json` | off | Machine-readable JSON output |

## Python API

```python
from orxaq.experiences.demo import run_regulatory_demo

result = run_regulatory_demo(
    output_dir="./filings",
    institution_id="MY_BANK",
    period="2025Q4",
    seed=42,
)
print(result["compliance_status"])  # "PASS"
print(result["files"])              # list of 8 file paths
print(result["audit_entries"])      # number of audit log entries
```
