SAIPO-TAIPO and Genetic Algorithms for Investment Portfolios

: The classic model of Markowitz for designing investment portfolios is an optimization problem with two objectives: maximize returns and minimize risk. Various alternatives and improvements have been proposed by different authors, who have contributed to the theory of portfolio selection. One of the most important contributions is the Sharpe Ratio, which allows comparison of the expected return of portfolios. Another important concept for investors is diversiﬁcation, measured through the average correlation. In this measure, a high correlation indicates a low level of diversiﬁcation, while a low correlation represents a high degree of diversiﬁcation. In this work, three algorithms developed to solve the portfolio problem are presented. These algorithms used the Sharpe Ratio as the main metric to solve the problem of the aforementioned two objectives into only one objective: maximization of the Sharpe Ratio. The ﬁrst, GENPO, used a Genetic Algorithm (GA). In contrast, the second and third algorithms, SAIPO and TAIPO used Simulated Annealing and Threshold Accepting algorithms, respectively. We tested these algorithms using datasets taken from the Mexican Stock Exchange. The ﬁndings were compared with other mathematical models of related works, and obtained the best results with the proposed algorithms.


Introduction
In finance, applying the diversification of assets that make up an investment portfolio aims to maximize profits and minimize risk. The mean-variance portfolio integration model developed by Harry Markowitz in 1952 has been a widely accepted tool for asset portfolio integration [1]. Markowitz's portfolio theory states that the investor should analyze the portfolio as a whole, studying the characteristics of risk and global return. The participation of each asset is chosen based on its expected return. In other words, volatility is treated as a risk factor, and the portfolio is integrated, considering the risks and seeking the maximum level of profitability available [2]. Some investigations have expanded the work of the Markowitz model, such as the mean semi-variance model [3], mean objective model [4], and portfolio optimization models with fuzzy logic [5]. Different metaheuristics algorithms have been applied to solve difficult problems, and recently important overviews have been published regarding these types of problems [6][7][8]. The reason for employing these algorithms is that they obtain suitable solutions within reasonable execution times [9]. For instance, a two-stage multi-attribute portfolio analysis framework using genetic algorithms (GA) to solve a multi-attribute portfolio selection problem was proposed [10]. Moreover, Genetic Algorithms have been used for selecting and evaluating investment portfolios [11]. As seen in [12], the mean-variance approach was used as a reference to propose a new model which included different constraints, using GA as an optimization method. Chen Annealing, Threshold Accepting, and Genetic Algorithms. In Section 3, the algorithms proposed in this work are described. In Section 4, we present the experiments and results. Finally, in Section 5, the conclusions of this work are presented.

Background & Related Works
As we mentioned before, this work proposes the use of classical algorithms GA, TA, and SA. We present a general description of these algorithms in the first subsection. Moreover, new successful models are usually based on the Markowitz model; they are referred to here as Yu, Gilli, and Masese models. Then, we briefly present all these models in the Related Works subsection.  [38]. These algorithms imitate nature for solving complex problems [39][40][41]. They select solutions from the solution space of the problems considered. Basically, a GA evolves a population of individuals (solutions) by selecting operations similar to those in biological evolution (for instance, mutation and crossing over). The procedure of the Classic GA is shown in Algorithm 1. Begin /* Reproductive cycle */ 4: Select two individuals, X 1 y X 2 of P(i), 5: Crossing point random selection. 6: Cross X 1 y X 2 getting two offspring X h1 , X h2 . 7: Insertion X h1 y X h2 in P(i) 8: Mutation random τ elements of P(i); 9: Compute fitness function (i) of τ elements, 10: Order individuals best evaluated in P(i).

11:
Limit the population to its original size. 12: End 13: IF convergence = true or gen = max generation 14: End

