1 Introduction

The problem of optimizing a stock portfolio consists in finding the best arrangement of weights that maximize the expected return and minimize risk. One of the most used approaches is genetic algorithms due to their proven effectiveness in solving complex search problems [4]. This optimization problem can be modeled as a multi-objective problem (maximizing return and minimizing risk) with constraints to make it more realistic, such as cardinality constraints (limiting the maximum amount of assets that can make up the portfolio), penalty systems and transaction costs [3, 7]. The addition of these mechanisms makes optimization models more complex and challenging computationally [1]. In [11], Evolutionary algorithms were used with cardinality, border and entire batch constraints to select portfolios, however the memetic version did not bring significant improvements.

The Sharpe Ratio is a popular measure to evaluate portfolios, maximizing the risk-return ratio. This measure is an alternative that can be used instead of modeling the problem as multi-objective problem (maximizing return and minimizing risk). In the financial literature, genetic algorithms have been proposed to maximize the Sharpe Ratio [1, 8], however, in general, it has not received much attention in the past, perhaps due to the extremely heavy load on the calculations [5]. In [2], a Markowitz medium-variance portfolio selection model was proposed that groups assets by economic sectors, but without cardinality constraints (i.e., there is no limit on the number of assets within the portfolio) associated with the optimization made by genetic algorithms. However, there is a lack of works in the literature that bring all these factors together.

Therefore, the objective of this work is to propose an algorithm that (i) selects assets in a completely independent way (without human supervision), containing asset allocation mechanisms that take into account the economic sector to reduce volatility, and (ii) maximizes the portfolio’s Shape Ratio via genetic memetic algorithm, using cardinality restrictions and containing a penalty mechanism for weight distributions to make it more realistic. As a case study, the stock portfolio of B3 companies is used, aiming to outperform the Bovespa index in the long term. The proposed algorithm, first groups the B3 companies to form clusters, from which assets are chosen for the final portfolio, assigning weights via genetic memetic algorithm. Among the possible ways used by the proposed algorithm to group the B3 companies are (i) to use clusters that B3 itself makes available online, in which each cluster represents a subsector of the economy; and (ii) to use the K Means DTW [9] technique of clustering, which is used to calculate a measure of distance between two time series that are not aligned.

2 Theoretical Background

The asset allocation algorithm proposed in this study uses three main theories: the Sharpe Ratio [10], the Markowitz asset diversification theory [6] and the Capital Asset Pricing Model (CAPM). These theories are detailed in this section. Finally, in Sect. 2.6, the K-Means algorithm with the DTW distance is described, which will be used in this work to create groups of assets.

2.1 Sharpe Ratio

The Sharpe Ratio [10] is widely used to evaluate assets or portfolios, measuring the risk-return ratio in comparison to the risk-free return:

$$\begin{aligned} Sharpe Ratio=(R_p - R_f)/\sigma _p \end{aligned}$$
(1)

where \(R_p\) is the expected return of the asset or portfolio, \(R_f\) is the risk-free return, (for example, the Selic Rate in Brazil) and \(\sigma _p\) is the volatility of the asset or portfolio.

2.2 Calculation of Expected Return and Risk (Volatility) of an Asset

The expected daily return \(R_p\) of an asset is the average of the daily returns observed over a period:

$$\begin{aligned} R_p= \frac{\sum _{i=1}^{n} r_i}{n} \end{aligned}$$
(2)

where \(r_i\) is the daily return on the day i and n are the numbers of days. The risk or volatility \(\sigma _p\) is the standard deviation of the historical returns:

$$\begin{aligned} \sigma _p = \sqrt{\frac{\sum _{i=1}^{n} (r_i - R_p)^2}{n}} \end{aligned}$$
(3)

In this work, the daily logarithmic return is used, defined as the natural logarithm of the ratio between the current price (\(a_i\)) and the previous day’s price (\(a_{i-1}\)):

$$\begin{aligned} {r_{i}}= \ln {\frac{a_i}{a_{i-1}}} \end{aligned}$$
(4)

These calculations are used to determine the expected return and the risk/volatility of each candidate asset to make up the final portfolio.

2.3 Calculation of Expected Return and Portfolio Risk (Volatility)

