NEW YORK (Reuters) - U.S. stocks closed lower on Wednesday as investors grappled with a threat from President Donald Trump to shut down the government if Congress fails to fund a Mexico border wall.

Stocks managed to briefly pare losses after comments from U.S. House Speaker Paul Ryan calling a government shutdown unnecessary. Yet that was not enough to calm nerves as the deadline to approve spending measures draws near and a fight looms over raising the cap on government borrowing.

Congress will have about 12 working days when it returns from its summer recess on Sept. 5 to raise the debt ceiling before the U.S. Treasury exhausts the last of its options to remain current on all of the federal government’s obligations.

Credit ratings agency Fitch Ratings said a failure to raise the ceiling in a timely manner would prompt it to review its rating on U.S. sovereign debt, “with potentially negative implications.”

“What we’ve seen over this last week or so in financial markets has been a bit of wiggling around regarding the U.S. political situation,” said Paul Eitelman, multi-asset investment strategist at Russell Investments in Seattle.

“Ultimately, I don’t think markets care that much about the noise coming out of Washington, D.C., but they’re trying to translate what that noise means for the potential for tax reform.”

Trump’s comments also affected the bond and currency markets, with the dollar index slipping 0.4 to 93.14 and 10-Year U.S. Treasury yields falling a touch below 2.17 percent on safety buying.

Investors have grown increasingly concerned about Trump’s ability to legislate his pro-growth agenda given the near-constant political turbulence in the White House.

The Dow Jones Industrial Average .DJI fell 87.8 points, or 0.4 percent, to 21,812.09, the S&P 500 .SPX lost 8.44 points, or 0.34 percent, to 2,444.07 and the Nasdaq Composite .IXIC dropped 19.07 points, or 0.3 percent, to 6,278.41.

Traders work on the floor of the New York Stock Exchange (NYSE) in New York, U.S., August 22, 2017. REUTERS/Brendan McDermid

The CBOE Volatility index .VIX, a widely-followed measure of market anxiety, increased 6.0 points to 12.03, its first rise in four days.

Investors looked towards a speech by Federal Reserve Chair Janet Yellen at a meeting of central bankers in Jackson Hole, Wyoming, on Friday, which will be scrutinized for clues on the U.S. central bank’s monetary policy.

Also weighing on sentiment was data showing sales of new U.S. single-family homes unexpectedly fell in July to a seven-month low.

“It seems like the story there is the affordability for housing is really what is weighing on the new-home market,” said Lindsey Bell, investment strategist at CFRA Research in New York.

The consumer discretionary .SPLRCD index ended down 0.8 percent, dragged lower by a 3.71-percent decline in Lowe's Companies LOW.N after disappointing results and forecast.

Bigger rival Home Depot HD.N dropped 0.54 percent to $149.10.

Shares of advertising firm Omnicom OMC.N dropped more than 6.94 percent to $72.71, while Interpublic Group IPG.N fell 6.32 percent to $72.71 after WPP WPP.L cut its sales forecast after consumer goods giants curbed spending. WPP'S U.S.-listed shares WPPGY.O sank 11.49 percent..

Advancing issues outnumbered declining ones on the NYSE by a 1.11-to-1 ratio; on Nasdaq, a 1.20-to-1 ratio favored decliners.

The S&P 500 posted 49 new 52-week highs and 10 new lows; the Nasdaq Composite recorded 98 new highs and 85 new lows.

About 5.04 billion shares changed hands in U.S. exchanges, below the 6.2 billion daily average over the last 20 sessions.