This story was updated at 4 p.m. EDT

U.S. stocks closed higher Wednesday, despite fluctuating during most of the trading session after a rise in crude inventories offset forecasts for falling production. The Dow Jones Industrial Average gained more than 150 points following the opening bell, but erased all its gains in late morning trading after crude inventories rose by 3.1 million barrels in the last week, the Energy Information Administration said Wednesday.

However, the Dow reversed in afternoon trading and jumped roughly 120 points higher, driven by drug maker Merck & Co Inc. (NYSE:MRK), which added 2.3 percent. Eight of the 10 sectors in the Standard & Poor's 500 index closed higher, led by advances in healthcare, material and energy stocks.

Following the EIA report, oil pared gains to close lower after adding more than 1 percent in morning trading. West Texas Intermediate crude, the benchmark for U.S. oil prices, lost 1.5 percent to $47.81 per barrel for November delivery on the New York Mercantile Exchange. On the London ICE Futures Exchange, Brent crude, the global benchmark for oil prices, fell nearly 1 percent to $51.30.

The Dow Jones Industrial Average (INDEXDJX:.DJI) rose 122.10 points, or 0.73 percent, to close at 16,912.29. The Standard & Poor's 500 index (INDEXSP:.INX) added 15.9 points, or 0.8 percent, to finish at 1,995.82. The Nasdaq composite (INDEXNASDAQ:.IXIC) gained 42.79 points, or 0.9 percent, to end at 4,791.15.

U.S. stocks closed mixed a day earlier, seesawing during most of the trading day as investors weighed corporate earnings along with a mixed trade report that revealed the trade deficit widened in August by the most in five months.

The EIA report comes after separate data this week from the American Petroleum Institute showed a 1.2 million-barrel decrease in crude stockpiles last week. Crude prices leaped 5 percent a day earlier, after OPEC said it expects global oil production to ease in 2016, which could help ease concerns about a glut in crude supplies. Global crude prices have lost more than half of their value over the last year due to fears of oversupply.

Global supply is forecast to rise to 95.98 million barrels a day next year, 0.1 percent less than expected last month, the U.S. Energy Information Administration said Tuesday in its Short-Term Energy Outlook.

Oil also rallied more than 3 percent Monday on news Russia said it was ready to meet with OPEC and other nonmember crude producers to discuss the crude market.

Global shares traded higher Wednesday, with China’s benchmark Shanghai Composite index closing up 0.5 percent while Japan’s Nikkei index added 0.75 percent.

European stocks also closed higher, with Germany's DAX and France's CAC rising 0.7 percent and 0.14 percent, respectively.