  We analyze the modular properties of D3-brane instanton corrections to the
hypermultiplet moduli space in type IIB string theory compactified on a
Calabi-Yau threefold. In Part I, we found a necessary condition for the
existence of an isometric action of S-duality on this moduli space: the
generating function of DT invariants in the large volume attractor chamber must
be a vector-valued mock modular form with specified modular properties. In this
work, we prove that this condition is also sufficient at two-instanton order.
This is achieved by producing a holomorphic action of SL(2,Z) on the twistor
space which preserves the holomorphic contact structure. The key step is to
cancel the anomalous modular variation of the Darboux coordinates by a local
holomorphic contact transformation, which is generated by a suitable indefinite
theta series. For this purpose we introduce a new family of theta series of
signature (2,n-2), find their modular completion, and conjecture sufficient
conditions for their convergence, which may be of independent mathematical
interest.
