Electronic structure, optical spectra, and x-ray magnetic circular dichroism in CoS 2