US stocks whipsaw to end higher as investors mull rate fears and government shutdown risks