The gains came despite overall market weakness amid sustained selling by foreign portfolio investors