Consider a portfolio containing heterogeneous risks, where the policyholders’ premiums to the insurance company might not cover the claim payments. This risk has to be taken into consideration in the premium pricing. On the other hand, the premium that the insureds pay has to be fair. This fairness is measured by the distance between the risk and the premium paid. We apply a non-linear programming formulation to find the optimal premium for each class so that the risk is below a given level and the weighted distance between the risk and the premium is minimized. We consider also the dual problem: minimizing the risk level for a given weighted distance between risks and premium.