The aim of this paper is to construct an optimal investment strategy for a non-life insurance business. We consider an insurance company which provides, in exchange for a single premium, full coverage to a portfolio of risks which generates losses according to a compound Poisson process. The insurer invests the premium and trades continuously on the financial market which consists of one risk-free asset and n risky assets (Black-Scholes market). We deal with the insurer's wealth path dependent disutility optimization problem and apply a quadratic loss function which penalizes deviations below a reserve for outstanding liabilities as well as above a given upper barrier. An optimal investment strategy is derived using stochastic control theory in the absence of constraints on control variables. Some properties of the strategy and the behaviour of the insurer's wealth under the optimal control are investigated. The set up of our model is more general, as it can also be used in non-life loss reserving problems.