We systematically study the ecology of trading strategies and its relationship to financial stability through agent-based modelling. The basis of the research is a simulation of many trading strategies interacting with one another in a stock market that is calibrated against the U.S. stock market. We study how the profitability of each strategy depends on the capital invested in each of the other strategies present in the market. This allows us to relate strategies and identify the nature of their interaction, and study how they affect the evolution of the capital associated with each strategy through time. It also allows us to study the approach to market efficiency and its relationship to financial stability. We study how market volatility depends on the population of trading strategies and the use of leverage.