An escalation in the trade war between the U.S. and China in recent weeks has led several large banks to upgrade Malaysian stocks — a market that foreign investors have been wary about for much of the year.

Swiss financial giant UBS said Wednesday that it upgraded Malaysia to "overweight" from "neutral." It came one day after Europe's largest bank HSBC said in a report it had bumped up the Southeast Asian country to "neutral" from "underweight."

Malaysia's stock benchmark, the Kuala Lumpur Composite Index, has lost around 5% so far this year — and is one of the worst-performing Asian emerging markets. Many foreign investors have stayed away from investing in Malaysia, citing concerns such as uncertainties surrounding the new government's economic agenda.

But the country's resilience, especially at a time when tensions between the world's top two economies threaten to derail global growth, has convinced some investors to reconsider.

"We think the economy looks resilient, with domestic demand strong and manufacturing growth holding up. Low earnings growth is a concern but we see limited further downside. Valuations, while not as attractive as other markets in the region, are not particularly expensive," HSBC said in its report on Tuesday.

"The market has strong defensive qualities, which should reduce downside risks if trade tensions escalate," it added.