Optimal patterns of trade and development