Foundations of system-wide financial stress testing with heterogeneous institutions