BP plc (BP - Get Report)  shares traded at the highest level in more than a month Tuesday after the group posted second quarter earnings that were largely in-line with forecasts and maintained its dividend as the group swung into profit thanks to gradually rising global oil prices.

BP said profits for the three months ending in June hit $144 million, a massive swing from the $1.42 billion loss recorded over the same period last year.  So-called underlying replacement cost profits slipped 5% to $684 million, BP said, but still topped a company-provided consensus of $500 million.

Earnings per share came in at $0.04, the company said, matching the FactSet consensus and rising from a loss of $0.46 from the same period last year. Revenue hit $56.511 billion, up 21% from last year and firmly ahead of the FactSet estimate of $51.284 billion. The group said it will maintain its $0.10 per share dividend.  

"We continue to position BP for the new oil price environment, with a continued tight focus on costs, efficiency and discipline in capital spending," said CEO Bob Dudley. "We delivered strong operational performance in the first half of 2017 and have considerable strategic momentum coming into the rest of the year and 2018, with rising production from our new Upstream projects and marketing growth in the Downstream."

Brent crude prices averaged $49.67 in the three months ending in June, according to Energy Information Administration data, up 9.11% from the same period in 2016. BP said it expects to see global oil prices trading in a range of between $45 and $50 per barrel for the remainder of the year.

Oil price projections will be important for BP as it continues to strap on debt in order to pay claims related to the Deepwater Horizion rig disaster in the Gulf of Mexico in April 2010, which killed 11 people and resulted in the largest marine oil spill in history.

BP's net borrowing rose $9 billion from the same period last year to a record $39.8 billion, the company said, but more than 75% of the payments in relation to the Deepwater disaster due this year -- which could hit $5.5 billion -- were made in the six months ending in June. The remainder will be covered by asset sales, BP said.

"Cash flow was strong in the first half," said CFO Brian Gilvary. "Organic cash flow exceeded organic capital expenditure and dividends paid."

"While net debt rose primarily due to Gulf of Mexico payments, we expect this will improve over the second half as these payments decline and divestment proceeds come in towards the end of the year," he added.

BP shares were marked 3.25% higher in the opening 90 minutes of trading in London and changing hands at 460 pence each, the highest since June 22 and trimming their year-to-date loss to around 10%.

More of What's Trending on TheStreet: