The S&P 500 and the Nasdaq have surged to record highs this week as investors focused on strong financial reports from US companies.