It's been a tough few months for several sectors, but it's been downright brutal for food companies. Already operating on thin profit margins, a few of these names have been pushed to the brink of net losses by rising shipping rates and soaring commodity costs.

That's why shares of Campbell Soup (CPB 0.11%), Hormel Foods (HRL -1.20%), and Kraft Heinz (KHC -0.76%) are down 17%, 8%, and 14%, respectively, for the past six months while the broad market is firmly higher. Investors have priced in their perception of the present inflation situation.

Veteran investors know, however, that perceptions can sometimes be wrong, setting up great buying opportunities as a result. Is that the case here?

No minced words

In its defense, the market is simply listening to these companies' warnings following problematic earnings results.

Take Campbell Soup as an example. It reported a 13% decline in adjusted earnings per share for its fiscal fourth quarter (which ended Aug. 1), citing increased input and supply chain costs. The company's fiscal 2022 outlook indicates profits will further slip between 4% and 8% (despite flat revenue growth), largely due to "accelerating inflationary pressures and a constrained labor market."

Food production facility workers examining at a converter belt.

Image source: Getty Images.

Kraft Heinz is in the same boat. Mostly flat sales in its three-month stretch ended Sept. 25 were dented by its 13% slide in gross profit. The word "inflation" again featured prominently in the company's explanation and outlook. Like Campbell and Hormel Foods, Kraft Heinz is lowering what costs it can and offsetting any cost increases with higher prices.

At the same time, although the current level of inflation has been described as "transitory" and set to cool in 2022, food prices will be stabilizing at their currently elevated levels. Kraft Heinz CEO Miguel Patricio even conceded during a recent interview with the BBC that consumers should brace for these price increases being permanent.

We've seen it before

But what if investors are overestimating the actual impact of higher commodity and shipping costs and subsequently higher consumer prices? The question cuts to the heart of investing in the consumer staples sector, and in food companies in particular. Whereas consumer demand for these goods isn't cyclical, the underlying costs and pricing power for food are cyclical.

That's ultimately a good thing, though.

While the food industry's pricing and cost ebb-and-flow is slow-moving, it does move. It just takes time for consumers to find alternatives that temper demand for more frequently purchased foods. It takes time for food producers to figure out how to ship fast-selling goods by rail rather than road, which is generally more cost-effective. And it takes time to set up new factories that lower a company's overall costs.

But these things do happen. All three of the aforementioned companies have faced and survived outrageous inflation before -- inflation that usually cools off on its own anyway, as the chart below illustrates happened in 2009 and then again in 2016.

US Consumer Price Index: Food Chart

U.S. Consumer Price Index: Food data by YCharts.

As the chart also shows, steady food price increases are actually the norm. In the meantime, these companies tend to enjoy rather resilient pricing power while waiting for prices to peel back to long-term norms.

Consumers aren't happy about it, but they still have to eat.

Think bigger picture

The knee-jerk (and now lingering) response from investors is certainly understandable. While inflation is nothing new, the current combination of sky-high shipping and commodity costs is unprecedented. And again, the natural, cyclical downshift in gas and food prices is a process measured in months, if not years. Value-seeking investors expecting an immediate and enormous rebound from the market's most prolific food companies shouldn't hold their breath.

Shares of Campbell, Hormel, and Kraft Heinz are down sharply in the past few months, but the market is missing the long-term rebound potential of these companies. None are high-growth players, but neither are they disasters despite this year's underperformance.

That said, while all three stocks are in the red looking back several months, it's telling that they are up for the past few weeks. It looks like the market is finally starting to catch on to its overreaction.