How to play stocks in the second half

Best second half performers

It's no secret that the stock market has been on an absolute tear over the past five years. After all, the depths of the financial crisis pushed prices down to bargain basement levels back in March 2009.

While stocks have generally moved higher, there are clear patterns of outperformance that have developed in that five-year period. There are also winning themes that emerged, especially for the second half of the year.

Read MoreSanta Claus July?

So as the second half kicks off, here's what's worked on Wall Street over the past five years, looking only at top performers for the final two quarters of each year. Of the 10 major sectors of the , the single best-performing sector in the final six months was consumer discretionary.

Traders work the floor of the New York Stock Exchange.
Getty Images

The sector returned nearly 16.5 percent on average per year. Consumer discretionary stocks can encompass anything from retailers like and Macy's, to media companies like CBS and Disney. Consumer discretionary stocks posted only one negative second half in the last five years, and that was in 2011 when the sector fell by 3 percent.

The second best-performing sector was materials, which includes everything from miners like Freeport McMoRan and Newmont Gold, to chemicals companies like Dow and DuPont. Over the final six months of each of the last five years, that sector has returned an average of 16 percent as well. It too had its lone negative year during that stretch in 2011, when it lost 14 percent.

Read More Stocks could face bumpy second half despite healthy gains

As for the single worst-performing second-half sector, that distinction belongs to one of this year's standouts. Utility stocks, as a whole, have been lagging the overall market, at least when it comes to the second-half story. Though still positive, the average gain has been just 5 percent in the second half of each year.

Of course, utilities head into the second half of this year with a good amount of momentum, having gained 16 percent year-to-date. The question is whether that uptrend will continue.

There are a good number of individual stocks that have been consistent standouts, given those same time parameters. There were 209 stocks in the S&P 500 that had an average second-half gain of 15 percent or more over the past five years. We then looked for only those stocks that posted at least a 10 percent gain in each of the last five second halves. Those 209 stocks became just eight.

Read More Second half playbook: Pros hunt for value

Employment data and consumer credit score company Equifax has averaged an 18 percent gain for those second halves. Biopharmaceuticals and cancer drug specialist Celgene has averaged a 22 percent gain. Specialty and athletic apparel company VF Corp has averaged a 23 percent gain. Retail giant Macy's has averaged a 24 percent gain. Payments processor MasterCard has averaged a 30 percent gain. Internet search and advertising company Google has averaged a 31 percent gain. Computer data storage and semiconductor maker SanDisk has averaged a 34 percent gain. And Kansas City Southern tops the list with an average 38 percent gain in the final six months of each of the last five years.

As many traders start fine-tuning their portfolios for the next six months, some are looking toward the past to see if history will repeat itself. If it does, then it may bode well for sectors like consumer discretionary, materials and industrials, and not so well for utilities, despite their first-half fireworks. Then again, the market may just rotate into those underperformers as this year's second-half story.

—By CNBC's Dominic Chu. CNBC's Giovanny Moreano contributed reporting.