The simplest approach, taken by many banks, is to use external ratings agencies such as Standard and Poors, Fitch or Moody's Investors Service for estimating PDs from historical default experience.
The credit history of the counterparty / portfolio and nature of the investment are taken into account to calculate the PD.
There are many alternatives for estimating the probability of default.
Systematic risk is quantified and modelled by a multifactor Vasicek model with a latent residual, a factor accounting for default contagion and feedback effects. Stress testing as a tool for assessing systematic risks, Financial Stability Review, 2005:6, pp.116-126 Carlehed, M., Petrov, A. A methodology for point-in-time-through-the-cycle probability of default in risk classification systems, Journal of Risk Model Validation, Fall 2012, pp.3-25  Cihak, M. Introduction to Applied Stress Testing, IMF Working Paper, WP/07/59 Committee on the Global Financial System (2001).
The asymptotic maximum likelihood approach for parameter estimation for this model is equivalent to least squares linear regression. A Survey of Stress Tests and Current Practice at Major Financial Institutions Das, S., Duffie, D., Kapadia, N., Saita, L. A risk-factor model foundation for ratings-based bank capital rule.
The performance of the estimation results for LDPs validated by Monte Carlo simulations.