The market got a boost from a pickup in the price of oil, which climbed about 4 percent after an early slide. When oil prices rise they tend to favor battered energy stocks and financial companies such as banks, which have been in the doldrums due to investor concerns that loans to struggling oil companies could go bad.
Utilities and consumer staples stocks were among the biggest decliners.
The& Dow& Jones industrial average rose 42.67 points, or 0.2 percent, to 18,096.27. The Standard & Poor’s 500 index added 1.60 points, or 0.1 percent, to 2,102.40. The Nasdaq composite index gained 7.80 points, or 0.2 percent, to 4,948.13.
The& Dow& is now up almost 4 percent for the year, while the S&P 500 is up about 3 percent. The Nasdaq narrowed its loss to 1.2 percent.
Trading got off to a flat start, with the major stock indexes moving sideways. They perked up by midmorning, as oil prices turned higher, but the rally lost some steam by the end of the day.
U.S. crude rose $1.55, or 3.8 percent, to close at $42.63 a barrel in New York. Brent crude, the international benchmark, climbed $1.77, or 4 percent, at $45.80 a barrel in London. Heating oil jumped 5.5 percent after adding 7 cents to close at $1.33 a gallon.
That helped lift shares in several energy companies. Chesapeake Energy gained 30 cents, or 4.9 percent, to $6.42, while Williams Cos. rose 82 cents, or 4.6 percent, at $18.83.
The market got some hopeful data on housing, with the National Association of Realtors reporting sales of previously occupied U.S. homes bounced back in March after a February slump.
Investors also had their eye on the latest batch of company earnings.
Corporate profits for companies in the S&P 500 are expected to be down 8.1 percent, according to S&P Global Market Intelligence. Even excluding energy companies, which have been hammered by falling oil prices, earnings growth for the S&P 500 companies is projected to be down 3.3 percent.
Coca-Cola slid 4.8 percent after the world’s biggest beverage maker reported a lower profit for the first quarter. The company was squeezed by a strong dollar and charges related to the transformation of its North American operations. Coca-Cola was the biggest decliner in the S&P 500. It lost $2.23 to $44.37.
Stock markets in Europe also closed higher.
Germany’s DAX rose 0.7 percent, while the CAC-40 of France gained 0.6 percent. The FTSE 100 of leading British shares added 0.1 percent. Earlier in Asia, most markets closed lower. South Korea’s Kospi fell 0.3 percent and Hong Kong’s Hang Seng slid 0.9 percent. Japan’s benchmark Nikkei 225 edged up 0.2 percent.
In other energy trading, wholesale gasoline rose about 3 cents, or 1.8 percent, to close at $1.51 a gallon. Natural gas fell 2 cents to close at $2.069 per 1,000 cubic feet.
Precious and industrial metals futures inched higher. Gold rose 10 cents to $1,254.40 an ounce, silver gained 16 cents, or 1 percent, to $17.14 an ounce and copper rose 1.5 cents to $2.24 a pound.
Bond prices fell. The yield on the 10-year Treasury note rose to 1.85 from 1.78 late Tuesday. In currency markets, the euro fell to $1.1302 from $1.1377, while the dollar rose to 109.80 yen from 109.13.