The calculation of the expected return of a portfolio, according to Markowitz, is the weighted sum of the expected returns of the assets that compose it. For a portfolio with n assets, with expected returns \(R_1\), \(R_2\), ..., \(R_n\) and weights \(x_1\), \(x_2\), ..., \(x_n\) respectively, the expected return \(R_p\) is given by:

$$\begin{aligned} R_p=\sum _{i=1}^{n} x_iR_i \end{aligned}$$
(5)

Markowitz defined a portfolio’s risk as its variance, which includes the individual asset variances weighted by the squares of their weights, plus twice the sum of the covariances between all pairs of assets, weighted by the product of their weights. For a portfolio with two assets a and b, with weights \(w_a\) and \(w_b\), the risk is given by:

$$\begin{aligned} \sigma ^2_p = w^2_a\sigma ^2_a + w^2_b\sigma ^2_b + 2w_aw_b\sigma _{a,b} \end{aligned}$$
(6)

Generalizing for a portfolio with n assets:

$$\begin{aligned} \sigma ^2_p = \sum _{i=1}^{n}\sum _{j=1}^{n} w_iw_j\sigma _{i,j} \end{aligned}$$
(7)

where \(\sigma _{i,j}\) is the covariance between the returns on assets \(a_i\) and \(a_j\).

2.4 Asset Diversification

Markowitz’s diversification theory states that adding new assets to a portfolio reduces the total risk due to covariance between assets [6]. As more assets are added, the risk decreases until it reaches an asymptote, where adding new assets no longer reduces risk. This reduction occurs mainly due to the negative covariance between assets. Markowitz’s risk formula demonstrates that the risk of a portfolio can be reduced with assets that have low covariance with each other. However, there is a limit to this reduction, called Unsystematic risk, specific to the characteristics of companies or sectors. Systemic risk, such as political crises and pandemics, cannot be reduced by diversification.

This work proposes the use of two clustering ways and evaluates which one best separates companies into groups with lower covariance, aiming to reduce Unsystematic risk.

2.5 Capital Asset Pricing Model (CAPM) Theory

The Capital Asset Pricing Model (CAPM), proposed by Sharpe (1964), Lintner (1965) and Mossin (1966), calculates the expected return of an investment based on its risk compared to the market (IBOVESPA). The CAPM formula is:

$$\begin{aligned} E(R_i) = R_f + \beta _i(R_m - R_f) \end{aligned}$$
(8)

where \(E(R_i)\) is the expected return on the investment, \(R_f\) is the risk-free return (Selic rate), \(\beta _i\) is the correlation of the asset’s risk with the market risk (Bovespa index) and \(R_m\) is the expected market return (Bovespa index).

2.6 K-Means Algorithm for Time Series and DTW Distance Between Time Series

K-Means algorithm for time series groups them based on their format. The process begins with randomly selecting k time series as centroids, then calculating the distance between each time series and the centroids, and continually adjusting the centroids until they represent the center of mass of the clusters. The algorithm is run several times to improve representativeness. To calculate the distance between time series, they must all have the same size and be normalized. A similarity metric that can be used is Dynamic Time Warping (DTW), which is more suitable than Euclidean distance for time series with time-shifted correlations [9]. DTW is used to measure the similarity between two time sequences that do not exactly align in time, allowing one time series to be stretched or compressed to better match another time series, offering an advantage over traditional methods such as Euclidean distance.

3 Modeling the Portfolio Weight Assignment Problem Using Memetic Genetic Algorithms

Genetic Algorithms (GAs) constitute a search and optimization technique, inspired by the Darwinian principle of natural selection and genetic reproduction, in which the fittest individuals have a greater chance of reproducing. In the proposed modeling, a chromosome represents a portfolio of assets, and the weights of each asset are the genes. Chromosomes are then subjected to an evolutionary process that involves the steps of evaluation using a Fitness function, selection, sexual recombination (crossing-over) and mutation. After several cycles of evolution, the population should contain fitter individuals. Below, each of these mechanisms that make up the genetic algorithms for the case study is described.

3.1 Fitness Function

The fitness function is the function that will evaluate how well-adapted each individual in the population is in relation to the objective they want to achieve. In this study, the objective is to maximize the portfolio’s Sharpe Ratio, therefore, the input to the Fitness function is a portfolio (an individual) from the population and the output is its respective Sharpe Ratio, which can be calculated by Eq. 1. The proposed GA has a penalty system, this mechanism is implemented within the Fitness function and is described below.

