In an overlapping generations economy, lenders fund risky investment projects of firms by drawing up loan contracts in the presence of an informational asymmetry. An optimal contract entails the issue of only debt, only equity, or a mix of the two. The equilibrium choice of contract depends on the state of the economy, which in turn depends on the contracting regime. Based on this analysis, the paper provides a theory of the joint determination of real and financial development. The paper is able to explain both the endogenous emergence of the stock market along the path of economic development and the diversity in the mode of financing that is commonly observed in the intermediate stage of development.