A dynamical Thouless formula