The happiness of individuals is an important metric for societies, but we know little about how the cumulative influence of daily life events are aggregated into subjective feelings. Using computational modeling, I show that momentary happiness in a decision-making task is explained not by task earnings, but by the combined influence of past rewards and expectations. The robustness of this account was evident in a large-scale smartphone-based replication. I use a combination of neuroimaging and pharmacology to investigate the neural basis of happiness, finding that it relates to dopamine. I then show that this computational approach can be used to investigate the link between mood and behaviour in psychiatric disorders including major depression and bipolar disorder.