NEW YORK (AP) — Banks and energy companies surged Wednesday and smaller companies made huge gains as stocks got back almost all the ground they lost the day before. Investors reversed course as they hoped Italy would be able to avoid a new round of elections after all.

Financial companies rallied as bond yields turned higher and energy companies rose along with U.S. crude oil, which busted out of a five-day losing streak. The shift came after Carlo Cottarelli, nominated to be Italy's next prime minister, said there were "new possibilities" to form a government.

Stocks had plunged the previous day as investors expected gridlock to be resolved with new elections that could have turned into a yes-or-no referendum deciding whether Italy would continue to use the euro.

JJ Kinahan, chief market strategist for TD Ameritrade, said the market often reacts irregularly to political events like the uncertainty in Italy or tensions between the U.S. and North Korea: stocks often fall fast and then recover in quick fashion. That process can sometimes repeat itself weeks or months later.

"If there's no follow-up news, they tend to come back near where they started," he said. "I wouldn't count on it being done for the summer."

The S&P 500 index jumped 34.15 points, or 1.3 percent, to 2,724.01. The Dow Jones industrial average climbed 306.33 points, or 1.3 percent, to 24,667.78. The Nasdaq composite gained 65.86 points, or 0.9 percent, to 7,462.45.

While the S&P 500 and Nasdaq recovered Tuesday's losses and then some, smaller and more U.S.-focused companies did ever better as investors continued to worry about trade. Small companies finished with minor losses Tuesday, and on Wednesday they made even bigger gains than larger multinationals did. The Russell 2000 index surged 24.34 points, or 1.5 percent, and closed at a record high of 1,647.99.

The Chinese government criticized the U.S., which had renewed a threat to raise duties on some imports from China. At the same time, officials from the U.S. and European Union held talks on the tariffs the Trump administration has proposed on European steel and aluminum. European Union negotiations seemed pessimistic and said they expected the U.S. to announce a final decision Thursday.

China and the EU have both said they will react to new tariffs imposed by the U.S. with duties of their own, which has raised the prospect of greater tensions and the possibility of trade wars. Kinahan, of TD Ameritrade, said investors feel smaller companies are less vulnerable.

Multinational companies have had a rough ride lately as investors reacted to trade tensions by shifting money into smaller and more U.S.-focused companies.

"Much of their business is done domestically, so the tariffs shouldn't affect them as badly," he said. "But even if the tariffs don't happen, many of those stocks are performing well."

Italy's FTSE MIB stock index climbed 2.1 percent after a 2.7 percent drop a day earlier. Prices for Italian government bonds also rose, sending yields down following a huge surge the day before.

The euro rose to $1.1648 from $1.1531, which was its lowest level in almost a year. The dollar rose to 108.85 yen from 108.24 yen.

Germany's DAX climbed 0.9 percent while the FTSE 100 index in Britain rose 0.7 percent. The CAC 40 in France lost 0.2 percent.

Bond prices fell. The yield on the 10-year Treasury note rose to 2.84 percent from 2.79 percent. Interest rates rose and bank stocks recovered about half of their losses from Tuesday. When rates rise, banks can make more money on mortgages and other types of loans.

Energy companies rose as U.S. crude oil climbed 2.2 percent to $68.21 per barrel in New York. Brent crude, used to price international oils, added 2.8 percent to $77.50 a barrel in London.

Exxon Mobil rose 3.9 percent to $81.50. that was its biggest one-day gain since September 2016.

Oil prices fell 7.6 percent in five days following reports OPEC countries and Russia might start producing more oil soon. Those countries cut production at the start of 2017, which helped take U.S. crude from about $50 a barrel in late 2016 to more than $70 this month. They had agreed to keep production at its current levels until the end of this year, but upheaval in Venezuela and new sanctions on Iran could change their plans.

Investors also reacted to more earnings from retailers. Dick's Sporting Goods soared 25.8 percent to $38.35 after it raised its annual profit forecast. Its first-quarter report was better than expected thanks in part to strong online sales. Its decision to stop selling assault rifles and cease selling guns to people under 21 didn't appear to affect its business.

Clothing company Chico's FAS plunged 18.2 percent to $8.17 after its profit fell short of expectations and luxury retailer Michael Kors dropped 11.4 percent to $60.41 following a disappointing forecast for the year.

Gold rose 0.2 percent to $1,301.50 an ounce. Silver added 1 percent to $16.54 an ounce. Copper gained 0.2 percent to $3.07 a pound.

Japan's Nikkei 225 stock index dropped 1.5 percent and the Kospi of South Korea dropped 2. The Hang Seng in Hong Kong slipped 1.4 percent.