A Monte Carlo code for nuclear astrophysics experiments