Simulated Annealing and Threshold Accepting
Proposed by Kirkpatrick in the 1980s [42], the Simulated Annealing (SA) algorithm is based on the Metropolis algorithm [43], which is used in the heat treatment of metals. SA begins with an initial solution; then, a neighbor solution is selected randomly. A new solution is accepted if it is better than the old solution; otherwise, the new solution is accepted with a probability based on the Boltzmann distribution; with this criterion, the acceptance rate of incorrect solutions decreases during the execution of the algorithm. This strategy is used to escape from local optima. The parameters of this algorithm include an initial temperature T i , final temperature T f , cooling rate α, and the number of iterations for each metropolis cycle, as shown in Algorithm 2.
The Threshold Accepting (TA) algorithm was proposed by Dueck and Scheuer [44] and is similar to Simulated Annealing. The fundamental difference is the acceptance criterion of new solutions. In TA, a poor solution can be accepted if the decrease does not exceed a certain tolerance or threshold, which decreases during the execution of the algorithm. This criterion avoids calculating probabilities or making random decisions. The parameters of this algorithm are the number of iterations n iter , number of steps n steps , and a threshold sequence, as shown in Algorithm 3. Both SA and TA algorithms have been applied to successfully solve different problems [45,46]. T k = T i 3: s current = random initial solution 4: while T k ≥ T f do 5: while Metropolis lenght do 6: if ∆ < 0 then 9: s current = s new 10: else if e −∆ T k < random(0, 1) then 11: s current = s new 12: end if 13: end while 14: T k = α * T k 15: end while 16: end Simulated Annealing Algorithm 3. Classic Threshold Accepting 1: Initialize n iter and n steps 2: Compute Threshold Sequence T r , r = 1, 2, . . . n iter 3: Generate random initial solution X c ∈ X 4: for r = 1 to n iter do 5: for i = 1 to n steps do 6: Generate X n ∈ N(X c ) 7: if ∆ < T r then 9: X c = X n 10: end if 11: end for 12: end for The process of parameter tuning for the SA and TA algorithms used in this paper is based on the analytical tuning method presented in [47]. This method states that the initial and final temperatures are functions of the maximum and minimum cost or energy values E max and E min . These values are used in the Boltzmann distribution criterion, which establishes that, in a temperature T, a poor solution is accepted if random(0, 1) ≤ e − ∆E T . The values ∆E max and ∆E min are used in the Boltzmann distribution for determining the initial and final temperatures. To obtain these values, a set of previous executions must be carried out [46]. The parameters used in the tuning process are shown in Table 1.
The probability of accepting a new solution is close to one at high temperatures, thus the deterioration of the energy is at a maximum. T i is associated with ∆E max and P(∆E max ), and can be calculated with Equation (1), while P(∆E max ) is given by Equation (2). The minimum deterioration P(∆E min ), calculated with Equation (3), is used to establish T f , as shown in Equation (4).
The cooling scheme establishes the method behind decreases in temperature using a factor α. For rapid decrements, an α value equal to 0.7 is commonly used, and for slow decrements, the figure is 0.99 [46]. Given a current temperature T k , the next temperature value T k+1 is calculated with Equation (5).
The parameter L k , refers to the number of iterations of the Metropolis cycle at each temperature. In high temperatures, few iterations are required, since the equilibrium is reached quickly; for this reason, L min is usually close to one. Nevertheless, at low temperatures, a more exhaustive search is required; therefore, a larger L k is used. For a given value of L k , then L k+1 can be calculated with Equation (6). Since Equations (5) and (6) are applied successively from T i to T f , L max is calculated as L max = β n L min , while T f = α n T i , where n and β are calculated with Equations (7) and (8), respectively [48].
P(∆E max ), P(∆E min ) Probability of accepting a solution with maximum and minimum deterioration α Temperature decrease factor - C Exploration level C = ln P s j (11) On the other hand, the probability of selecting the solution s j from N random samples in V Si is given by Equation (9); for this expression, N is calculated with Equation (10), where C defines the exploration level calculated with Equation (11). To guarantee a good exploration level, the value of C must be between 1 ≤ C ≤ 4.6. Finally, once C is defined, L max can be established with Equation (12).

Markowitz Model
A typical feature of Markowitz's theory is that it provides a quantitative solution to portfolio asset allocation, as it considers the possible trade-off between expected return and risk exposure between established securities or assets. Thus, the investment portfolio design problem is a multi-objective optimization issue with two main objectives [1]: maximize the expected return, and minimize the variance of the portfolio models with Equations (13) and (14), respectively. This model uses a mean-risk relationship, which is known as the mean-variance approach.
x i x j σ ij (14) Subject to : where E(R) is the expected return of the portfolio; µ i is the expected return of asset i; x i is the fraction or weight of asset i in the portfolio, this weight must be positive (Equation (16)), in addition, the sum of all weights must be equal to one as shown in Equation (15); n is the number of assets in the portfolio; σ 2 (R) is the variance of the portfolio; σ ij is the covariance between asset i and j.

