The Election Showed a Divided Country. Investors Can Live With That.

Stocks jumped on Wednesday, extending a recovery from the sharp sell-off in October with broad-based gains, after midterm elections that will split control of the United States government between both major parties.

The S&P 500 rose 2.1 percent, led by giant technology companies including Amazon, Apple and Google. The tech-heavy Nasdaq composite index rose 2.6 percent, its strongest gain this month.

Stock in consumer discretionary companies climbed 3.1 percent, in a sign of growing optimism that President Trump, stung by his party’s loss of the House of Representatives, could seek a win by striking a trade bargain with China at the Group of 20 summit meeting this month. Shares of Wynn Resorts, the casino company with significant business in China, jumped 3.9 percent.

After weeks of uncertainty heading into the election, investors seemed to focus again on the strong fundamentals for American businesses, helping fuel the gains on Wednesday.

In the voting on Tuesday, Democrats secured control of the House in the next Congress, while the Republicans padded their majority in the Senate. A divided government is conventionally thought of as good for stock investors, because it means lawmakers are unlikely to produce sweeping policy changes.

“Investors can basically refocus their mental energy away from the macro and back to the micro, where earnings are really good and valuations are really reasonable,” said Julian Emanuel, chief equity strategist at the institutional brokerage BTIG.

Industrial shares rose, bolstered by renewed hope for a bipartisan infrastructure-spending bill. The construction machinery maker Caterpillar, which also has large exposure to China, rose 4.5 percent.

Health care shares rallied on the prospect that major health legislation is much less likely. Managed care companies that sell contract Medicaid services to state governments and insurance products on health exchanges established under the Affordable Care Act rose sharply.

“You worry less about large sweeping regulatory change,” said Zack Sopcak, an equity analyst covering managed care companies for Morgan Stanley. “It means a repeat of ‘repeal and replace’ is off the table,” he added, referring to the potential for a wholesale replacement of the law, commonly known as Obamacare.

After an ugly sell-off in October, investors appear to have regained their appetite for stocks. The S&P 500 has risen in four of the first five trading days of November. The 2.1 percent gain on Wednesday for the broad index of large companies was its third-best showing this year.

That turn of events reflects a dizzying swing in market sentiment. As recently as Oct. 29, the market was down more than 1 percent for the year after a rout that started in September had vaporized nearly 10 percent in gains.

At that time, investors saw ubiquitous threats to the nearly decade-long rally for stocks. The potential pitfalls included rising interest rates, climbing commodity and wage costs, signs of slowing growth in China and Europe and the tariff war between the United States and China, the world’s two largest economies.

Most of the issues remain unresolved, but the markets have found their footing and trading seemed to suggest investors see reasons for optimism now that the elections have concluded.

Equity investors are now sitting on gains of more than 5 percent for the year.