The question of what drives stock price movements is fundamental in the theory of financial markets, and one which has important implications for market stability and for forecasting and managing financial crises. We describe a model of stock market return dynamics based on investor behavior and linear response theory which describes observed daily return responses. The model has natural "calm" regimes, where market movements are slow and losses and profits are small, and "frantic" regimes, in which returns are exponential and either bubbles form or crashes happen. These regimes are distinct and separated by a phase transition. We confirm this behavior by analyzing data for a wide range of financial institutions across different time periods. We account for the network of investors in the market and incorporate in a natural way both endogenous and exogenous factors which influence market dynamics. Our model offers a framework that naturally connects external influences (such as news) with agent behavior, price dynamics, and market stability, and identifies parameters which can serve as an early warning tool for detecting system-wide dynamics which lead to crashes. We plan to use this model to probe quantitatively the impact of external financial news on price dynamics, to test market efficiency, and also to develop a theoretical framework for probing how markets process information more generally.