We report first-principles calculations of the second-order optical response coefficients in the I-III-${\mathrm{VI}}_{2}$ $(\mathrm{I}=\mathrm{A}\mathrm{g},\mathrm{C}\mathrm{u};$ $\mathrm{I}\mathrm{I}\mathrm{I}=\mathrm{G}\mathrm{a},\mathrm{I}\mathrm{n};$ $\mathrm{V}\mathrm{I}=\mathrm{S},\mathrm{S}\mathrm{e},\mathrm{T}\mathrm{e})$ chalcopyrite semiconductors. The computational approach uses the length-gauge formulation of perturbation theory which explicitly separates pure interband from mixed intraband-interband contributions. The expressions for static and frequency dependent second-harmonic generation coefficients are evaluated from band structures based on the local density approximation but including semiempirical gap corrections. The linear muffin-tin orbital method is used to calculate the required band structures and matrix elements. The results are in good agreement with experiment for the compounds for which data are available and provide predictions in the other cases. The trends show that the dominating factor determining ${\ensuremath{\chi}}^{(2)}$ is the anion rather than the group I or group III cation. The ${\ensuremath{\chi}}^{(2)}$ values clearly fall into separated groups with increasing value going from S to Se to Te. While this correlates approximately inversely with the band gap, several exceptions are notable: (1) Cu compounds have smaller gaps than corresponding Ag compounds and nevertheless have slightly lower ${\ensuremath{\chi}}^{(2)};$ (2) ${\mathrm{AgGaTe}}_{2}$ has a higher gap than ${\mathrm{AgInSe}}_{2}$ but nevertheless has a much higher ${\ensuremath{\chi}}^{(2)}.$ An analysis of the various contributions to the frequency dependent imaginary part of the response functions, $\mathrm{Im}{{\ensuremath{\chi}}^{(2)}(\ensuremath{-}2\ensuremath{\omega},\ensuremath{\omega},\ensuremath{\omega})},$ is presented in an attempt to correlate the ${\ensuremath{\chi}}^{(2)}$ values with band structure features. The main findings of this analysis are that (1) there is a large compensation between intra/inter- and interband contributions frequency by frequency as well as in the static values; (2) the static ${\ensuremath{\chi}}^{(2)}$ value is strongly affected by the sign of the low frequency parts of these separate contributions; (3) these low frequency parts correspond to only a few valence and conduction bands and only to so-called $2\ensuremath{\omega}$ resonances; (4) the general shape of the $\mathrm{Im}{{\ensuremath{\chi}}^{(2)}(\ensuremath{-}2\ensuremath{\omega},\ensuremath{\omega},\ensuremath{\omega})}$ response functions is determined by the band structures alone while the intensity, which ultimately explains the difference between tellurides and selenides, arises from the magnitude of the matrix elements. Starting from ${\mathrm{AgGaSe}}_{2},$ the smaller effect on the ${\ensuremath{\chi}}^{(2)}$ due to In subsitution for Ga than to Te substitution for Se can be explained by the fact that the Ga to In substitution changes the gap only in a small region near the center of the Brillouin zone, while the Se to Te substitution changes the gap throughout the Brillouin zone. This shows that contributions from other parts of the Brillouin zone than the center dominate the behavior. The difference between Cu and Ag based compounds can be explained on the basis of a different degree of compensation of inter- and intra/interband contributions.