The dollar posted its first weekly gain since early January, buoyed by haven demand amid broader market turmoil.The dollar closed 0.2% higher for the week, even after paring gains on Friday. The advance halted a three-week drop fuelled by speculation that the Trump administration’s policy shifts would spur foreign investors to dial back exposure to US assets.The reversal came as the stock market was whipsawed by volatility, Bitcoin tumbled and what had been a steep run-up in gold and silver prices abruptly reversed, all of which drove investors into the safety of US Treasuries. At the same time, analysts said investors started to take profits from widespread bets on the currency’s fall after bearish sentiment hit extreme levels late last month.“The market was heavily short USD as recently as last week, so there is likely a whiff of short-term profit taking here,” said Bipan Rai of BMO Asset Management. “That profit taking has been buttressed by decent US sentiment.”Data released by the Commodity Futures Trading Commission on Friday showed speculative traders boosted their bets against the dollar to $17.4bn, the most since July. The data shows activity in the week through February 3.The week’s gains for the greenback were driven largely by an advance against the yen ahead of Sunday’s national election in Japan. Polls there show Prime Minister Sanae Takaichi’s Liberal Democratic Party is expected to secure a big win. Hedge funds have increased bets against the yen, anticipating that a decisive mandate for Takaichi would allow her to enact fiscal-stimulus plans that could push up inflation.“The dollar firmed this week, largely reflecting yen weakness,” said Elias Haddad, global head of markets strategy at Brown Brothers Harriman. “Takaichi’s expansive fiscal agenda is an ongoing drag for the yen as polls suggest her coalition is headed for a landslide victory.”The dollar’s advance came even as layoff and jobless-claims data this week pointed to further cooling in the labour market, which bolstered speculation that the Federal Reserve will resume cutting interest rates later this year. Such reductions would likely act as a drag on the dollar by giving investors incentive to shift money to countries where rates are higher.January jobs data delayed by the partial US government shutdown will be released next week. Traders also see the dollar’s recent upswing as unlikely to last: A key options gauge on the Bloomberg dollar index remains in negative territory, a sign it’s expected to depreciate over the coming month.