Stocks gained 7% in the first quarter of 2023, snapping a painful three-quarter losing streak and overcoming a sudden, new, and unexpected threat to the banking system that has complicated the Federal Reserve’s aggressive yearlong monetary tightening balancing act to lower inflation without triggering a recession.