The origin of the red-sequence galaxy population in the EAGLE simulation