Aetna’s second-quarter profit jumped 52 percent to top expectations, and the nation’s third-largest health insurer raised its 2017 forecast again, this time well beyond analyst projections.

Investors responded by pushing company shares to another all-time high price in Thursday trading.

Aetna added some Medicare customers and grew the health coverage it provides for large employers, but a pullback from the Affordable Care Act’s health insurance exchanges also helped its business improve compared to last year’s quarter.

The Hartford, Connecticut, insurer’s biggest expense, health care costs, fell and the percentage of premiums it pays in medical claims improved as Aetna slashed its participation in the law’s exchanges to four states from 15 last year. The insurer still expects to lose more than $200 million before taxes this year on ACA-compliant coverage it sells on and off the law’s exchanges. But that’s better than the approximately $300 million it lost last year.

Aetna once covered more than 900,000 people through the exchanges, which amount to a small slice of its overall business. But the Hartford, Connecticut, company and several other national insurers have scaled back their presence in the Obama-era law’s marketplaces, where they have struggled with a sicker-than-expected patient population and not enough healthy customers, among other challenges. Aetna covered about 180,000 people through the exchanges at the end of the second quarter and intends to completely leave that market next year.

Health insurance is Aetna’s main business, and most of its enrollment comes from commercial coverage sold through employers or directly to individuals. But the insurer and its competitors also have been expanding into government-funded business like the Medicaid program that covers the poor or Medicare Advantage plans for people who are over 65.

Aetna on Thursday joined competitors like UnitedHealth Group Inc. and the Blue Cross-Blue Shield insurer Anthem Inc. in easily beating second-quarter expectations and hiking its 2017 forecast.

The insurer’s quarterly earnings jumped to $1.2 billion, from $791 million last year, even though its total revenue slipped and enrollment fell due to pullbacks from the exchanges and the company’s Medicaid business and a pause in a health insurance fee. Health care costs fell 6 percent to $10.58 billion.

Adjusted earnings totaled $3.42 per share. Revenue excluding capital gains came to $15.5 billion.

Analysts expected, on average, earnings of $2.37 per share in the second quarter on $15.24 billion in revenue, according to FactSet.

Aetna also said Thursday that it now expects adjusted earnings of between $9.45 and $9.55 per share for the year, a big hike from its previous forecast for $8.80 to $9 per share.

It’s also well above industry analyst per share projections of $8.98.

The price of Aetna shares jumped past $160 Thursday morning to set a new, all-time high mark. The stock has already reached several all-time highs this year. Shares have climbed consistently for much of 2017, particularly since Aetna said in February that it was doubling its quarterly cash dividend to 50 cents a share and would buy back millions of shares.

That announcement came after Aetna abandoned its planned, $34-billion purchase of Medicare Advantage provider Humana, a deal that had been rejected in federal court.