We propose a systematic procedure for constructing effective models of strongly correlated materials. The parameters, in particular the on-site screened Coulomb interaction U, are calculated from first principles, using the GW approximation. We derive an expression for the frequency-dependent U and show that its high frequency part has significant influence on the spectral functions. We propose a scheme for taking into account the energy dependence of U, so that a model with an energy-independent local interaction can still be used for low-energy properties.