# An Approach to Aid Decision-Making by Solving Complex Optimization Problems Using SQL Queries
## 2 Materials and Methods
### The Portfolio Selection Problem  
An investment portfolio is a set of instruments listed on the stock market in which a person or company decides to invest. It is composed of fixed- and variable-income securities; the idea is to reduce the risk by combining different instruments such as stocks, bonds, real estate, and money market accounts. The PSP involves the selection of an investment portfolio through which it is possible to achieve a given rate of return and minimize the risk at the same time. According to [PERSON] [17], the process to select a portfolio consists of two stages: (1) the first stage begins with observation and experience and ends with expectations of the future behavior of securities, and (2) the second stage starts with the expectations and ends with the selection of the portfolio. The PSP is an optimization problem in which the goal is to maximize the predicted profit. As a result, the solution to the PSP is contingent on a collection of securities and an investment quantity \(\mathcal{Q}\). The optimal size of the investment portfolio, the selection of securities in which it must be invested, and the quantity to be put in each security are all part of a solution to the problem. Equation (1) formally defines the PSP. The problem uses a vector \(e=\{e_{1},e_{2},\cdots,e_{K}\}\) to optimize the distribution of an investment quantity \(\mathcal{Q}\). Each element \(e_{i}\in e\) is associated with the \(i\)th security from the set \(S=\{s_{1},s_{2},\cdots,s_{K}\}\) and takes a value \(j\), which represents a quantity \(q_{j}\) from the set \(\mathcal{I}=\{q_{1},q_{2},\cdots,q_{N}\}\) of investors' wealth portions. The matrix \(\beta_{N\times K}\) contains cells \(\beta_{i,j}\) with the expected return of the securities \(s_{j}\) given an investment \(q_{i}\). Let us note that \(N=|\mathcal{I}|\), \(K=|\mathcal{S}|\). \[ \begin{array}{l}\text{\it Maximize}\qquad f(e,\mathcal{I},\beta,\mathcal{ Q})=\sum_{j=1}^{K}\beta_{e_{j},j}\\ \text{\it subject to}\\ \sum_{j=1}^{K}q_{e_{j}}=\mathcal{Q}\\ \quad e_{j}=i|q_{i}\in\mathcal{I}\end{array}  \tag{1}\]  
The \(\beta\) matrix specifies the expected return given an amount to invest and the specific security in which to invest. In the first column, the set \(\mathcal{I}\) is shown, which represents the different choices of proportions, in ascending order, that the investor has chosen. The other columns represent the \(S\) set, one column for each additional security. In cell \(\beta_{i,j}\in\beta\), the return of investing the percentage \(q_{i}\in\mathcal{I}\) on security \(s_{j}\in S\) is found. The index \(i\) of the proportion \(q_{i}\in\mathcal{I}\) that must be invested in security \(s_{j}\in S\) to maximize Equation (1) corresponds to the value for each element \(e_{j}\in e\). The proportion \(q_{1}\) of the first row of the matrix \(\beta\) must be 0 to allow for the possibility that a security does not belong to a portfolio. The set \(\mathcal{I}\) is formed by dividing the quantity to be invested \(\mathcal{Q}\) among the \(N\) different proportions. Equation (2) shows the procedure for obtaining \(q_{i}\) where \(2\leq i\leq N\). \[q_{i}=(i-1)*\frac{\mathcal{Q}}{N-1} \tag{2}\]  
In summary, an instance of the PSP is established with the tuple \((S,\mathcal{I},\beta,\mathcal{Q})\), i.e., a set of securities \(S\), a set \(\mathcal{I}=\{q_{1},q_{2},\cdots,q_{N}\}\) of investors' wealth portions, a matrix \(\beta_{N\times K}\) of expected securities' returns, and the amount of investment \(\mathcal{Q}\). Table 1 shows an instance of the PSP, where \(\mathcal{Q}=200\), \(N=11\), \(\mathcal{I}=\{0,20,40,60,80,100,120,140,160,180,200\}\), \(K=5\), and \(S=\{s_{1},s_{2},s_{3},s_{4},s_{5}\}\). The expected returns are established for each pair \((q_{i},s_{j})\); a row filled with zeros was added so that the size of the portfolio is not restricted. [PERSON] et al.