Yu Model
A genetic algorithm (GA) was proposed [10] for a two-stage multi-attribute portfolio analysis framework to solve the portfolio selection problem. First, a GA is used for evaluating asset quality with multiple asset attributes, and some are selected. Then, another GA is used to optimize capital allocation among the selected assets in the second stage. Finally, the fitness function F(R) is used to make a rational trade-off between minimizing risk and maximizing expected return, as shown in Equation (17). (17) where x i , x j are the portion of the stocks i, j integrating the portfolio, and σ ij ; is the covariance of them. Moreover, µ i is the mean of the stock value and n ∑ i=1 µ i x i is the expected return of the portfolio. Finally, γ represents the MARR.
In another section, we present the results obtained with this model.

Gilli Model
This model uses a single-objective minimization approach based on the classical Markowitz model. The Gilli model seeks to create optimal portfolios in terms of variance and expected return [21]. The mathematical model is shown in Equations (18) and (19).
where, the variables σ 2 (R) and E(R) denote the variance and the expected return of the portfolio, respectively, while p is a penalty function. The values for σ 2 (R) max , σ 2 (R) min are the maximum and minimum variance, and R is an average of the expected return value of numerous randomly generated portfolios. While γ is the required return and has been pre-defined. These parameters are used for defining the scaling constant p. The problem in this model is to define this scaling constant for achieving the best portfolios. Therefore, this model uses the scaling constant for achieving optimal portfolios.

Masese Model
This model is similar to the classical formulation of Markowitz for investment portfolios, and is an optimization problem defined by Equation (20). This model aims to minimize the variance of the portfolio [22]; they use the classical Threshold Accepting algorithm [44].
Subject to n in f ≤ n sup (22) where x i in f and x sup i , shown in Equation (21), are the minimum and maximum weights for the stock in the portfolio, and n in f and n sup in Equation (22), are the constraints setting the minimum and a maximum number of stocks in the portfolio. The authors of this paper reported that their model outperforms the Markowitz Model for portfolio selection.

Proposed Algorithms
The three algorithms proposed in this work, GENPO [49], SAIPO, and TAIPO, are described in this section. These algorithms use optimization heuristics for obtaining the stocks and then integrating the portfolio that is modeled as an optimization problem. GENPO uses a Genetic Algorithm, SAIPO uses a Simulated Annealing Algorithm, and TAIPO uses a Threshold Accepting Algorithm.

Mathematical Model for the Evaluation Function
The Sharpe Ratio (SR) is a financial metric proposed by W. Sharpe [34]. This financial ratio indicates how suitable an investment is concerning its risk. This ratio can be used to determine which investment obtains the greatest return with the same risk. In other words, it determines the additional return achieved by investing in riskier financial assets. SR is calculated with Equation (23).
where E(R) is the portfolio's expected return, γ is the MARR (Minimum Acceptable Rate of Return), and σ(R) represents the portfolio's risk. The MARR parameter means that any stock (or investment) should not be part of the portfolio if it does not surpass it. Sharpe Ratio (SR) is based on the Markowitz model, and it is assumed that there are adequate statistics for determining: (a) the expected value of the shares and (b) the standard deviation (the risk measure) of the asset value over a given period. On the other hand, the problem of selecting the best stocks from a specific market can be formulated as those that maximize the expected return and, at the same time, minimize the risk value of the portfolio; a practical alternative centers on finding stocks which maximize the Sharpe ratio. This strategy allows the discovery of portfolios with assets from different financial areas selected when the SR is maximized.
The proposed model represented by Equation (24) seeks to maximize the Sharpe Ratio, subject to the expected value of the portfolio being greater or equal to the MARR ratio.
Subject to where E(R) = µ i x i is the expected return of the portfolio, µ i is the expected return of asset i, and x i is the weight of the asset i in the portfolio. This model includes a constraint shown in Equation (25), that allows only assets with an expected return equal to or greater than the MARR to be included in the portfolio. The MARR parameter is represented here by γ. As mentioned before [49], maximizing the value of the Sharpe Ratio allows solving the problem of two objectives in one. However, it is an NP-hard problem; thus, finding the optimal solution is not an easy task. We used Equation (26) to estimate the risk of the portfolio, while the average correlation of the portfolio was obtained with a simple process [37]. This correlation is provided in Equation (27), and we used it to check that the correlation of the entire portfolio had a low value. In [50], the correlation between assets and bonds was analyzed. Similarly, a previous study [37] used a strategy to evaluate portfolios and risks from different portfolios.
The interpretation of Equation (27) is as follows: if ρ p ∼ = 1 the portfolio has little diversification; on the other hand, if ρ p ∼ = 0 the portfolio is highly diversified.
The portfolio solution found with the model implemented in this paper, contained the weighted values of the assets x i ; the expected value portfolio's E(R) and its risk σ(R), in addition to the Sharpe Ratio and average correlation of the portfolio ρ p . This model and the implemented algorithms aim to find a balance between the expected value and the portfolio's risk. Moreover, the implemented algorithms seek to find an equilibrium between the Sharpe metric and the managing portfolio risk.

