Continued from page 1

D.R. Horton rose 79 cents, or 3.9 percent, to $21.72. Lennar gained $1.41 cents, or 3.9 percent, to $37.42.

Investors were also encouraged by comments from a key Fed official. William C. Dudley, Federal Reserve Bank of New York president, said the central bank likely will keep buying bonds if the economy failed to grow at the pace the Fed was expecting.

“If labor market conditions and the economy’s growth momentum were to be less favorable than in the (Fed‘s) outlook — and this is what has happened in recent years — I would expect that the asset purchases would continue at a higher pace for longer,” Mr.  Dudley said at a news conference in New York.

The S&P 500 index is on track to log its best first half of a year in 15 years. The index has gained 13.2 percent so far this year. If it ends the week at its current level, it would mark the best first-half performance since 1998. That year the index rose 17.7 percent in the first six months of the year.

The market likely will become more volatile in the second half of the year as investors assess when the Fed will end its stimulus, said Kate Warne, investment strategist at retail brokerage firm Edward Jones.

“The general outlook for the economy is solid,” Ms. Warne said. “The trend in stock prices is likely to continue to be higher, even though we’ll see a lot more zigzagging as everyone debates the timing of the Fed’s next move.”

In commodities trading, the price of oil rose $1.49, or 1.6 percent, to $97.01 a barrel. Gold fell $27.50, or 2.3 percent, to $1,202.50 an ounce. The price of the metal has plunged more than 10 percent in the last two weeks.

In other trading, the Nasdaq composite rose 27 points, or 0.8 percent, to 3,403.

The dollar fell against the euro and the Japanese yen.

Among stocks making big moves:

• ConAgra Foods rose $1.78, or 5.3 percent, to $35.13 after the company posted a quarterly profit that came in a penny above the expectations of Wall Street analysts. The maker of Chef Boyardee, Hebrew National and other packaged foods benefited from acquisitions and price cuts that helped increase sales.

• Payroll processor Paychex fell $2.03, or 5.3 percent, to $35.96 after posting earnings that fell short of analysts’ expectations. The company said profit for the three months through May 31 came in roughly flat at 34 cents per share. Analysts had expected earnings of 37 cents a share.

• KB Home rose 56 cents, or 2.8 percent, to $20.46, after the homebuilder’s second-quarter loss narrowed. The company continued to deliver more homes at higher prices as the real estate market strengthened.