Only three industry sectors within the S&P 500 have beaten the broad index so far this year: consumer discretionary (11 percent), health care (11.6 percent) and ...
... consumer staples, up 3.4 percent. And in the still-young third quarter, consumer staples is out in front, up 5.6 percent, moving ahead of discretionary, up 4.78 percent over that same time period. The staples sector is now trading at an all-time high.
But recent performance in the consumer staples sector hasn't been easy to capture as a sector bet. The small outperformance versus the S&P 500 year to date, compared with consumer discretionary's big run, illustrates a problem for consumer staples: some really big dogs are weighing on the sector.
Wal-Mart Stores declined 16 percent year to date, through the end of the second quarter. Whole Foods Market fell 28 percent and Keurig Green Mountain more than 43 percent. Even two of Warren Buffett's all-time favorite consumer stocks—and two of his larger stock holdings after U.S. banks—Coca-Cola and Wal-Mart, are among the notable laggards at the moment.
"The story here is that even though it's up a little bit more than the index and you would think people have done well, there have been big winners but a lot of junk on the other side, lots of mines," said Scott Mushkin, consumer analyst at Wolfe Research. "So you really better pick the right ones or you're not reflecting the opportunity."
With that in mind, here are three themes boosting consumer staples stocks that can help you to pick the spots in the sector that are working.
The bad habits of Americans are paying off for consumer staples investors. Leading the way have been some stocks that don't necessarily bring out the best in us—or leave the best inside us—tobacco names, liquor stocks and energy drink makers.
Monster Beverage was the No. 1 stock in the sector through the end of the second quarter, up 42 percent. Tobacco company Reynolds American was No. 2 among consumer staples, up 34 percent. But arguably the biggest trend has been how much Americans, especially younger ones, are taking to drink, and drink finer distillations.
"Liquor stocks have their own set of fundamentals," said Tim Ramey, head of consumer research at Pivotal Research Group. The whiskey sector grew for a century at a rate of plus or minus 1 percent, but in the past five years, it's been growing at high single-digit rates. Why?
Read More$6 eggs could be on the way
Ramey said to thank younger Americans. "Millennials have been the best thing that ever happened to the alcohol industry. They have sophisticated tastes, even if they don't have a lot of money." He added, "Baby boomers didn't discover these beverages until 40."
Investor activists get a bad rap for meddling in the affairs of stodgy corporations, but they can help boost stocks, a lot. ConAgra and Mondelez are among the top 10 stocks in the staples sector, and both have been targets of recent high-profile activist campaigns.
Nelson Peltz's Trian Fund Management has a history of taking on big names in the food industry and he has continued to increase his stake in Mondelez. Meanwhile, Jana Partners disclosed in June that it's now in ConAgra, buying more than 7 percent of the company's shares and stating in a regulatory filing that it's getting involved in what the hedge fund said in a regulatory filing has been a disappointing deal: the company's $5 billion purchase of private-label foods company Ralcorp. In late June, ConAgra announced it would divest Ralcorp assets.
"Real activists or the perceived threat of activism, makes boards aware that it's time to be thinking of doing themselves what others might do to them," Ramey said. "That thought process and [stock] optionality is worth something."
"Activists are coming into the space because they can get mergers done and find cost savings," Mushkin said.
While Warren Buffett is no activist, it's worth noting that he teamed with Brazilian private equity firm 3G Capital for the biggest consumer staples deal in recent history, the creation of food giant Kraft Heinz.
The answer: Kroger.
Wal-Mart has been crushed. Whole Foods has been crushed, but check out Kroger, up 22 percent through the end of the second quarter.
Mushkin said two big trends are at play in the Kroger success.
First, in an environment of slow growth and increased regulation, larger companies with scale and advantaged business models can navigate better than peers. As one example, Mushkin pointed to Wal-Mart having to contend with the minimum wage increase battles across the country, versus Kroger, which is unionized, which makes Kroger more competitive.
Read MoreCVS will no longer cover Viagra
An even bigger trend at play in the Kroger story is the importance of "playing down the middle" with investments—meaning the middle class. With unemployment falling and the fresh/organic trend going mainstream, Kroger is in the right spot—what Mushkin referred to as "the vast middle." Kroger may not be the cheapest like Wal-Mart, but it is offering better food at prices that are lower than Whole Foods. "Kroger has learned how to do natural and organic. Whole Foods has an enormous price problem and Kroger can mimic them for less," Mushkin said.
Meanwhile, the analyst said the No. 1 traffic driver for Wal-Mart has been its supercenters but they've been in decline. "They aren't great at 'fresh.' Most of what they are good at is in decline," Mushkin said. He added, "Most of those staples companies are not on trend anymore. Think the unthinkable now in food: soda in perpetual decline, Kroger 'out-competing' Whole Foods."
Top 5 consumer staples stocks year to date
Worst 5 consumer staples stocks year to date