19 pages, 19 pages, The price fluctuation in agricultural markets is an obstacle to poverty reduction for small-scale farmers in developing countries. We build a microfoundation to study how farmers with heterogeneous production costs, under price fluctuations, make crop-planting decisions over time to maximize their individual welfare. We consider both strategic farmers, who rationally anticipate the near-future price as a basis for making planting decisions, and naive farmers, who shortsightedly react to the most recent crop price. The latter behavior may cause recurring overproduction or underproduction, which leads to price fluctuations. We find it important to cultivate a sufficient number of strategic farmers because their self-interested behavior alone, made possible by sufficient market information, can reduce price volatility and improve total social welfare. In the absence of strategic farmers, a well-designed preseason buyout contract, offered by a social entrepreneur or a for-profit firm to a fraction of contract farmers, brings benefit to farmers as well as to the firm itself. More strikingly, the contract not only equalizes the individual welfare in the long run among farmers of the same production cost, but it also reduces individual welfare disparity over time among farmers with heterogeneous costs regardless of whether they are contract farmers or not. On the other hand, a nonsocially optimal buyout contract may reflect a social entrepreneur's over-subsidy tendency or a for-profit firm's speculative incentive to mitigate but not eliminate the market price fluctuation, both preventing farmers from achieving the most welfare.