We consider a risk process modelled as a compound Poisson process. We find the optimal dynamic unlimited excess of loss reinsurance strategy to minimize infinite time ruin probability, and prove the existence of a smooth solution of the corresponding Hamilton-Jacobi-Bellman equation as well as a verification theorem. Numerical examples with exponential, shifted exponential, and Pareto claims are given.