#!/usr/bin/env python3
"""Quickstart: End-to-end credit risk workflow in 30 lines.

Demonstrates the core Orxaq pipeline:
1. Load the credit ontology into the World DAG.
2. Generate synthetic data.
3. Fit a causal PD model.
4. Compute CECL expected credit loss.
5. Run a stress test.
"""

from orxaq.orchestration.integration import OrxaqEngine

# 1. Initialize the engine and load the credit ontology.
engine = OrxaqEngine()
dag = engine.load_credit_ontology()
print(f"Loaded {dag.node_count()} variables, {dag.edge_count()} causal edges")

# 2. Generate synthetic data (1000 borrowers, seed=42 for reproducibility).
data = engine.generate_synthetic(n=1000, seed=42)
print(f"Generated {len(data)} borrower records")

# 3. Fit the causal PD model.
model = engine.fit_pd_model(data)
sample_pd = model.predict_pd(data[0])
print(f"Sample borrower PD: {sample_pd:.6f}")

# 4. Compute CECL expected credit loss.
ecl = engine.compute_ecl(data)
print(f"Total ECL: {ecl.total_ecl:.6f}")
print(f"Horizon: {ecl.horizon_quarters}Q ({ecl.horizon_method})")
lo, hi = ecl.confidence_band
print(f"Confidence band: [{lo:.6f}, {hi:.6f}]")

# 5. Stress test under adverse scenario.
stress = engine.stress_test(data, "adverse")
print(f"\nStress test ({stress['scenario']}):")
print(f"  Base PD:   {stress['base_pd']:.6f}")
print(f"  Stress PD: {stress['stress_pd']:.6f}")
print(f"  Delta:     {stress['delta']:+.6f}")