Penalty Mechanism. A penalty system is used to leave the final output of the GA (portfolio closest to the global maximum) with a more realistic weight distribution. Unrealistic weight distributions will be penalized in such a way that their Sharpe Ratio value will be decreased on purpose, thus this individual will have less chance of continuing to the next generation. Portfolios with excessively high or low weights in certain assets are considered unrealistic solutions. The allocation of 20% or more in a single asset is rarely seen in the real world, as it is very risky. The same solutions often allocated excessively low weights to some assets in such a way that their variation (high or low) had no impact on the total variation of the portfolio. For this reason, solutions that allocated very low weights (less than 0.5%) to assets were also penalized.

3.2 Selection Algorithm

The selection algorithm is divided into two parts: elitist selection and window selection. Elitist selection ensures that the fittest individuals are retained for the next generation, while window selection chooses portfolios randomly within a window that decreases throughout interactions. In this way, the fittest individuals will have a greater chance of being chosen because they are within the selection window more often, while the less fit individuals will have less chance of being chosen because they will be within the window less often.

3.3 Crossing-Over and Mutation Algorithm

Position Based Crossover (PBX) algorithm was used as crossing-over algorithm.

Firstly, PBX randomly selects 40% of the parents’ genes. Child 1 receives the randomly selected genes from parent 2, that is, child 1 already has 40% of the genes completed, the other 60% comes from parent 1 completing 100%. Similarly, child 2 receives randomly selected genes from parent 1 and the other 60% comes from parent 2. Figure 1 shows an example. After the PBX function completes and generates 2 new individuals (children), the weights of the new portfolio must be adjusted so that the sum of all weights is always equal to 1.

Fig. 1.
figure 1

Position Based Crossover (PBX)

3.4 Mutation Algorithm

Aiming to generate genetic variability and consequently increase the chance of leaving local maxima, three mutation functions are used:

  • Order Based Mutation: The element in position i is exchanged with the element in position j.

  • Position Based Mutation: The element in position i is removed and inserted into position j.

  • Scramble Mutation: A randomly selected sublist is shuffled.

3.5 Local Search for Nearest Neighbors (Memetic Step)

Memetic step of the algorithm involves a local search for the nearest neighbors, generating new individuals similar to those selected, and increasing genetic variability. This search involves small adjustments to the weights of the assets and normalization so that the sum of the weights is equal to 1. A nearest neighbor of a solution is a solution that contains 1% more in 2 weights.

4 Proposed Asset Allocation Algorithm

This section will detail how the asset allocation algorithm works. The proposed algorithm will select between 6 and 25 companies among 462 companies, which are all companies listed on B3 on 10/1/2023. The range between 6 and 25 assets was defined by the following reasons:

  • This is the range seen in most Brazilian stock portfolios managed by stock funds.

  • The smaller the number of assets within the portfolio, the greater the risk will be, and the greater the number of assets that make up the portfolio, the tendency is for the risk to decrease.

  • Limiting the maximum value to 25 is due to 2 factors: firstly, managing a portfolio with more than 25 assets is quite costly, and secondly, a value above that can dilute the profitability obtained, because as the number of assets increases, the tendency is for the weight allocated to each asset to decrease together.

  • Limiting the minimum value to 6 assets is due to the fact that, if a portfolio has only 5 assets or less, it is guaranteed that at least one of the assets will have 20% of the entire weight; this greatly increases the portfolio risk (the penalty mechanism proposed in Sect. 3.1 will attempt to handle this scenario in the cases where the number of assets is greater than 6).

In short, the proposed algorithm first obtains the clusters of companies and then selects an asset from each cluster of companies by analyzing the Sharpe Ratio to obtain the final portfolio. The memetic genetic algorithm is applied to this portfolio several times to obtain the weights in the end. These steps are described below.

4.1 Get Company Clusters

To reduce Unsystematic risk (risk related to the company or sector), the asset allocation algorithm first obtains clusters of companies and selects only one asset from each existing cluster. Selecting companies that belong to different clusters tends to select assets in which the correlation between them is low. Selecting assets that have low correlation tends to reduce the risk of the entire portfolio as the number of assets within the portfolio increases and the correlations between them are weak. To this end, the method for calculating the risk of a stock portfolio proposed by Markowitz (1952) [6] is followed, in which the risk of a set of assets (a portfolio) is a function that takes into account the covariances between assets, calculated two by two. Therefore, this work proposes to design two asset allocation algorithms in which the only difference between them will be the technique used to generate these clusters.

