The theoretical and numerical approaches are discussed for ab initio calculations of optical properties. The density functional theory (DFT) combined with the local-density approximation (LDA) allows the calculation of the geometry of crystalline solids and their surfaces with a precision of about one percent. The DFT-LDA band structure and single-electron states therefore provide a reasonable starting point for the calculation of linear and nonlinear susceptibilities within the independent-particle approximation. However, this approach has to be improved by taking into account many-body interactions: self-energy effects, local-field corrections, and electron-hole attraction. Three types of optical spectra are studied: the frequency-dependent dielectric function, the second-harmonic generation, and surface reflectance anisotropy spectra. The systems considered are two-atomic semiconductors, their polytypes and their surfaces.