Abstract: Litigants are unrealistically optimistic with regard to the probability of prevailing at trial. This systematic bias is well documented, and has been often invoked to explain breakdowns in pre-trial settlement negotiations. Contrary to existing models that allow for optimism as an exogenous assumption, the present study derives this cognitive bias endogenously. It thus provides a theoretical foundation for optimism in litigation. Quasi-evolutionary forces - market pressure (in the market for legal services) and imitation processes - are shown to favor cautiously optimistic litigants. Moreover, the endogenous optimism model enables an examination of the factors that determine the magnitude of the optimism bias. In particular, it is shown that the legal environment influences the equilibrium level of optimism. Focusing on rules for the allocation of litigation costs, the American rule induces a higher level of optimism, as compared to the British rule. This finding qualifies the conventional wisdom regarding the advantage of the American rule in fostering settlements. Finally, the present analysis is offered as an illustration of a broader theme, that the law can play an important role in determining the types and magnitudes of prevailing cognitive biases. The identification, characterization and analysis of this perception-shaping role of legal institutions are a novelty of the present study. Behavioral law and economics is revealed as a two-way, rather than a one-way street. Not only do cognitive biases affect the operation of legal rules, but also the legal rules themselves influence the types and magnitudes of observed biases.