We study the following stochastic investment model: opportunities occur randomly over time, following a renewal process with mean interarrival time d, and at each of them the decision-maker can choose a distribution for an instantaneous net gain (or loss) from the set of all probability measures that have some prespecified expected value e and for which his maximum possible loss does not exceed his current capital. Between the investments he spends money at some constant rate. The objective is to avoid bankruptcy as long as possible. For the case e>d we characterize a strategy maximizing the probability that ruin never occurs. It is proved that the optimal value function is a concave function of the initial capital and uniquely determined as the solution of a fixed point equation for some intricate operator. In general, two-point distributions suffice; furthermore, we show that the cautious strategy of always taking the deterministic amount e is optimal if the interarrival times are hyperexponential, and, in the case of bounded interarrival times, is optimal ‘from some point on’, i.e. whenever the current capital exceeds a certain threshold. In the case e = 0 we consider a class of natural objective functions for which the optimal strategies are non-stationary and can be explicitly determined.