66 lines
2.3 KiB
Python
66 lines
2.3 KiB
Python
"""Tests for workbook runner and dashboard."""
|
|
|
|
import os
|
|
import tempfile
|
|
|
|
from fqbm.state import FQBMState
|
|
from fqbm.workbook.runner import run_workbook
|
|
from fqbm.sheets.dashboard import dashboard_aggregate
|
|
from fqbm.sheets.monte_carlo import run_n_simulations, ShockSpec
|
|
|
|
|
|
def test_run_workbook():
|
|
state = FQBMState(R=200, Deposits=1000, Loans=900, E_b=100)
|
|
result = run_workbook(initial_state=state, mc_runs=5)
|
|
assert "state" in result
|
|
assert "stress" in result
|
|
assert "dashboard" in result
|
|
assert "liquidity_stress" in result["stress"]
|
|
assert "capital_stress" in result["stress"]
|
|
assert "ratios" in result["dashboard"]
|
|
|
|
|
|
def test_dashboard_aggregate():
|
|
state = FQBMState(R=100, Deposits=500, Loans=400, E_b=80)
|
|
dash = dashboard_aggregate(state, mc_runs=3, shock_spec=ShockSpec(seed=42))
|
|
assert "state" in dash
|
|
assert "ratios" in dash
|
|
assert "mc_summary" in dash
|
|
assert "p_insolvency" in dash["mc_summary"]
|
|
|
|
|
|
def test_run_n_simulations():
|
|
df = run_n_simulations(20, shock_spec=ShockSpec(seed=1))
|
|
assert len(df) == 20
|
|
assert "insolvent" in df.columns
|
|
assert "reserve_breach" in df.columns
|
|
assert "inflation" in df.columns
|
|
assert "debt_sustainable" in df.columns
|
|
|
|
|
|
def test_run_workbook_with_cbdc():
|
|
from fqbm.sheets.cbdc import CBDCParams
|
|
state = FQBMState(R=100, Deposits=500, Loans=400, E_b=80)
|
|
result = run_workbook(initial_state=state, cbdc_params=CBDCParams(deposit_shift=10))
|
|
assert result["state"].Deposits == 490
|
|
assert result["state"].R == 90
|
|
assert result["cbdc"] is not None
|
|
assert result["cbdc"]["cbdc_liability"] == 10
|
|
|
|
|
|
def test_run_workbook_with_ccp():
|
|
from fqbm.sheets.ccp import CCPParams
|
|
result = run_workbook(ccp_params=CCPParams(margin_posted=100, margin_obligations=100, vm_calls=5, liquidity_buffer=10))
|
|
assert result["ccp"] is not None
|
|
assert result["ccp"]["ccp_identity_holds"] is True
|
|
assert result["ccp"]["waterfall_triggered"] is False
|
|
|
|
|
|
def test_workbook_excel_export():
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
path = os.path.join(tmp, "fqbm_out.xlsx")
|
|
state = FQBMState(R=100, Deposits=500, Loans=400, E_b=80)
|
|
run_workbook(initial_state=state, mc_runs=3, export_path=path)
|
|
assert os.path.isfile(path)
|
|
assert os.path.getsize(path) > 0
|