# Optimizing Investment Portfolios with Bacterial Foraging and Robust Risk Management
## 5 Experimental Results Evaluation  
Addressing the imperative concern of striking a balance between maximizing returns and mitigating risks constitutes a pivotal facet in ensuring comprehensive portfolio management. Within the confines of this scientific inquiry, the application of the BFO Algorithm is meticulously executed to contend with this quandary, utilizing Python as the programming language and incorporating the mathplotlib library for visualization purposes. The fundamental objective of the algorithm's development lies in the optimization of portfolio risk and returns. A tridimensional representation is adopted to portray the results, with specific parameters governing the execution of the BFO algorithm. The stock data utilized in this study were derived from historical daily returns over the past 5 years from a publicly available financial dataset, ensuring robust and representative testing of the algorithm. This dataset was filtered to select stocks across diverse sectors to minimize concentration risk and enhance portfolio diversification. The population size of 20 refers to the number of virtual bacteria (agents) used in the optimization, a value balancing computational efficiency and solution diversity. The step size of 0.1 is fine-tuned to ensure the algorithm effectively explores the search space while maintaining convergence speed. The algorithm employs 30 chemotaxis steps, aligning with the 30 time periods analyzed, ensuring synchronization between the algorithm's iterations and the temporal granularity of the portfolio data. These 30 time periods correspond to a one-month horizon of daily intervals, a practical choice for short-term portfolio management and tactical rebalancing strategies often employed in active investment scenarios [11, 25]. The reproduction rate of 0.2 ensures sufficient diversity in the population without introducing excessive computational overhead. The choice of these parameters was guided by prior research and empirical testing. For example, a population size of 20 has been widely adopted in swarm intelligence studies [7, 15], while the step size and chemotaxis steps were fine-tuned using grid search techniques to achieve an optimal balance between convergence and computational feasibility. The 30-day interval and stop-loss threshold align with widely used tactical rebalancing strategies, reflecting both theoretical insights and practical considerations in financial management [2, 26]. The portfolio consists of five final assets, selected from a pool of candidate stocks based on the optimization criteria. The 30 time periods represent daily intervals over a month, a practical horizon for short-term portfolio strategies. A stop-loss risk threshold of 0.8 triggers rebalancing if the portfolio value drops below 80% of its initial level, helping mitigate significant losses. The rebalancing frequency of every 15 periods (15 days) balances transaction costs with maintaining a responsive portfolio. This choice is particularly pertinent for portfolios with moderate to high volatility, as demonstrated in prior studies exploring rebalancing benefits [27]. Numerous experiments, exceeding several dozen in number, were conducted to scrutinize the algorithm's performance, with particular emphasis on three distinct sets of experiments chosen for detailed analysis. The chosen experiments from each of the three groups are illustrated in Figures 2-4, with the corresponding data presented in Table 1.  
Figure 4: Graphical representation of the portfolio management with BFO results number 3a and 3b, where the portfolio is rebalanced after 15 time periods. Figure 3: Graphical representation of the portfolio management with BFO results number 2a and 2b, showing a portfolio with assets of moderate to high volatility. Figure 2: Graphical representation of the portfolio management with BFO results number 1a and 1b, which illustrates a typical scenario.