In the field of economics and financial markets, optimal asset allocation strategies are essential for investor satisfaction and success. This paper delves into the complex landscape of multi-period portfolio selection, where the objective is to maximize wealth while minimizing investment risk. The core challenge of this research lies in addressing the complexity and uncertainty inherent in multi-period portfolio selection under stochastic conditions. The study introduces a framework for multi-period portfolio selection, considering N risky assets over T time periods. Stochastic return rates are modeled using a stochastic distribution, with the objective of maximizing wealth under risk constraints. The study presents an empirical case study involving the S&P500 market index, demonstrating the applicability of the proposed approach. Utilizing a random forest model, the paper predicts future returns, incorporating these predictions into a deterministic model via chance constraints. The contributions of the paper are substantial and multifaceted. Firstly, it introduces bankruptcy constraints, providing a more realistic approach to portfolio optimization and addressing an often-overlooked aspect of financial modeling. Secondly, transaction costs, a critical consideration in real-world scenarios, are integrated into the model, significantly enhancing the accuracy and practical relevance of portfolio optimization strategies. Thirdly, uncertainty management is rigorously tackled through stochastic approaches, ensuring the development of robust strategies that can accommodate varying market conditions. The paper also introduces risk-adjusted performance measures, enabling more informed decision-making by considering both risk and returns. Innovatively, this paper employs the Random Forest technique to predict return rates, thereby substantially enhancing the precision of investment predictions. Additionally, the Root System Growth Algorithm adds a heuristic dimension to problem-solving, effectively bridging the gap between computational and solution efficiency. The findings highlight the pivotal role of optimal allocation strategies in mitigating investment risks. The proposed approach yields impressive final wealth values and consistently performs well across different risk levels. © 2024 Elsevier B.V.