The first algorithm which will be referred to as the Model B3, uses the clusters that B3 itself makes available online, in which each cluster represents a subsector of the economy. The B3 cluster is a grouping of all companies listed on the Brazilian stock exchange, which divides all 463 companies present (as of November 1, 2023) into 41 different economic sectors such as Agriculture, Electricity, Mining, Telecommunications, and others.

The second algorithm uses the K-Means DTW clustering technique, which is used to calculate a distance measure between two times series that are not aligned. This algorithm will be referred to hereafter as the K-Means DTW Model.

After the cluster creation step, both algorithms will follow the same subsequent steps, which are the selection of an asset from each existing cluster (described in Sect. 4.2), the creation of the final portfolio (Sect. 4.3) and obtaining weights from the final portfolio using genetic algorithm (Sect. 4.4).

4.2 Selection of an Asset from Each Company Cluster

When selecting an asset from each cluster, the following criteria are used:

  1. 1.

    The asset must have the highest individual Sharpe ratio within the respective cluster and this Sharpe ratio must be greater than zero.

  2. 2.

    The individual asset Sharpe ratio must surpass the Ibovespa Sharpe, which is the main benchmark.

  3. 3.

    The asset must have a return greater than the expected return calculated by CAPM formula.

    • As previously defined, if the minimum acceptable amount returned according to the CAPM formula is lower than the Selic rate for the training period, the amount returned by the formula will be the Selic annual return rate itself. In other words, we are defining that the algorithm will not accept assets that have an expected return lower than the safe return for the same period.

  4. 4.

    The asset must exist in full throughout the entire training period.

The asset can only be chosen if it simultaneously meets the four requirements above. If no asset within the cluster meets all four at the same time, no asset will be chosen within the respective cluster. This implies the possibility that the number of assets selected to compose the stock portfolio will not necessarily be the same as the number of clusters created by clustering techniques.

4.3 Creation of the Final Portfolio

After the stage of selecting an asset from each cluster of companies, a list of candidate companies to make up the final portfolio is generated. This list of assets is organized in descending order by the individual Sharpe ratio, and is inserted in order, one by one, in the final portfolio. In other words, the assets with the highest individual Sharpe ratios will be added to the final portfolio first. Insertion will only be allowed if it meets the following criteria:

  1. 1.

    The insertion of the candidate asset must reduce the total risk/volatility of the portfolio, that is, it must respect the asset diversification proposed by Markowitz [6]. If the asset does not meet the first condition, in other words, if the inclusion of the candidate asset increases the total risk of the portfolio, it will only be accepted if the Sharpe ratio of the portfolio as a whole increases. In this scenario, what generally happens is that the portfolio’s risk increases, but the portfolio’s expected return increases even more, that is, the percentage increase in expected return is greater than the percentage increase in risk.

  2. 2.

    The insertion of the asset is only allowed if the portfolio’s expected return is greater than the minimum acceptable return calculated by the CAPM formula. In other words, if, when inserting the asset, it reduces the expected return of the portfolio in such a way that it is below or at the minimum acceptable (according to CAPM theory) it will not be selected.

It is worth highlighting that the calculation of the portfolio’s return and risk will be made considering that the assets have homogeneous weights within the portfolio. If the candidate asset does not fit into any of the two situations above, it will not be chosen to make up the final portfolio. After this step, we will have a portfolio with several assets and it will go through a simple pruning/cutting mechanism, to maintain the defined number of 6–25 assets. If the number of assets is less than 6, the algorithm discards the portfolio and does not return any portfolio recommendations, if the number of assets is less than or equal to 25, the algorithm returns the portfolio recommended to the user, and if the number of assets exceeds 25, the assets with the lowest individual Sharpe are removed until the maximum quantity of 25 is reached.

4.4 Obtaining Final Portfolio Weights Using Genetic Algorithm

On the portfolio assembled in the previous step, the memetic genetic algorithm is applied to obtain the best possible configuration of weights within the portfolio which returns the highest Sharpe Ratio. After the stage of maximizing the Sharpe Ratio via genetic algorithm, we have the final portfolio, the assets and their respective weights. Finally, the performance of the final portfolio is calculated, that is, the return obtained one year after the training period is calculated.

4.5 Asset Allocation Algorithm Pseudocode

