Oil climbed on Friday for a seventh straight session as a decrease in the U.S. rig count and stronger demand data from China lifted depressed prices that still finished the first half with the biggest decline for that period since 1998.
U.S. drillers decreased their number of rigs for the first time since January, according to energy services company Baker Hughes. The rig count had risen for the previous 23 weeks.
Earlier, Chinese data showed factories grew at the quickest pace in three months. Rob Haworth, senior investment strategist at U.S. Bank Wealth Management, said the Chinese data "certainly gives you hope that demand is growing globally."
U.S. crude futures settled up $1.11, or around 2.5 percent, to $46.04 a barrel. Benchmark Brent crude futures settled up 50 cents at $47.92 a barrel.
Both benchmarks ended the first half of 2017 with drops of more than 14 percent since Dec. 30, 2016, the largest drop since Brent and U.S. crude fell about 19 percent in the first half of 1998.
Oil prices have generally increased in first half of most years.
Trading volume was low ahead of the U.S. Independence Day holiday weekend. Last week, crude hit a 10-month low as rises in output revived concerns about global oversupply.
The U.S. dollar fell, making dollar-denominated crude oil less expensive for investors using other currencies.
The global crude glut has knocked 16 percent off Brent crude so far this year, even though the Organization of Petroleum Exporting Countries and other major producers have agreed to cut production about 1.8 million barrels per day (bpd).
"There’s a longer term question of where are prices going to be when the market rebalances," said Haworth.
Money managers cut their net long U.S. crude futures and options positions in the week to June 27 to the lowest since late September, the U.S. Commodity Futures Trading Commission (CFTC) said on Friday.
The market has also seen traders building short positions to the highest levels since mid-August.
Reuters' monthly oil price poll showed analysts have reduced their price forecasts again, with 2017 average Brent and WTI prices lowered by more than $2 since last month.
Bank of America Merrill Lynch analysts cut their forecast for average 2017 Brent crude prices to $50 a barrel from $54 and WTI to $47 from $52. They cited rising output from Libya, Nigeria and U.S. shale fields, coupled with weaker demand growth.
While U.S. drillers cut two oil rigs in the week to June 30, the total rig count of 756 is still more than double the count the same week a year ago, Baker Hughes said on Friday. (Additional reporting by Karolin Schaps in London, Naveen Thukral in Singapore; editing by David Gregorio)