(Bloomberg) -- Health care stocks posted their best monthly gain since April 2020 as investors seek shelter in a weakening economy.

The S&P 500 Health Care Index rallied 9.6% in October, its best month in two and a half years and beating the greater benchmark’s 8% rise. Hospital operator Universal Health Services Inc. -- fresh off its best week on record -- and diabetes device maker Dexcom were among the top performers driving the sector higher. 

The gains come as investors look for safe bets amid rising interest-rates and a looming recession. Pockets of the health sector, from insurers to large drugmakers, tend to do well in downturns as demand for their services isn’t swayed by the economic outlook.

While wipeouts from major tech stocks have been grabbing the headlines, earnings beats in health care have been rewarded more than any other sector, according to Asad Haider, a Goldman Sachs Group strategist. 

He said health care’s defensive appeal and outflows from other sectors, including tech bellwethers, are helping bolster the stocks. Disappointing earnings from tech companies stand in contrast to the beats-and-raises from Biogen Inc., Gilead Sciences Inc., Merck & Co. Inc. and others, Haider wrote in a note to clients dated Friday.

The group has charged higher for the past four weeks, its longest weekly winning streak since December 2021.

And more earnings reports are coming. The best health performers this year are drug distributors McKesson Corp., which is expected to report earnings on Tuesday after a 57% rally this year, and Cardinal Health Inc., which is set to share results on Friday after a 47% gain. 

Several large-cap drugmakers and managed care companies are trading near all-time highs, including Eli Lilly & Co. ahead of a Tuesday earnings report, and Humana Inc., which is expected to report on Wednesday. Cigna Corp., UnitedHealth Group Inc. and Elevance Health Inc. are also around record levels. 

The sector was nearly unchanged on Monday, while the S&P 500 Index closed lower by 0.8%.

Not all health stocks are heading higher, and with the sector still down about 5.9% this year, the group is on pace for its first annual decline since 2016. The strong dollar and unfavorable exchange rates have hurt sales for the sector while negative earnings reports drove plunges in device maker Edwards Lifesciences Corp. and Invisalign-maker Align Technology Inc. 

Still, the impact of FX as well as rising interest rates should be factors well understood by investors by now.

“Large-cap health care should work higher as an S&P component, as many risks appear to be generally well priced in and the business variability is manageable vs other sectors,” Jared Holz, a health-care strategist at Oppenheimer Holdings, wrote. 

(Updates throughout to market close.)

©2022 Bloomberg L.P.