The following problem in risk theory is considered. An insurance company, endowed with an initial capital a > 0, receives insurance premiums and pays out successive claims from two kind of risks. The losses occur according to a marked point process. At any time the company may broaden or narrow down the offer, which entails the change of the parameters of the underlying risk process. These changes concern the rate of income, the intensity of the renewal process and the distribution of claims. Our goal is to find the best moment for changes which is the moment of maximal value of the capital assets. Based on the representation of stopping times for piecewise deterministic processes and the dynamic programming method the solution is derived for the finite and infinite horizon model.