# Stock Portfolio Management in the Presence of Downtends Using Computational Intelligence
## 4 Methods and Materials
### Evolutionary Algorithms to Select Stocks  
It is common that practitioners use indicators from the so-called fundamental analysis to assess the financial health of stocks. Besides these indicators, here, we use the stock prices and tendencies forecasted by the ANN to define which stocks should be further considered for investment. To ponder all these values, we establish an optimization problem following the recommendations in ([78]) and use an evolutionary algorithm to address it as recommended in ([10]). Let \(S=\{s_{1},s_{2},\ldots,card(S)\}\) be the set of considered stocks, \(v_{j}(s_{i})\) be the evaluation of stock \(s_{i}\) on the \(j\)th indicator, \(j=1,\ldots,N\) (for the sake of simplicity, assume that \(v_{1}\) is the forecasted return as calculated by Equation (1)), and \(w_{i}\) be the relative importance of each indicator and forecasted return (the latter is denoted by \(w_{1}\)). The score of stock \(s_{i}\) can be calculated as follows (cf. [10,79]):  
\[score(s_{i})=\sum_{j=1}^{N}w_{j}v_{j}(s_{i}) \tag{2}\]  
Since increasing \(v_{j}(s_{i})\) for \(j=1,\ldots,N\) indicates the convenience of the stock, determining the most appropriate values for \(w_{j}\) becomes crucial to determining the most plausible stocks as those that maximize Equation (2). If we want to take advantage of market downtrends, sometimes we will be interested in obtaining the more negative returns to invest in a short position. To implement this idea, the value of each factor \(v_{j}\) is taken as positive or negative according to the prediction given by the ANN model on the previous stage. Namely, if the ANN model predicts a positive stock return, a long position will be chosen for this stock and the factor values are taken as they are. However, if the ANN model predicts a negative stock return, a short position is chosen for this stock and the return and each factor value are multiplied by \(-1\), so Equation (2) is still valid. To determine the most convenient values for \(w_{j}\) (\(j=1,\ldots,N\)), we use the function recommended in ([78]). Let us define this function. For a given historical period \(t\), a set of predefined weights will allow one to determine the score of each stock; thus, the top, say, 5% of the stocks can be selected. These top stocks constitute the set of \"selected\" stocks, and the rest constitute the set of \"non-selected\" stocks for period \(t\). Let \(R^{t}_{selected}\) and \(R^{t}_{non-selected}\) be the average returns of the stocks in these sets (as calculated by Equation (1)), respectively. The convenience of the predefined weights is then calculated as the arithmetic difference between the average returns of the selected and non-selected stocks that they produce, that is:  
\[\text{Maximize}\;\xi(W)=\frac{1}{T}\sum_{t=1}^{T}(R^{t}_{selected}-R^{t}_{non -selected}) \tag{3}\]where \(T\) is the number of historical returns used to assess the weights in \(W\), \(W=[w_{1},w_{2},\ldots,w_{N}]^{\top}\) and \(\xi(W)\) is the convenience of the weights in \(W\). As was stated in Section 2.4, the differential evolution (DE) algorithm has been found to be highly effective in non-linear mono-objective optimization problems, especially in problems related to financial problems ([11; 23; 24]); therefore, this type of algorithm represents serious advantages over other optimization algorithms, particularly over other meta-heuristics. We use here a basic version of the DE algorithm as presented by Algoritm 1 in ([80]). Let us describe this algorithm. To determine the best values for \(w_{j}\) (\(i=1,\ldots,N\)), the decision variables considered by the DE will be the values \(w_{j}\) such that each individual in the DE will contain the values for \(w_{j}\) fulfilling the constraints of the problem: \(w_{j}\geq 0\) and \(\sum_{i=1}^{N}w_{j}=1\). Lines 1-8 of Algorithm 1 randomly initialize the population of the DE; that is, the lines initialize feasible individuals by placing them in a random position within the search space.