Foreign investors are giving up on China as capital flows reverse