Stocks gain on corporate results, rising commodities