Regardless of how midterm elections turn out, Wall Street usually ends up a big winner.

The S&P 500, the stock market’s benchmark index, has climbed in the 12 months after each of the midterm elections going back to 1946. That’s 18 elections, many of which ended up shuffling the balance of power in Congress.

“It turns out that under every political makeup in Washington, stocks have gone up and the economy has grown,” said Kate Warne, an investment strategist for Edward Jones.

In midterms going back to 1946, the S&P 500 index had an average price return of 16.7 percent in the 12 months after the elections, according to CFRA.

Right now, polls show Democrats taking control of the House in the Nov. 6 elections while Republicans retain control of the Senate. One popular adage is that Wall Street likes gridlock in Washington, because it creates less uncertainty and diminishes the likelihood of major legislation that could upset the markets.

“There are big issues that need to be resolved and gridlock means those get deferred or pushed forward,” Warne said. “That’s disappointing but doesn’t necessarily mean market returns are bad.”

True, they’re not bad. They’re just not as good as in the other scenarios.

“The best scenario (for the market) is when one party controls all branches of government,” said Sam Stovall, chief investment strategist for CFRA. “The second best is a unified Congress. The worst is a divided Congress.”

Recently, markets have had other worries beside the elections. After a solid third quarter that saw records for the S&P 500 and Dow Jones industrials, stocks have swooned on fears that rising interest rates and the U.S. trade dispute with China could undo some of the benefits of the GOP tax cuts and eventually squeeze corporate profit margins.

The length of the current bull market, now at more than nine years — the longest ever — also has some investors worried that stocks are overdue for a severe pullback.

Currently, the U.S. economy is growing at the best clip in years. The earliest most experts see a recession in the U.S. is 2020. And Wall Street continues to expect solid growth from companies reporting third-quarter results the next few weeks.

History shows that voters have been more likely to support incumbents when the economy is strong, which could be good news for the GOP. But history also shows the president’s party typically suffers big losses in the first midterm elections after taking office. In recent history, the party holding on to the White House lost the majority in one or both houses of Congress in every midterm going back to 2002.

So, investors must prepare for anything. The outcome of the elections may have policy implications that could affect some sectors of the market, including banking, companies that would benefit from government infrastructure projects and those that rely on healthy consumer spending, analysts say. It just depends on which party is in control.

Should Republicans remain in control of Congress, it’s likely the Trump administration will try to make the personal tax cuts included in last year’s reform package permanent. Also, on the possible to-do list: reforming entitlements, more easing of government regulations on banks and other businesses and perhaps tackling the issue of drug price controls, according to a report from UBS on the potential impact of the midterm elections.

If the GOP extends its majority, there could be a push to lower capital gains taxes and enact an infrastructure spending bill.

In the scenario where Democrats regain control of the House, major policy initiatives from the White House will be dead on arrival. Democrats might find common ground with the GOP on an infrastructure bill or on legislation to control drug pricing.

But generally analysts expect gridlock to seize Congress. Compromise could be difficult, especially if the Democrats move to impeach Trump.

If Democrats get control of the House, Senate or both, analysts expect to see more investigations of big banks and Wall Street firms.

“Headline risk for the banking industry would significantly increase as we anticipate numerous congressional hearings to investigate Wells Fargo and other large banks,” analysts at Keefe, Bruyette & Woods wrote in a recent election analysis.

San Francisco-based Wells Fargo has faced several investigations in recent years over practices including the opening of accounts without customers’ consent, charging clients for unnecessary insurance policies, and imposing unfair fees tied to mortgage rates.

UBS also sees the possibility of a government shutdown increasing with a divided Congress, noting that during the government shutdown that occurred during Congress’ 2011 debt ceiling impasse the S&P 500 slumped nearly 20 percent.

However, it’s unlikely that even if Democrats win control of Congress they will be able to reverse the Trump tax cut and the White House’s rollback of government regulations on businesses.

“With this in mind, this election is really about how dysfunctional Washington will be for the second half of President Trump’s first term,” Mike Ryan, chief investment officer, Americas, for UBS Global Wealth Management, noted in the report.

© The Associated Press. All rights reserved.