One thing to consider when balancing farms and stock markets: Economy bonus is additive, so for example while four stock exchanges means a 100% bonus, the next four stock exchanges will just increase that bonus to 200%, so in total you triple your income instead of quadrupling it (doubling twice). Farms, on the other hand, increase population, which affects the base tax income, which is multiplied by the entire economic bonus.
So for some generic race in ToA, let's run the numbers, assuming that it will take one extra morale building to keep a planet happy going from 8 billion to 14 billion, and two extra morale buildings to keep it happy going from 14 billion to 20 billion:
1 farm + 1 morale buildings uses two tiles and provides a 32% bonus (sqrt[14/8]
2 farms + 3 morale buildings uses five tiles and provides a 58% bonus (sqrt[20/8])
Now, two stock exchanges provides a 50% bonus and 5 stock exchanges provides a 125% bonus, so it seems at first like stock exchanges should win easily. However, the actual bonus of the stock exchanges depends on the existing economic bonus. For example, if you already have a 100% economic bonus, you currently produce at 200% of base levels, so going to 250% of base levels is only an increase of 50/200=25%. The 32% multiplicative bonus from farms will be better than the 50% additive bonus from stock markets if your existing economy bonus is more than 56%, or about two stock markets, so as long already have at least two stock markets, you should build the farm and morale building (if you need two morale buildings with your farm, then the number changes to 134% existing bonus and at least 6 stock markets, but one farm is still worth it for most decent planets). Looking at two farms, if you'll need 3 morale buildings to keep up, the 58% increase in base outcome only outweighs a 125% additive bonus if you have 222% already in econ bonuses, so that's 9 stock markets plus room for five more buildings, and so two farms is only worth it for maybe PQ in the high teens or above, since you'll probably also have a factory or two and maybe another morale building or a starport. Of course, farm bonus or morale bonus tiles both favor building farms, because you are sacrificing fewer stock markets. In addition, I believe your civilization economic bonus adds to the planets bonus, so if you have a high bonus based on race or green resources, that will make your econ bonus higher to start with and mean that farming will be favored more on lower PQ worlds, and of course morale resources and bonuses probably also favor farming because fewer morale buildings will be needed.