The AssetAllocation algorithm (Algorithm 1) shows the complete pseudocode of the proposed asset allocation algorithm. This algorithm receives a set of companies, the clustering that will be used (which can be K-Means or B3), the training year and the number of weight vectors that will be used to calculate the final weight vector. After obtaining the clusters (lines 2–6), the SelectCompaniesFromClusters method is applied, performing the procedure of selecting an asset from each cluster of companies (described in Sect. 4.2), and creating the final portfolio (described in Sect. 4.3), then returning the final portfolio (line 7). As this step involves analyzing the Sharpe Ratio, it is necessary to define a training time interval. On the final portfolio, the memetic genetic algorithm is applied several times (specifically quantity_vec_weights times), and in each call to the genetic algorithm, a possible configuration (the one that returns the highest Sharpe Ratio) of weights is obtained (lines 8 to 10). In line 11, these various weights settings found are averaged to obtain the final weights. Finally, the performance of the final portfolio is calculated, which means that the return obtained one year after the training period is calculated (line 12).

5 Results

This section presents the results obtained using the K-Means DTW model and the B3 model (model that uses clustering by economic sectors). For both models, a training period of 1 year was used, that is, to generate the portfolio for year n, year \(n-1\) was used for training. In the experiments, the income of the portfolios generated by the two proposed asset allocation models is compared with (i) the annual income of the Bovespa index, both annual and accumulated (Sect. 5.2); and (ii) the accumulated income of the 20 best investment funds in multimarket assets of B3 companies, to analyze whether the portfolio generated by the algorithm is competitive with other portfolios (funds) on the market (Sect. 5.3).

Before discussing the results achieved (portfolios generated and their incomes), the results of K-Means DTW clustering technique are initially presented.

Algorithm 1
figure a

AssetAllocation function

5.1 K-Means DTW Clustering

To perform the clustering, the Tslearn library was used, being a Python package that provides machine learning tools for time series analysis. From the Tslearn library, the (untrained) model Clustering.TimeSeriesKMeans was imported, which is the model that receives 4 inputs: (i) k which is the number of centroids, (ii) n which is the number of times that K-Means algorithm will be executed with different centroid seeds (the final results will be the best result of n executions), n = 2 was used in the experiments, (iii) the metric that will be used to calculate the distance between two time series, DTW was used in the experiments, (iv) the number of iterations for the process of calculating the barycenter of each of the k clusters, 10 iterations were used in the experiments, and (v) the random state field, which is the generator used to start the first centroids.

In the experiments, to compare the different time series, they were standardized so that they were all on the same amplitude scale. To find the best value of k (number of clusters/centroids), the Elbow Method was used. The Elbow Method is based on the idea that as you increase the number of clusters, the variation within each cluster decreases, but at some point the improvement becomes insignificant. This point, on a graph, is what is called an Elbow and indicates the ideal number of clusters for your data. The Sum of Squared Distances (SSD) was used as the criterion for evaluating variation within each cluster.

Each of the seven portfolios (one portfolio per year) used 4 years in the past to create their clusters. For example, a 2019 portfolio used time series data from Jan/2015 to Dec/2018. The 4-year interval was reached after realizing that portfolios that used clusters generated by shorter intervals ended up generating very unbalanced clusters (many companies concentrated in a few clusters and many clusters with few companies). Very unbalanced clusters ended up generating portfolios with five or fewer assets, which goes against the selection mechanism described in Sect. 4. Using 4 years had consequences on the number of companies analyzed in each year, as the K-Means DTW time series clustering algorithm, for its proper functioning, requires that all companies exist in those 4 years (i.e., the time series must exist entirely in this interval). For example, to generate the 2019 cluster, only companies that have been on the stock exchange at least since 01/01/2015 were used. Companies that entered the stock market after that date were ignored to generate the 2019 clusters.

In Table 1, there are the numbers of clusters per year obtained by the K-Means DTW algorithm, that is, the optimal value for k found using the Elbow Method and the number of companies distributed in the k clusters per year.

Table 1. Number of clusters and number of companies distributed in the k cluster per year obtained by the K-Means DTW algorithm

5.2 Results of B3 and K-Means DTW Models

