The paper assesses how cognitive abilities and education affect the performance of individual investors in the stock market. We use an exhaustive NASDAQ Tallinn dataset covering two bull markets and one bear market. We show that stronger mathematical and overall academic abilities are associated with more profitable investments and relative outperformance, after trading style, income, experience and a variety of educational characteristics are controlled for. However, the effects are not always linear or monotonic. A similar positive effect on performance is produced by higher education or specialisation in certain subjects. None of these factors is able to explain the performance of investors during bear markets, and none is a substitute for experience. Investors with strong academic abilities tend to have moderate trading frequency and performance seems to be affected more by the ability to find good trades than by the use of any particular trading strategies.