Ab initio calculations have been performed for the static and dynamic polarizability and hyperpolarizability for a series of polyynes C2nH2 using self-consistent field (SCF) (n = 1-6) and multiconfiguration self-consistent field (MCSCF) (n = 1-4) wave functions. We have considered the longitudinal component of the static hyperpolarizability and the same component of the dynamic hyperpolarizability measured in electric-field induced second harmonic generation gamma(ESHG) = gamma(-2omega;omega,omega,0). The frequency dependence of the polarizability and hyperpolarizability has been rationalized in terms of the coefficients in expansions in omega2. The static hyperpolarizabilities vary smoothly with the chain length and satisfy gamma (C2nH2) = gamma(C2H2) X n(X), where X almost-equal-to 3.0. The dynamic hyperpolarizability satisfies a similar relation where X in creases slowly with omega.