US stocks close lower as exchanges post weekly losses