Genetic Portfolio Optimization Algorithm (GENPO)
Algorithm 4 shows the structure of the GENPO algorithm. This is a Genetic Algorithm where the initial population is conformed randomly by a set of weights in the range (0,1); additionally, the summation of these weights should be one. The fitness function was previously shown in Equation (24), and is applied for each population generated by the algorithm. Then, the subsequent generations are generated, choosing one or two solutions, depending on the genetic operator used: crossover or mutation, respectively.
From lines 1 to 5, a population is generated using a random number in the range (0,1). The fitness Sharpe Ratio (SR) is the fitness function based on Sharpe Ratio described in Equation (24). Moreover, it establishes the population size and the generations.
Lines 6 to 16 integrate the selection step. Two individuals from the population are evaluated by the fitness function and two individuals from the binary tournament, evaluating from the higher expected value.
In the Crossover step, the x i values (the portion of assets) are randomly selected to generate offspring from the selected individuals in the previous step. These offspring could be part of the population depending on their SR. They are sorted from highest to lowest. The last two individuals are discarded from the population to retain the population size. From line 17 to the end, lays up the best individual from each generation to store their variables and performance.
The best individual from generation i is compared with the previous individuals of generation i − 1. The process is repeated each time a new population is generated. This process is performed to determine if the number of generations achieves the maximum permitted number without enhancement, which is used as a stop criterion.
The result of the algorithm is a portfolio with the best assets and the investment proportion applied in each one. This combination of assets has the best profit-risk ratio and the lowest correlation, leading to the highest portfolio diversification. Set first gen i = 0 3: Generate initial population (portfolio) P(i) 4: Compute Sharpe Ratio (SR) evaluation initial for each individual SR(i) 5: While Converge = False or i < MaxGen do 6: Begin /* Produce new generation */ 7: Begin /* Reproductive cycle */ 8: Select two individuals (portfolios), X 1 y X 2 of P(i), 9: Crossing point random selection. 10: Cross X 1 y X 2 getting two offspring X h1 , X h2 .

11:
Insertion X h1 y X h2 in P(i) 12: Mutation random τ elements of P(i); 13: Compute fitness function (i) of τ elements, 14: Order individuals best evaluated in P(i).

15:
Limit the population to its original size.

