In recent years, peer‐to‐peer (P2P) lending has been gaining popularity amongst borrowers and individual investors. This can mainly be attributed to the easy and quick access to loans and the higher possible returns. However, the risk involved in these investments is considerable, and for most investors, being nonprofessionals, this increases the complexity and the importance of investment decisions. In this study, we focus on generating optimal investment decisions to lenders for selecting loans. We treat the loan selection process in P2P lending as a portfolio optimization problem, with the aim being to select a set of loans that provide a required return while minimizing risk. In the process, we use internal rate of return as the measure of return. As the starting point of the model, we use machine‐learning algorithms to predict the default probabilities and calculate expected values for the loans based on historical data. Afterwards, we calculate the distance between loans using (i) default probabilities and, as a novel step, (ii) expected value. In the calculations, we utilize kernel functions to obtain similarity weights of loans as the input of the optimization models. Two optimization models are tested and compared on data from the popular P2P platform Lending Club. The results show that using the expected‐value framework yields higher return.