Dow closes above 40,000 as US stocks finish week higher