Variational calculation of static and dynamic vibrational nonlinear optical properties