Stocks rose, with the major indexes posting record closes, amid sharp gains in oil prices and strong results from retailers.