Estimation of probability of default has considerable importance in risk management applications where default risk is referred to as credit risk. Basel II (Committee on Banking Supervision) proposes a revision to the international capital accord that implies a more prominent role for internal credit risk assessments based on the determination of default probability of borrowers. In our study, we classify borrower firms into rating classes with respect to their default probability. The classification of firms into rating classes necessitates the finding of threshold values separating the rating classes. We aim at solving two problems: to distinguish the defaults from non-defaults, and to put the firms in an order based on their credit quality and classify them into sub-rating classes. For using a model to obtain the probability of default of each firm, Receiver Operating Characteristics (ROC) analysis is employed to assess the distinction power of our model. In our new functional approach, we optimise the area under the ROC curve for a balanced choice of the thresholds; and we include accuracy of the solution into the program. Thus, a constrained optimisation problem on the area under the curve (or its complement) is carefully modelled, discretised and turned into a penalized sum-of-squares problem of nonlinear regression; we apply the Levenberg-Marquardt algorithm. We present numerical evaluations and their interpretations based on real-world data from firms in the Turkish manufacturing sector. We conclude with a discussion of structural frontiers, parametrical and computational features, and an invitation to future work.