Table 2 shows the monthly incomes of the B3, K-Means DTW and Bovespa index models, along with the annual and historical accumulated incomes. We can see that both the B3 and K-Means DTW models had a much higher accumulated income (in the long term) than Bovespa. The accumulated incomes are 310,86%, 453,65% and 119,01%, respectively. Both the B3 and K-Means DTW models also proved to be safer than Bovespa. They do not have a negative income during this period in any year, while Bovespa showed a drop of −11,59% in 2021.

Table 2. Monthly, annual and accumulated incomes; and annual risk of the B3, K-Means DTW and Bovespa index models from 2017 to 2023.

Figure 2 shows the evolution of the accumulated income of the B3 and K-Means DTW models compared to Bovespa. It can be noted that the annual evolution of the portfolios generally has the same shape as the Bovespa index (they vary together), and, in most cases, the proposed models have a higher income.

Fig. 2.
figure 2

Evolution of the accumulated income of the B3 and K-Means DTW models compared with Bovespa.

The year with the highest income, 2019, obtained by the K-Means DTW model, with an income of 85,56% is analyzed. Figure 3 (left) shows the evolution of the risk of the portfolio from 1 to 15 assets (the assets have ids from 0 to 14). The final portfolio has 15 assets for this year. Figure 3 (right) shows the evolution of the Shape Ratio of the best portfolio for 2019 (better distribution of weights that maximizes the Sharpe Ratio) found by the genetic algorithm in each generation. Finally, Fig. 3 shows the evolution of the accumulated monthly income of the respective portfolio compared to the Bovespa index (Fig. 4).

Fig. 3.
figure 3

Evolution of risk (left) and evolution of Sharpe ratio (right) of the 2019 portfolio obtained by the K-Means DTW model.

Fig. 4.
figure 4

Accumulated monthly income of the 2019 portfolio obtained by the K-Means DTW model.

Three points are worth highlighting: (i) for most portfolios, an evolutionary asymptote was reached, close to generation 35 of the genetic algorithm; (ii) the evolution of the risk of the 2019 portfolio showed an increase when the fifth asset was added, going from a risk of 19% to 33%, and this was only accepted (increase in risk) because the increase in the portfolio’s expected return was even greater, going from an expected return of 91% to an expected return of 165%; and (iii) at the end of 2019, there was a dizzying increase in income, which can be explained by the significant appreciation of EUCA3, LOGN3 and BRGE8 assets. EUCA3 assets went from an initial value of R$8.24 in Jan/2019 to R$55.70 at the end of Dec/2019. LOGN3 assets went from an initial value of R$8.13 in Jan/2019 to R$20.90 at the end of Dec/2019. Similarly, BRGE8 assets went from an initial value of R$3.22 in Jan/2019 to R$9.37 at the end of Dec/2019.

Table 3. Stock Funds

5.3 Proposed Models Compared to the Market

In this section, the performances of the two proposed models with real stock funds are compared. The following criteria were used to select the funds: (i) the fund must be composed integrally or mainly of assets; (ii) all assets must be from Brazilian assets; and (iii) the fund must exist within the entire analyzed period, from 01/01/2017 to 12/31/2023. Among the funds that meet the three requirements, the 20 funds with the highest accumulated incomes over that period were selected. Table 3 shows these funds and what would be the relative position of the two models proposed in this study, taking into account their accumulated incomes over the same period.

Table 3 shows that both models achieved excellent positions within the top 20 funds with the highest incomes. K-Means DTW model was in ninth place and B3 model was in twentieth place. The fund incomes data was obtained from the Mais Retorno website, which is a website that compares and ranks the best investment funds per year. On the website, it is possible to make the cut within the desired period (2017–2023) and obtain the income of each fund within that period.

6 Conclusion

Based on the results presented, it can be concluded that both models in the long term are extremely competitive with the current stock funds present in the Brazilian financial market. In other words, the algorithm’s main selection strategy, which is the selection of the most promising asset (an asset that presents the highest Sharpe ratio) from each cluster of companies, proved to be promising for both models. As observed in the Results section, the K-Means DTW model proved to be more profitable than the B3 model, since the K-Means DTW model presented an accumulated income of 453,65% and B3 model had an accumulated income of 310,86%. Additionally, both models performed well in pandemic years (crisis years). B3 model had an income of 33,9% and 26,05% and DTW model had an income of 26,04% and 10,5%, in 2020 and 2021, respectively. It is worth noting that the total income in both models may be even higher, since, in this study, the income received as dividends was not taken into account.