NEW YORK (Reuters) - The energy sector is the stock market’s dud so far in 2017 after a banner performance in 2016, and the rest of the year may also be rocky for investors due to the unclear path for crude oil prices.

Traders work on the floor of the New York Stock Exchange (NYSE) in New York, U.S., February 28, 2017. REUTERS/Brendan McDermid

Energy outdid all other sectors last year, up nearly 24 percent thanks to a late-year rally on anticipation that impending production cuts from major oil producers would lift crude prices and after the election of Donald Trump as U.S. president spurred investor hopes for industry-friendly policies.

However, energy shares have been weak after peaking in mid-December, and are the worst-performing of the Standard & Poor’s 11 stock sectors in 2017. Oil producers have been the poorest among energy sub-industries, due to doubts about the demand outlook and an unexpectedly high level of crude and finished product inventories.

In 2017, energy is down 5 percent, compared with a 6 percent climb for the overall S&P 500. U.S. oil producer shares rallied in late November along with commodity prices. But they have pared gains this year as a Nov. 30 agreement by the Organization of the Petroleum Exporting Countries to cut production has so far failed to quell fears of oversupply and lift crude prices beyond a tight $5 a barrel range.

Since not all oil companies perform the same task, not all shares are created equal. Analysts said production companies, particularly those operating in U.S. shale regions like Texas’s Permian Basin, where drillers have been rapidly adding to rig counts, may be best positioned for gains.

They do carry risk, as shale producers can get more volatile if prices move more rapidly.

“There’s a lot of worry about what the U.S. supply picture will look like, and there’s a lot of worries about the OPEC cuts,” said Vikas Dwivedi, global oil and gas strategist at Macquarie Group in Houston. “We think you’re going to get good inventory numbers, which will propel a rally in the commodities, and take the exploration and production companies higher.”

Investors have already beefed up bets on the sector - about $263 million has flowed into U.S.-listed energy mutual and exchange-traded funds in 2017 through February, according to Lipper data. The Energy Sector Select SPDR Fund, which has about $17.6 billion in assets, has attracted $400 million of new investment, according to Lipper data.

Companies like Exxon Mobil Corp and Chevron Corp may see profits rise as the economy strengthens and oil prices increase. Increased power demand and defense spending - the defense sector is a big energy consumer - could also propel demand. The chief executives of both companies will be presenting at this week’s closely watched CERAweek conference in Houston.

Shares of oil majors pay a dividend yield, a benefit for times when oil prices are range-bound, said Christian Ledoux, senior portfolio manager at South Texas Money Management in San Antonio. “We think that the other categories of energy provide just too much risk at this point,” he said.

Investors are also looking at the potential effect from Trump’s policies. Since the election, refiners are up more than 9.5 percent, while oil producers have gained less than 2 percent, the weakest energy sub-sector.

Macquarie’s Dwivedi said some independent refiners may benefit from expected changes to renewable fuel standards, while others may see profits hurt if a border adjustment tax is passed. Since the election, Valero Energy, which supports changes to renewable fuel blending rules, is up 14 percent.

Refiners overall saw margins pinched in 2016 after overproduction of product early in the year. Product inventories for gasoline and distillates are still considered high. That will hurt margins, especially if crude prices rise with production dropping.