16:
End 17: Save best individual of the population P(i) 18: If SR(i +

Simulated Annealing for Investment Portfolio Optimization (SAIPO)
The SAIPO algorithm uses the negative value of the Sharpe Ratio, shown in Equation (24), as the objective function.
SAIPO (Algorithm 5) receives as initial parameters (line 1) an initial temperature (T i ), final temperature (T f ), a cooling rate α, an internal cycle length L k , and an internal cycle increment coefficient β. In line 2, a random initial solution is generated, represented by X c , defined as a portfolio with random weights. Then, in line 3, the negative value of the Sharpe Ratio is calculated. In line 4, the current temperature T k takes the value of the initial temperature T i . In line 5, the main cycle begins, which is executed until the current temperature is greater than or equal to the final temperature. In line 6, the Metropolis cycle begins. In line 7, a new solution is generated by applying a perturbation to the current solution. This new solution is compared with the existing solution, then calculating the difference between both solutions in line 8. When this difference is negative (line 9), the new solution is accepted in line 10; if this new solution is better than the best previously found, it is accepted as the best global solution in line 12. Alternatively, if the difference is greater or equal to zero, the new solution is accepted by applying the Boltzmann acceptance criterion in line 14. In line 19, the number of iterations of the Metropolis cycle (L k ) increases, multiplying its previous value by β. In line 20, the current temperature T k is decreased by multiplying its value by the α value. Finally, in line 22, the Sharpe Ratio is calculated by multiplying its negative value by −1. Lastly, in line 23, the output of the algorithm is generated.
Generate random initial solution X c = X best 3: s c = f (X n ) = SRneg = s best 4: while k < L k do 7: if ∆ < 0 then 10: s c = s n ; X c = X n 11: if s c < s best then 12: s best = s c ; X best = X c 13: end if 14: else if random (0,1)< e −∆/T k then 15: s c = s n ; X c = X n 16: end if 17: return SR, X best 24: end SAIPO Based on the neighborhood structure method presented in [23], in this work, a perturbation is applied to generate a neighbor solution X n close to the current solution X c . This procedure is detailed in Algorithm 6. Algorithm 6. Perturbation Procedure 1: Parameters (q, X c ) 2: Select two assets i and j randomly 3: If wi ≥ q then 4: wi = wi − q 5: else if wi < q then 6: q = wi 7: wi = 0 8: end if 9: wj = wj + q 10: X n (wi, wj) In line 2, two assets i and j with weights w i and w j are randomly selected. Then, a quantity q is subtracted from asset i in line 4, and the same quantity is added to asset j in line 9. Therefore, the weight of asset i in the portfolio, when the neighbor solution is generated, will be w i − q, and the weight of asset j will be w j + q. This quantity q is obtained by experimentation.

Threshold Accepting for Investment Portfolio Optimization (TAIPO)
Algorithm 7 shows the TAIPO algorithm that shares the same structure as SAIPO. These two algorithms have a temperature cycle and a Metropolis cycle. TAIPO has an additional parameter in line 1: a decreasing tolerance rate δ. As in SAIPO, in the TAIPO algorithm, a perturbation is applied to the current solution to generate a new solution in line 7. However, in this algorithm, if the new solution is worse, the current solution is replaced if the difference does not exceed a certain tolerance (Tol) or threshold (line 9), which decreases by multiplying its previous value by δ in line 17. In the beginning, Tol has a value equal to T k (line 4), which implies that at high temperatures, the new solution will be generally accepted as the current solution. That is, during the processing of 90% of temperatures, Tol has the same value of T k ; in this case, δ is equal to 1. For the remaining temperatures, δ takes the value of 0.96, obtained by experimentation, making the process more restrictive in the last iterations [46].
Generate random initial solution X c = X best 3: s c = f (X n ) = SRneg = s best 4: k = 0; Tol k = T i = T k 5: while T k ≥ T f do 6: while k < L k do 7: X n = Perturbation (X c ); s n = f (X n ) 8: ∆ = s n − s c 9: if ∆ < Tol k then 10: S c = S n ; X c = X n 11: if s c < s best then 12: s best = s c ; X best = X c 13: end if 14: end if 15: k = k + 1 16: end while 17: Tol k+1 = δ * Tol k 18: L k+1 = β * L k 19: T k+1 = α * T k 20: end while 21: SR = −s best 22: return SR, X best 23: end TAIPO In this work, we used the classic TA algorithm and compared its performance with the algorithms proposed. As described in Algorithm 3, TA used a threshold sequence. The procedure shown in Algorithm 8, which is based on the method proposed in [23], was used to generate this sequence. Generate random solution X c 4: X n = Perturbation (X c ) // Generate neighbor solution 5:

and use as Threshold Sequence
In line 1, the size of the sequence is declared, which will be equal to the number of iterations of the TA classic algorithm. In line 3, a random solution is generated, then in line 4, a neighbor solution is generated, applying the perturbation described in Algorithm 6. In line 5, the difference between the new solution and the current solution is calculated. This process is repeated until the given number of iterations is generated. Finally, these differences are ordered from highest to lowest in line 7.

Proposed Algorithms Hybridized with Related Models
The Sharpe Ratio (Equation (24)) is regularly used as the objective function of GENPO, SAIPO, and TAIPO. To compare the performance of the algorithms proposed in this work with the related works described previously, we developed three hybrid algorithms using the last algorithm but replaced the objective function with that used by the reference models of Gilli, Yu, and Masese. These three hybrid algorithms are named: GENPO-X, SAIPO-X, and TAIPO-X, where X is the name of a reference model.

Hybrid Pseudocodes
The SAIPO Hybrid Algorithm shown in Algorithm 9 has a similar structure to the single SAIPO of Algorithm 5. In the beginning, the initial parameters are specified in line 1. Then, the objective function is defined in line 2. There are three alternatives or different models. Used in line 3 is the model presented in [10], the Yu model, shown in Equation (17). On the other hand, to use the Gilli model [21] calculated with Equation (18), it is necessary to compute the penalty p, established with Equation (19). This process is shown in lines 4-8. Finally, the function of the Masese model [22], calculated with Equation (20), is presented in line 10.
After selecting the model, a random feasible solution is generated in line 11. Then, the temperature cycle begins in line 13, and the Metropolis cycle begins in line 14. The Sharpe ratio is calculated at the end of the algorithm (lines [29][30]. The rest of the process and parameters are similar to SAIPO. Generate 1000 random port f olios and compute Generate a random feasible solution X c 12: s c = s best = f (X c ); k = 0; X c = X best ; T k = T i . 13: while T k ≥ T f do 14: while k < L k do 15: X n = Perturbation (X c ); s n = f (X n ) 16: ∆ = s n − s c ; r = random (0,1) 17: if ∆ < 0. then 18: s c = s n ; X c = X n 19: if s c > s best then s best = s c ; X best = X c end if 20: else if r < eˆ(−∆/T k ) then 21: s c = s n ; X c = X n 22: end if 23: k = k + 1 24: end while 25: L k+1 = β * L k ; 26: T k+1 = α * T k 27: end while 28: return s best , X best , SR 31: end SAIPO Hybrid Algorithm Algorithm 10, TAIPO Hybrid Algorithm, is similar to the SAIPO Hybrid Algorithm, changing the new solutions acceptance criterion, as shown in line 16.
Algorithm 11 illustrates the procedure of the GENPO Hybrid Algorithm. As with TAIPO and SAIPO hybrid algorithms, the fitness function is defined in line 4. In line 6, the Yu model is used as presented in [10], computed with Equation (17). On the other hand, the process behind the Gilli model [21] shown in Equations (18) and (19) is described in lines 9-14. Finally, the function of the Masese model [22], shown in Equation (20), is presented in lines 15-17. The remainder of the process is the same as in the GENPO algorithm. Generate 1000 random port f olios and compute σ 2 (R) max ; σ 2 (R) min ; R 6: Generate a random feasible solution X c 12: s c = s best = f (X c ); k = 0; Tol k = T k ; X c = X best ; T k = T i 13: while T k ≥ T f do 14: while k < L k do 15: X n = Perturbation (X c ); s n = f (X n ); ∆ = s n − s c 16: if ∆ < Tol k then s c = s n ; X c = X n 17: if s c < s best then s best = s c ; X best = X c end if 18: end if 19: k = k + 1 20: end while 21: Tol k+1 = δ * Tol k 22: L k+1 = β * L k 23: T k+1 = α * T k 24: end while 25: return s best , X best , SR 28: end TAIPO Hybrid Algorithm Algorithm 11. GENPO Hybrid Algorithm 1: Begin /* GenPO */ 2: Set first gen i = 0 3: Generate initial population (portfolio) P(i) 4: Define objective function f (X) 5: if f (X) = Yu model then 6: end if //Objective function for Yu model 8: else if f (X) = Gilli model then 9: Generate 1000 random port f olios and compute σ 2 (R) max ; σ 2 (R) min ; R 10: if γ > E(R) then 11: Begin /* Produce new generation */ 20: Begin /* Reproductive cycle */ 21 Select two individuals (portfolios), X 1 y X 2 of P(i),

24:
Insertion X h1 y X h2 in P(i) 25: Mutation random τ elements of P(i); 26: Compute fitness function (i) of τ elements, 27: Order individuals best evaluated in P(i).

28:
Limit the population to its original size.

Results
The experiments performed with the algorithms presented in this paper, and the comparison with the hybrid algorithms described previously are shown in this section. To perform analytical tuning for SAIPO and TAIPO algorithms, some previous executions were required. Moreover, we showed the parameters used for those executions in Table 2.

Experiments
To test all algorithms, we used a dataset with 47 stocks taken from the Mexican Stock Exchange. The period evaluated was from 1 January 2017 to 30 June 2018.
In this paper, the performance of the proposed algorithms was compared with the Hybrid Algorithms described in Section 3.5. The MARR or risk-free rate used was 8%. The main metric that we used was the Sharpe Ratio, which allowed measurement of the relationship between expected return and risk. The performance of the algorithms was also measured with other metrics: expected return, risk, average portfolio correlation, and runtime. GENPO algorithm used an initial population of 50 individuals through 100 generations, and used 2 parents with a random selection cross point to generate 2 offspring, then applied an 8% mutation for the entire population. Finally, a stop criterion was implemented in the algorithm after 20 repetitions without improvement. Based on the evaluation, the individuals were ordered from best to worst and the least qualified individuals were eliminated from the population, leaving the population at its original size.
We compared the performance of the algorithms in two circumstances: first by applying the MARR constraint shown in Equation (25), which allowed only assets with an expected return equal to or greater than the MARR to be included in the portfolio; and then without this constraint. The average values of 30 runs are shown in Tables 3 and 4. Note in Table 3, we obtained the best result of the Sharpe Ratio using the algorithms TAIPO, SAIPO, and TA, while the second-best result was achieved by GENPO. When the asset constraint was not applied, the TA-Yu algorithm selected a portfolio with negative SR. This negative value is a consequence of the expected lower return than the MARR (eight percent), which is the acceptable minimum value for accepting a portfolio. In the risk metric, we obtained the best results with the hybrid algorithms SAIPO-Gilli, TAIPO-Gilli, TA-Gilli, and GENPO-Gilli. In terms of expected return, the portfolios obtained with TAIPO, SAIPO, TA, and GENPO, had higher values than the other algorithms. As shown in Tables 3 and 4, TAIPO, SAIPO, and TA algorithms achieved equivalent results in Sharpe Ratio with and without a constraint. However, the SR placed higher than the rest of the algorithms when the MARR constraint was applied.
In Table 4, we observe that the average correlation is higher when the MARR constraint is implemented than when it does not (as in Table 3). However, this difference is lower in TAIPO, SAIPO, and TA. We obtain the best average correlation value with the GENPO algorithm.
When the MARR constraint satisfies the assets, they can conform to the portfolio, and the algorithms may select them. In addition, portfolios with the lowest number of stocks are collected with TAIPO, SAIPO, and TA, which can be advantageous for these algorithms. We can observe that when the MARR is implemented, the runtime is reduced among all algorithms. Although the TA algorithm attains similar results to TAIPO and SAIPO in the Sharpe Ratio, the runtime is higher. Thus, the new TAIPO algorithm proposed in this paper represents a better alternative than the classical Threshold Accepting algorithm. However, SAIPO and TAIPO algorithms require a lower runtime than Genetic algorithms. Table 5 shows the relationship between the result reached in the Sharpe Ratio and the runtime (seconds), that is Sharpe Ratio Runtime , of each algorithm; a higher value represents a better result. When the constraint was applied, the best results were obtained with TAIPO-Gilli and SAIPO-Gilli.
When the constraint was not implemented, we obtained the largest

Sharpe Ratio
Runtime , with the algorithm TA-Gilli. This metric can be used when seeking faster solutions, although faster solutions do not necessarily obtain the best quality results.

Statistical Test
To compare the results, a Friedman test [51] was applied, considering 30 observations, where each algorithm represented a treatment. Tables 6 and 7 show the results applied to the TA, TAIPO, and SAIPO algorithms and their hybrid versions. With a significance value of 5% and a p-value equal to zero, we can conclude that there are significant differences in at least one algorithm. In addition, those that reached the best results were the TAIPO, SAIPO, and TA algorithms, with the higher sum of ranks. In both cases, whether a constraint is applied or not, the TAIPO, SAIPO, and TA algorithms secured the best results in the Sharpe Ratio.
For the algorithms GENPO-Sharpe and its hybrid variants, considering a significance value of 5%, and with a p-value equal to zero, there were significant differences between them. Table 8 shows results for instances without constraint. In the same way, a Friedman test was applied for the instance with constraint, obtaining a p-value equal to zero, showing a statistically significant difference. Results are displayed in Table 9.  Table 10 shows the comparison of the best algorithms when the constraint was not applied. With a p-value of zero, the null hypothesis can be rejected, thus if there are differences between the groups, the TAIPO, SAIPO, and TA algorithms show better performance.  Table 11 shows the results of the Friedman test undertaken to compare the performance of the best algorithms in each group when the MARR constraint was applied. With a p-value of 0.964 and a significance value of 0.05, we can conclude that there are no significant differences.

Conclusions
This paper presents three algorithms for portfolio optimization: GENPO based on Genetic Algorithms, SAIPO based on Simulated Annealing, and TAIPO, which improves upon the classical Threshold Accepting algorithm (TA). We compared them with state-ofthe-art algorithms, namely: Gilli, Yu, and Masese models. This comparison was undertaken by replacing the Sharpe ratio with the objective functions used in these models. The proposed algorithms maximize the Sharpe Ratio (SR) and apply the Minimum Acceptable Rate of Return (MARR) as an essential constraint. Therefore, we present three families of algorithms for portfolio optimization in this paper. For instance, the GA family constituents are GENPO, GENPO-Yu, GENPO-Gilli, and GENPO-Masese.
The proposed algorithms were designed to select the best combination of assets from any stock exchange such as S&P 500 and any other stock market. However, they were only tested with datasets from the Mexican stock exchange (BMV). The optimal result of these algorithms was defined as the proportion of each asset that maximized the objective function.
The experimental results revealed that the proposed algorithms, GENPO, SAIPO, and TAIPO, obtained the highest quality portfolio within each family. Upon application of the MARR constraint, the portfolio with the highest quality was obtained. Moreover, for the same algorithm, when this constraint was included, the execution time was significantly shorter. Regarding the GA family, the proposed GENPO algorithm showed the highest quality in both cases, with and without application of the MARR constraint. Moreover, GENPO did not require excessive tuning time to obtain high-quality portfolios. Similarly, the algorithms SAIPO, TAIPO, and TA showed superior performance with or without the MARR constraint. In addition, they had the lowest average correlation than that of their respective family.
Finally, in the statistical test, where the performance of the proposed algorithms was compared, no significant differences were found when the MARR constraint was applied. However, when the MARR constraint was not applied, SAIPO, TAIPO, and TA obtained a significant difference in quality compared with the GENPO algorithm. The difference was that the TAIPO and SAIPO algorithms converge faster than GENPO and TA algorithms. Therefore, TAIPO and SAIPO represent excellent alternatives for the portfolio integration problem.
The SAIPO and TAIPO algorithms contained more parameters than GENPO; their tuning process was longer and involved a series of previous executions; for this reason, the tuning of these algorithms was more complex than that of GENPO. However, once the appropriate parameters were obtained, the execution time of SAIPO and TAIPO was shorter than the time used by GENPO. However, with TAIPO, unlike SAIPO, for the acceptance criterion of new solutions, the calculation of probabilities was not required, which rendered the execution time of TAIPO slightly lower than SAIPO.
For future research, we propose an application of these algorithms to larger stock markets, including other objective functions and metrics. Finally, we propose the application and extension of these algorithms with other heuristics for design portfolios among several markets. Moreover, the applicability of these algorithms regarding derivatives and other stocks remains a problem that should be studied.  Data Availability Statement: In this section, Data supporting are located in this paper.

Acknowledgments:
The authors thank Conacyt for the scholarship for graduate studies that let us become researchers and/or full professors.

Conflicts of Interest:
The authors declare no conflict of interest.