For stock investors, the trade war has been nothing but trouble. For bond investors, it’s been a dream.

Unable to stomach turbulence driven by the escalating conflict between China and the United States, and leery of a darkening outlook for the economy, investors have been pulling money out of the stock market and buying bonds, the traditional place to park cash during times of uncertainty.

The rush has turned parts of the ordinarily boring bond market into a better bet than stocks. The gains are unusual; by some measures, bonds are having their best year since 2002. And they do carry risks for investors who are buying now. If the concerns that have lured investors into the bond market dissipate — because Washington and Beijing reach a trade deal, for example — then bond prices could start to fall. When investors expect the economy to grow, they typically turn to investments like stocks that might rise fast as company profits increase.

But lately, the S&P 500 has been on a jagged path as bad news on the global economy, or sudden threats and escalations by President Donald Trump or the Chinese government, have unsettled investors. The upshot of these swings is that, even with a decent gain this year, the stock benchmark is roughly unchanged from where it was in early 2018.

“For a lot of clients, they feel like they’ve just been bouncing up and down, and stocks are not going much of anywhere,” said Michael Ball, president of Weatherstone Capital Management, an asset manager based in Denver. “That gets people on edge.”

For investors weary of such volatility, bonds have become a go-to alternative. Bond prices do not fluctuate as much as stocks, and the returns they offer are typically more certain than those of many other investments. On top of the interest payments companies are obligated to make, the price of the bond itself can rise — as they have this year — generating an investment gain for bondholders. So, as investors sold almost $70 billion of stock investments like mutual funds and exchange-traded funds in the year through July, according to data from the tracking firm EPFR, nearly $260 billion (Dh954 billion) of cash flooded into vehicles that invest in the US bond market. Interest rates in places like Europe and Japan are even lower than they are in the United States, making bonds in the US appealing to global investors as well.

One of the broadest gauges of the American bond market, the Bloomberg Barclays Aggregate index — the S&P 500 of the American bond market — is sitting on gains of more than 9 per cent, including both interest payments and price appreciation. If it were to finish the year at that level, it would be the index’s biggest increase since 2002.

Longer-term bonds have done even better. If you simply bought the 10-year Treasury note at the end of last year, you’d be up almost 13 per cent. In other words, an investment that is seen as virtually risk free (because repayment is considered guaranteed by the US government) has done as nearly as well as the much riskier stock market.

These price gains are the obvious corollary to a feature of the bond market that has received a good deal of attention lately: bond yields, which move in the opposite direction of prices, have fallen sharply. That drop continued Wednesday, with the yield on the 10-year Treasury note dropping to just under 1.47 per cent. That yield was more than 3 per cent in late end of 2018.

But bonds are still surprising investors who thought of them as a safe, low-return, bet, like George Alexander, a 38-year old software engineer, who bought a fund of high-quality long-term bonds in February.

Alexander was not expecting big returns from the bonds. After an ugly sell-off in the stock market, he figured that he could collect an advertised 3.5 per cent annual yield on the bond fund while he waited for the uncertainty to clear. Instead, the bond fund rocketed higher.

It is up more than 20 per cent this year — handily outpacing the nearly 16 per cent gain for stocks, including dividends.

“It’s crazy,” said Alexander, who lives outside Houston. “It’s acting like a stock fund.”

Investors like Alexander, who are now sitting on a pile of unexpected gains, face a tough choice: lock in those profits or expect the gains to continue as other investors follow them into bonds.

“They’re performing well, they’re perceived as safe and no one thinks interest rates will ever go up again,” said Michael Hartnett, chief investment strategist at Bank of America Merrill Lynch Global Research. “The question is, what could come up that would disrupt the narrative?”

Despite the reputation of bonds as a low-risk place to park money, if the current headwinds hitting the global economy start to ease up, bonds bought recently could become losers quickly.

For many, the noisy political environment — and the potential damage it could do to the economy — is the primary concern. Gilbert Shank, a 30-year-old customer service representative at an industrial equipment supplier in Minneapolis, knows that with decades to go before retirement, his portfolio should be heavily weighted toward stocks.

But early this month, after stocks fell sharply, Shank grew worried about “political instability” and reports that the economy could be slowing down. He moved almost all the money from his 401(k) into bond funds.

“I’d rather risk missing out on some gains than risk losing a big chunk of what I have,” he said. “I’m kind of just waiting for the recession to happen, really.”