China's currency has spiked to its strongest level against the dollar since the aftermath of President Trump's election in November.

The yuan jumped as much as 0.5% against the greenback on Thursday, bringing its gains in the past four trading sessions to 1.2%.

A stronger yuan is likely to please Trump, who frequently accused China during his campaign of devaluing its currency to get an unfair advantage in trade. But currency traders say the yuan's recent surge is most likely about Beijing proving a point to some of its other critics.

In particular, Chinese officials were infuriated by a downgrade last week from credit rating agency Moody's, which warned about China's rising debt levels and slowing growth.

Related: Moody's cuts China debt rating for first time since 1989

"There is a possibility that the authorities want to squash any worries" about China's debt burden after the Moody's announcement, Jason Daw, a currency strategist at Societe Generale, wrote in a research note Thursday.

The negative news of the Moody's downgrade was awkwardly timed for Beijing, which is trying to attract overseas money into its domestic bond market.

"They're trying to make the currency stronger and more stable to attract foreign investors," said Stephen Innes, a Singapore-based trader at online broker Oanda.

Related: Trump's claims about China's currency are getting more bizarre

In the short term at least, it appears to be working. "We're seeing more buyers than sellers of the yuan in the last two days," Innes said.

In recent years, fears the yuan would keep falling against the dollar prompted investors to move huge sums of money out of China. Beijing responded by spending hundreds of billions of dollars to prop up the currency and introduced capital controls to stem the outflow of funds.

In the weeks after Trump's election, the dollar soared against other major currencies, including the yuan. But amid a broad weakening in the dollar in recent months, the Chinese currency has stayed largely stable against the greenback -- until last week.

Related: The dollar's Trump bump has vanished

The yuan's sudden surge is prompting some analysts to reconsider their predictions of what it will do next.

Economists at Capital Economics said late Wednesday they no longer expect the yuan to decline against the dollar this year.

But Societe Generale's Daw said that with China's economic growth likely to have peaked, it's "just a matter of time" until Beijing needs to go back to steering the yuan lower against the currencies of its key trading partners.