*2.1. Building Blocks of Portfolio Selection*

Here, we will discuss the building blocks of portfolio selection, i.e., expected return (profit), risk, total investment, total transaction cost, and cardinality constraint.

#### 2.1.1. Expected Return

The primary factor in portfolio optimization is the maximization of expected return: in other words, the profit that investors are expecting from their investment in stocks. Let us say there are *K* total stocks and the normalized investment in all *K* stocks is given as *E* = [*E*1, *E*2, *E*3, . . . , *E<sup>i</sup>* , . . . *<sup>E</sup>K*] <sup>∈</sup> <sup>R</sup>*K*, where *<sup>i</sup>* is the *<sup>i</sup>*-th stock and *<sup>E</sup><sup>i</sup>* is the the normalized investment in the *i*-th stock. Now, let us say that the mean return of *K* stocks based on their past data is given as, *e* = [*e*1, *e*2, *e*3, . . . , *e<sup>i</sup>* , . . . , *eK*] *<sup>T</sup>* <sup>∈</sup> <sup>R</sup>*K*. The objective is to find the optimal *E* such that it maximizes the expected return, which is given as

$$\max\_{\mathbf{E}} \xi(\mathbf{E}) = \mathbf{E} \mathbf{e}^T. \tag{1}$$

To further consolidate (1) and to ensure that the expected return is above a certain threshold *k*, the modification to (1) is given as,

$$\max\_{E} \zeta(E) = E\mathbf{e}^{T} - k \ge 0. \tag{2}$$

here, *k* is a scalar quantity and *Ee <sup>T</sup>* <sup>−</sup> *<sup>k</sup>* <sup>=</sup> 0 means the break-even point (no profit-loss).

#### 2.1.2. Risk

The maximization of profit (expected return) does not avoid the risk factor. The second objective is to minimize the risk. The risk minimization is given as,

$$\min\_{\mathbf{E}} \upsilon(\mathbf{E}) = \mathbf{E} \mathbf{Q} \mathbf{E}^T,\tag{3}$$

where *Q* is a covariance matrix, and it is given as,

$$\mathbf{Q} = \begin{bmatrix} Q\_{11} & Q\_{12} & Q\_{13} & \dots & Q\_{1j} \\ Q\_{21} & Q\_{22} & Q\_{23} & \dots & Q\_{2j} \\ Q\_{31} & Q\_{32} & Q\_{33} & \dots & Q\_{3j} \\ \vdots & \vdots & \vdots & \vdots & \dots & \vdots \\ Q\_{i1} & Q\_{i2} & Q\_{i3} & \dots & Q\_{ij} \end{bmatrix} \tag{4}$$

where *Qij* is the variance of the *i*-th stock with *j*-th stock in the portfolio.

#### 2.1.3. Total Investment

Now, we will discuss one of the primary constraints: total investment. It ensures the allocation of the total asset in the stocks, and it is given as,

$$\mathbf{1}\mathbf{E}^T = \mathbf{1},\tag{5}$$

where **1** is a unit vector. As mentioned above, *E T* is a normalized investment, so the sum of the amount invested in the portfolio should be 1 as shown in (5). To ensure this, we need an additional constraint which is given as,

$$\mathbf{0} \le \mathbf{E} \le \mathbf{1}.\tag{6}$$

It will ensure that *E* remains positive and within [0, 1].

#### 2.1.4. Total Transaction Cost

The total transaction cost is another essential constraint in portfolio selection. The transaction cost is positive if the investor buys stock and is negative if the investor sells stock. Let us say that Φ(*E*) represents the transaction cost of the portfolio; it is given as,

$$\Phi(E) = [\Phi\_1(E\_1), \Phi\_2(E\_2), \Phi\_3(E\_3), \dots, \Phi\_i(E\_i)],\tag{7}$$

where *i* ∈ {1, 2, 3, . . . , *K*} and Φ*i*(*Ei*) represent the transaction cost of the *i*-th stock. The total transaction cost refers to the sum of all the individual stocks, which is given as

$$\Phi\_t(E) = \sum\_{i=1}^{K} \Phi\_i(E\_i). \tag{8}$$

If Φ*t*(*E*) > 0, it means more stock is bought than sold. Likewise, if Φ*t*(*E*) < 0, it means that more stock is sold than bought. Generally, the transaction cost includes some additional charges, which we can formulate using a linear transaction model [55], which includes a linear function *α* = [*α*1, *α*2, *α*3, . . . , *α<sup>i</sup>* ], where *i* ∈ {1, 2, 3, . . . , *K*}. The transaction cost of the *i*-th stock in the portfolio is given as,

$$
\Phi\_i(E\_i) = \mathfrak{a}\_i E\_i. \tag{9}
$$

We can rewrite (7) using (9) as,

$$
\Phi(E) = \mathfrak{a}E^T.\tag{10}
$$

We can combine (5) and (10) into a single constraint, which is given as,

$$\chi(\mathbf{E}) = (\mathbf{1} + \mathfrak{a})\mathbf{E}^T = \mathbf{1}.\tag{11}$$

#### 2.1.5. Cardinality Constraint

Another real-world constraint in portfolio selection is known as the cardinality constraint. So far, we have assumed that investment is made in all of the *K* stocks. However, in a real case scenario, it is observed that the investor may want to exclude some stocks n (<*K*) from the final portfolio selection, which is known as a cardinality constraint. We can make such a decision by introducing a binary decision vector, i.e., *b* = [*b*1, *b*2, *b*3, . . . , *b<sup>i</sup>* , . . . , *bn*], where *b<sup>i</sup>* ∈ {0, 1}. According to the cardinality constraint,

$$\sum\_{i=1}^{K} b\_i = n.\tag{12}$$

We also need to reformulate (6) according to (12), which is given as,

$$\mathbf{0} \le \mathbf{E} \le \mathbf{b}.\tag{13}$$

### *2.2. Portfolio Selection Models*

Here, we will discuss the three known models for portfolio selection: mean variance model, efficient frontier model, and Sharpe ratio model.

#### 2.2.1. Mean-Variance Model

The primary objective of the mean variance model is to minimize the risk involved in portfolio selection, and it treats the expected return (profit) as a constraint. We can formulate the mean variance model using (2), (3), and (11)–(13), which is given as,

Minimize:

$$\min\_{\mathbf{E}} \upsilon(\mathbf{E}) \tag{14}$$

Subject to:

*E*

$$\boldsymbol{\xi}(\mathbf{E}) = \mathbf{E}\boldsymbol{\varepsilon}^{\mathrm{T}} - k \ge 0 \tag{15}$$

$$\chi(\mathbf{E}) = (\mathbf{1} + \mathfrak{a})\mathbf{E}^T = 1 \tag{16}$$

$$\sum\_{i=1}^{K} b\_i = n \tag{17}$$

$$\mathbf{0} \le \mathbf{E} \le \mathbf{b}.\tag{18}$$

The mean variance model is not very flexible, since it restrains the growth in profits. To overcome it, we can make use of an efficient frontier model.

#### 2.2.2. Efficient Frontier Model

In this model, we include expected return (profit) in the objective function. We can formulate the frontier model using (2), (3), and (11)–(13), which is given as,

Minimize:

$$\min\_{\mathbf{E}} \lambda v(\mathbf{E}) - (1 - \lambda)\xi(\mathbf{E}) \tag{19}$$

Subject to:

$$\chi(\mathbf{E}) = (\mathbf{1} + \mathfrak{a})\mathbf{E}^T = 1 \tag{20}$$

$$\sum\_{i=1}^{K} b\_i = n \tag{21}$$

$$\mathbf{0} \le \mathbf{E} \le \mathbf{b}.\tag{22}$$

here, *λ* ∈ [0, 1]. If *λ* = 0, then the model will maximize the expected-return (profit). However, if *λ* = 1, then the model will minimize the risk. The value of *λ* between [0, 1] will be a trade-off between profit and the risk. The only drawback of the model is that it involves the use of a hyper-parameter *λ*. To avoid this, we will look into a Sharpe model, which we will optimize using DBAS.

#### 2.2.3. Sharpe Ratio Model

The Sharpe ratio model is another portfolio selection model which includes the ratio of profit *ξ*(*E*) and risk *υ*(*E*). The objective is to maximize the ratio, which is given as,

$$SR = \frac{\mathfrak{f}(\mathbf{E})}{\upsilon(\mathbf{E})}.\tag{23}$$

We will inverse the formulation (23) to form a minimization problem. The Sharpe ratio model will help to avoid the additional hyper-parameter *λ*. Now, the objective is to minimize *<sup>υ</sup>*(*E*) *ξ*(*E*) , which will in turn maximize the profit and minimize the risk. Again, we can formulate the model using (2), (3), and (11)–(13), which is given as,

Minimization:

$$\min\_{\mathbf{E}} \frac{v(\mathbf{E})}{\xi(\mathbf{E})} \tag{24}$$

Subject to:

$$\chi(E) = (\mathbf{1} + \mathfrak{a})E^T = 1 \tag{25}$$

$$\sum\_{i=1}^{K} b\_i = n \tag{26}$$

$$\mathbf{0} \le \mathbf{E} \le \mathbf{b}.\tag{27}$$

This model will be used for the portfolio optimization. In the next section, we will formulate the Distributed Beetle Antennae Search (DBAS), which we will be used to solve the portfolio problem given in (24)–(27).

#### **3. Distributed Beetle Antennae Search (DBAS)**

In this section, we will elaborate on the nature of BAS, its formulation, and the algorithm. Later, we will develop DBAS and will discuss its underlying algorithm.

#### *3.1. BAS Formulation and Algorithm*

BAS has a biologically inspired meta-heuristic algorithm, which is inspired by the food-searching behavior of the beetle. It has two antennas, i.e., left *X<sup>l</sup>* and right *X<sup>r</sup>* . It registers the smell of the food on both antennae, and based on the intensity of the smell, it either moves in the left direction or right. The beetle repeats this procedure iteratively until it finally reaches the food source. Details on the behavior of beetles and BAS are presented in [56]. Here, we will look into updating the equations of the BAS algorithm, which are responsible for converging the searching particle toward the optimal solution.

Imagine a non-linear objective function *F*(*X*), where *X* is a vector of optimizing variables. We can represent an objective function as,

$$\min\_{\mathbf{X}} F(\mathbf{X}).\tag{28}$$

Here, we are solely considering an objective function, while the real-world problem would include additional constraints, as shown in (24)–(27). The objective of the BAS is to find the optimal solution of (28) by tweaking the values of *X* such that the maximum value of (28) is achieved. Here, it is worth mentioning that we can assume the maximization problem as well. The formulation will be a little different, which will be shown later during the derivation.

From this point forward, we will refer to the beetle as a particle. Let us say that the current position of the particle is *<sup>X</sup>* <sup>∈</sup> <sup>R</sup>1×*K*. To compute the new position of the particle, we will move it slightly to the right *X<sup>r</sup>* and slightly to the left *X<sup>l</sup>* , which is given as

$$\mathbf{X}\_{\mathbf{r}} = \mathbf{X} + d\mathbf{b} \tag{29}$$

$$\mathbf{X}\_l = \mathbf{X} - d\mathbf{b}\_l \tag{30}$$

where *<sup>b</sup>* <sup>∈</sup> <sup>R</sup>1×*<sup>K</sup>* is similar to *<sup>X</sup>*. Here, *<sup>d</sup>* is an antenna length, which determines how big or small a step should be taken in each iteration. In the beginning, *d* will have a larger value allowing the particle to explore more of the search space, and over time when the particle approaches the optimal solution, the value of *d* becomes small.

The next step is to compute the objective function value at *X<sup>r</sup>* and *X<sup>r</sup>* , so that BAS can decide its course, i.e., either in the *X<sup>r</sup>* direction or *X<sup>l</sup>* direction. The computation of *F*(*X*) is given as,

$$F\_{\mathbf{r}} = F(\mathbf{X}\_{\mathbf{r}}) \tag{31}$$

$$F\_l = F(\mathbf{X}\_l),\tag{32}$$

where *F<sup>r</sup>* and *F<sup>l</sup>* are scalar values of the objective function at *X<sup>r</sup>* and *X<sup>l</sup>* respectively. Now, BAS will compute the next step based on the difference of the values of *F<sup>r</sup>* and *F<sup>l</sup>* , which is given as,

$$
\Delta F = F\_r - F\_l \tag{33}
$$

$$\mathbf{X} = \mathbf{X} - \tau \text{sgn}(\Delta F)\mathbf{b},\tag{34}$$

where sgn is an activation function to translate the value of ∆*F* between [−1, 1]. Likewise, *τ* is another hyper-parameter, which is used to decide the step length of the BAS particle. This concludes the general framework of BAS. The algorithm is shown in Algorithm 1.

**Algorithm 1** BAS Algorithm.

```
Objective Function:
F(X, O)
DBAS Initialization:
η = 0.99
d = 0.9
τ = 0.9
Portfolio Initialization:
T = iter
D = dim
X = randn(1, D)
O = [Mn, Cn] Mn : Mean Cn : Covariance
Fbest = F(X, P)
Xbest = X
For i = 1 : T
      b = randn(1, D)
      Compute Xr and Xl using (29) and (30)
      Compute Fr and Fl suing (31) and (32)
      Compute X using (34)
      F = F(X, O)
      If Fmin < Fbest :
             Fbest = Fmax
             Xbest = X
      Else:
             X = Xbest
      End If
      d = ηd + 0.01
      τ = ητ
End For
```
This algorithm is designed for the portfolio selection problem. The objective function includes *F*(*X*, *O*), where *O* includes all the parameters necessary for the portfolio problem, i.e., *M* means of the stocks, *C* covariance matrix of the stocks, and other constraints. The single-particle BAS algorithm is limited to single portfolio optimization because of its computational limitations. In order to optimize multiple portfolios at once, we need to

introduce a more robust nature in the already existing framework, which we will introduce in DBAS formulation.

**Remark 1.** *The above formulation of BAS is for the minimziation problem. For the maximization problem, we need to modify the (34), as shown below,*

$$\mathbf{X} = \mathbf{X} + \tau \text{sgn}(\Delta F)\mathbf{b},\tag{35}$$

*where the* − *sign is replaced with the* + *sign. It will help BAS to move up the valley in the search space.*

In the next section, we will formulate the DBAS algorithm. Unlike BAS, the DBAS formulation will be better focused on the portfolio problem. However, it is worth mentioning that the algorithm is not problem-specific, as an objective function must be defined for any real-world problem. The schematic of the proposed algorithm is shown in Figure 2.

**Figure 2.** The schematic of the DBAS algorithm for the multi-portfolio selection problem. It consists of 3 portfolios and clearly shows that each particle [*X***1,** *X***2,** *X***3**] optimizes portfolio *PF*<sup>1</sup> , *PF*2, and *PF*3, respectively. It can be seen that particles do not share any portfolio database or stock information among the swarm, which ensures privacy.

#### *3.2. DBAS Formulation and Algorithm*

DBAS is a hybrid variant of BAS and PSO (Particle Swarm Optimization) algorithms. It mimics the swarm-like nature of PSO, where each step of the particles is based on the particle's best position *Pbest* and the swarm's best position *Sbest*. However, it uses the BAS updating strategy given in (34).

#### 3.2.1. DBAS Updating Criteria

We will modify the updating criteria for *X<sup>r</sup>* and *X<sup>l</sup>* given in (29) and (30). The updating criteria depend on three factors: the particle's best position *Pbest*, the swarm's best solution *Sbest*, and the random direction *db*. The modified updating criteria is given as,

$$\mathbf{V} = b\_1 \mathbf{V} + d\_1 b\_2 (\mathbf{P}\_{\text{best}} - \mathbf{X}) + d\_2 b\_3 (\mathbf{S}\_{\text{best}} - \mathbf{X}) \tag{36}$$

$$\mathbf{X\_{f}} = \mathbf{X} + d\mathbf{b} + \mathbf{V} \tag{37}$$

$$\mathbf{X}\_l = \mathbf{X} - d\mathbf{b} - \mathbf{V}\_l \tag{38}$$

where *<sup>b</sup>* <sup>∈</sup> <sup>R</sup>*D*×*<sup>K</sup>* and [*b*1, *<sup>b</sup>*2, *<sup>b</sup>*3] <sup>∈</sup> <sup>R</sup>. Here, *<sup>X</sup>* <sup>∈</sup> <sup>R</sup>*D*×*<sup>K</sup>* represents the particles positions, *<sup>P</sup>best* <sup>∈</sup> <sup>R</sup>*D*×*<sup>K</sup>* shows the particles best positions, and *<sup>S</sup>best* <sup>∈</sup> <sup>R</sup>*D*×*<sup>K</sup>* is the swarm's best position, which are stacked in a row to meet the dimensionality requirement. Likewise, [*d*, *d*1, *d*2] are scalars. Typical swarm algorithms are used to compute a single objective function, but our objective is to optimize multiple objective functions since each portfolio comprises different stocks. Therefore, it is worth mentioning that *<sup>X</sup>* <sup>∈</sup> <sup>R</sup>*D*×*K*, where *D* and *K* represent the number of portfolios and portfolio size, respectively. Likewise, {*b***1,** *<sup>b</sup>***2**} ∈ <sup>R</sup>*D*×*<sup>K</sup>* are two random vectors and *<sup>d</sup>* represents the antenna size. Each particle in DBAS corresponds to a single portfolio. The objective is that each particle will optimize its corresponding portfolio locally, i.e., *P j best* <sup>∈</sup> <sup>R</sup>1×*K*, where *<sup>j</sup>* ∈ {1, 2, 3, . . . , *<sup>D</sup>*}, and the swarm will optimize all portfolios, i.e., *Sbest*, collectively.

After computing *X<sup>r</sup>* and *X<sup>l</sup>* ,, the next step is to compute the objective function value for each portfolio, i.e., each particle. It is given as,

$$\mathbf{F}\_{\mathbf{l}} = \mathbf{F}(\mathbf{X}\_{\mathbf{l}}, \mathbf{O}) \tag{39}$$

$$F\_l = F(\mathbf{X}\_l, \mathbf{O})\_l \tag{40}$$

where *O* includes all the parameters necessary for portfolio optimization as mentioned in the problem formulation section. Here, {*F<sup>r</sup>* , *<sup>F</sup>l*} ∈ <sup>R</sup>*D*×<sup>1</sup> and *<sup>F</sup>*(.) is a vector of dimension *D*; it includes the objective functions of all portfolios. Next, each position of particle *X* is updated using,

$$
\Delta \mathbf{F} = \mathbf{F}\_{\mathbf{r}} - \mathbf{F}\_{\mathbf{l}} \tag{41}
$$

$$\mathbf{X} = \mathbf{X} - \tau \text{sgn}(\Delta \mathbf{F}) \mathbf{b}. \tag{42}$$

Then, the objective function value of each portfolio is computed, i.e., the particle at *X*, which is given as,

$$\mathbf{F} = \mathbf{F}(\mathbf{X}, \mathbf{O}),\tag{43}$$

where *F* has similar dimensions as *F<sup>r</sup>* and *F<sup>l</sup>* . If the objective function value *Fj*(.) of a *<sup>j</sup>*-th particle at *<sup>X</sup><sup>j</sup>* <sup>∈</sup> <sup>R</sup>1×*<sup>K</sup>* is less than its personal best *<sup>P</sup> j best*, then update *P j best* with *X<sup>j</sup>* ,. Otherwise, retain the old best values. This updating rule for all the particles *X* is given as,

$$P\_{best} = \Omega(\mathbf{X}) = \begin{cases} \mathbf{X}\_{\prime} & \text{if } \mathbf{F}(\mathbf{X}) < P\_{best} \\ P\_{best\prime} & \text{otherwise.} \end{cases} \tag{44}$$

Now, the next step is to obtain the swarm's best position. This can be done by simply looking for the minimum value of the objective function in *F*(.), which is given as,

$$[F, j] = \min(F(X\_\prime \mathbf{O})).\tag{45}$$

If the value of *F* is less than the swarm's best solution *Gbest*, then update *Sbest*; otherwise, retain the old best, which is given as,

$$\mathbf{S}\_{best} = \psi(F) = \begin{cases} \mathbf{X}\_{j\prime} & \text{if } F < \mathbf{G}\_{best} \\ \mathbf{S}\_{best\prime} & \text{otherwise.} \end{cases} \tag{46}$$

To further randomize the process, we have included another condition to the update *d* and *τ*. We have included a random variable *r* = rand ∈ [0, 1]; if *r* < 0.5, then we will update the values of *d* and *τ*. The pseudocode is shown in Algorithm 2.

**Algorithm 2** DBAS Algorithm. **Objective Function:** *F*(*X***,** *O*) **DBAS Initialization:** *η* = 0.99 *d* = 0.9 *d*<sup>1</sup> = 0.9 *d*<sup>2</sup> = 0.9 *τ* = 0.9 **Portfolio Initialization:** *T* = *iter* %Iterations *D* = *pop* %Total Portfolios *K* = *dim* %No. of Stocks In Each Portfolio *X* = randn(*D*, *K*) *Xbest* = *X O* = [*O***1**, *O***2**, *O***3**, . . . , *OK*] % *O<sup>K</sup>* Includes Parameters For *k*-th Portfolio % *O<sup>K</sup>* = [*MK*, *CK*] *M<sup>K</sup>* : Mean *C<sup>K</sup>* : Covariance *Pmin* = *F*(*X***,** *P*) [*Gbest*, ind] = min(*F*(*X***,** *P*) *Sbest* = *X*ind **For** *i* = 1 : *T b* = randn(*D*, *K*) *b*<sup>1</sup> = randn(1, 1) *b*<sup>2</sup> = randn(1, 1) *b*<sup>3</sup> = randn(1, 1) Compute *V* using (36) Compute *X<sup>r</sup>* and *X<sup>l</sup>* using (37) and (38) Compute *F<sup>r</sup>* and *F<sup>l</sup>* suing (39) and (40) Compute *X* using (42) **For** *j* = 1 : *D F* = *Fj*(*X<sup>j</sup>* **,** *Oj*) **If** *F* < *P j min* : *P j min* = *F P j best* = *X<sup>j</sup>* **End If End For** [*F*, ind] = min(*F*(*X***,** *O*)) **If** *F* < *Gbest* : *Gbest* = *F sbest* = *X*ind *Sbest* = repmat(*sbest*, *D*, 1) **End If** *r* = rand **If** *r* < 0.5 : *d* = *ηd* + 0.01 *d*<sup>1</sup> = *ηd*<sup>1</sup> + 0.01 *d*<sup>2</sup> = *ηd*<sup>2</sup> + 0.01 *τ* = *ητ* **End If End For**

#### 3.2.2. DBAS Privacy Policy

Each particle in DBAS deals with a single portfolio. A particle alone has access to the private data of the assigned portfolio, including: stock names, investment amount, mean of the portfolio, and variance of the portfolio. The portfolio is like a black box. The particle *X<sup>j</sup>* will enter the black box *Fj*(*X<sup>j</sup>* **,** *O*), will compute the objective function of the portfolio and will give out the objective function value *F<sup>j</sup>* while keeping the privacy of the private database and portfolio information. The objective function value, i.e., gradient, will be available to all the other particles and based on all the gradients, i.e., objective function values of all particles, the DBAS algorithm will compute the swarm's best solution to decide the next step. It helps the DBAS to efficiently find the optimal selection of all portfolios without violating the confidentiality and privacy of portfolios. The concept of DBAS privacy is shown in Figure 3.

**Figure 3.** Each particle in DBAS is assigned to a single portfolio, and the particle alone has access to the private database of the portfolio. In DBAS, the particle in swarm only shares the objective function values *F*, i.e., gradients.

#### **4. Simulation Results**

In this section, we will discuss the stock data used for the multiple portfolio selection problem. Furthermore, the DBAS algorithm will be employed to solve the optimization problem formulated in the problem formulation selection.

#### *4.1. Stock Data*

For the simulation, we collected real-world stock data from the NASDAQ stock market in 2017. The data comprise several hundred stock companies. A total of 25 known companies were selected for the simulation. Then, 200 days worth of stock closing prices were collected for each company to understand the data trend in more detail and to provide more robust portfolios. All the 25 companies are shown in Table 2. The volatility of the stock market is shown in Figure 4. It can be seen how abruptly the stock prices (return rate) change over time.


**Table 2.** NASDAQ Symbols of The Stock Companies In Portfolio Selection.

**Figure 4.** The return rate for all the 25 companies for 200 days of NASDAQ stock data in 2017. (**a**–**e**) represents the data of companies 1–5, companies 6–10, companies 11–16, companies 16–20, and companies 20–25, respectively.

In our simulation, there are four multi-portfolio optimization problems, i.e., 5 stock companies, 10 stock companies, 15 stock companies, and 20 stock companies. In each multi-portfolio selection problem, we will be optimizing *three* portfolios. For instance, in the *f ive* stock companies multi-portfolio selection problem, DBAS will optimize three portfolios, each looking for an optimal selection of stock companies. Considering the stochastic nature of the DBAS algorithm and how results can vary with each experiment, we performed simulation on each portfolio for 10 times, and the average or mean result is obtained. The computational resources used in the simulations are given below:


#### *4.2. Three Portfolios of Five Stock Companies*

For the first simulation category, *three* portfolios were selected, each consisting of *f ive* companies. The objective is to optimize the three objective functions (24)–(27), i.e., portfolios, such that the raw data of each portfolio remain private and without sharing the private databases that DBAS optimizes. There are a few hyper-parameters in DBAS, i.e., antenna length *d* and particle step-size *τ*. We selected the values of these hyper-parameters through trial and error, e.g., *τ* = 0.900, *d* = 0.999, and *η* = 0.900, which are shown in Table 3. In addition, a few other parameters were selected for the simulation, i.e., total iterations *T* = 500, swarm population *D* = 3, dimension of each portfolio *K* = 5.



After setting all of the parameters. DBAS is ready to optimize the portfolio problem mentioned in (24)–(27). The simulation results are evaluated based on three parameters: swarm convergence *Gbest*, particles convergence *Pbest*, Sharpe ratio *SR*, and the total investment constraint (**1** + *α*)*E* = 1. The results are shown in Table 3 and the convergence profiles of *Gbest*, *Pbest*, *SR* and (**1** + *α*)*E* = 1 are shown in Figures 5–8a. For *three* portfolios of *f ive* stock companies, the swarm best solution turns out to be 10−<sup>7</sup> , and the convergence profile in Figure 5a shows how efficiently and quick DBAS converges to the optimal solution. Likewise, the convergence of each particle, i.e., each portfolio, is also robust, as shown in Figure 6a. However, the convergence rates do not give us the relationship between the profit and risk. For that, the Sharpe ratio curve was computed. It can be seen in Figure 7a that each portfolio has achieved substantial profit with minimal risk involved. Finally, it is essential that the investment in stocks remains around ≈ 1. We have shown the convergence profile of (**1** + *α*)*E* = 1 in Figure 8a, and it can be seen that all three investments converge to around 1, which is required. The detailed results are also shown in Table 3.

**Figure 5.** The sharp and fast convergence of DBAS swarm's *Gbest* toward the minima while selecting optimal configuration of all 3 portfolios. It also shows the comparison with PSO and GA algorithms, and it can be seen that the convergence profile of DBAS is fast compared to others. (**a**) shows the global convergence profile of all algorithms. Likewise, (**b**) shows the convergence of BAS, PSO, and GA. And finally, (**c**,**d**) shows the convergence of 15 and 20 stocks of all three algorithms respectively. **Figure 5.** The sharp and fast convergence of DBAS swarm's *Gbest* toward the minima while selecting optimal configuration of all 3 portfolios. It also shows the comparison with PSO and GA algorithms, and it can be seen that the convergence profile of DBAS is fast compared to others. (**a**) shows the global convergence profile of all algorithms. Likewise, (**b**) shows the convergence of BAS, PSO, and GA. And finally, (**c**,**d**) shows the convergence of 15 and 20 stocks of all three algorithms respectively.

**Figure 6.** The sharp and fast convergence of DBAS particles *Pbest* toward their respective minimas while selecting an optimal configuration of their portfolios. Since we are dealing with three portfolios, we can see the three convergence profiles. (**a**) shows the global convergence profile of all algorithms. Likewise, (**b**) shows the convergence of BAS, PSO, and GA. And finally, (**c**,**d**) shows the convergence of 15 and 20 stocks of all three algorithms respectively.

**Figure 7.** The rising trend of Sharpe ratio *SR* as the DBAS moves towar the optimal solution of portfolio selection problem. The higher value of *SR* indicates that each portfolio has a higher profit *ξ*(*E*) and lower risk *υ*(*E*), as shown in (23). (**a**) shows the convergence profile of sharpe-ratio of 5 stocks. Likewise, (**b**) shows the convergence of sharpe-ratio of 10 stocks. And finally, (**c**,**d**) shows the convergence of sharpe-ratio of 15 and 20 stocks respectively. **Figure 7.** The rising trend of Sharpe ratio *SR* as the DBAS moves towar the optimal solution of portfolio selection problem. The higher value of *SR* indicates that each portfolio has a higher profit *ξ*(*E*) and lower risk *υ*(*E*), as shown in (23). (**a**) shows the convergence profile of sharpe-ratio of 5 stocks. Likewise, (**b**) shows the convergence of sharpe-ratio of 10 stocks. And finally, (**c**,**d**) shows the convergence of sharpe-ratio of 15 and 20 stocks respectively.

The main takeaway from the results is that DBAS can converge multi-portfolios and ensures the clients' secrecy and privacy. In the simulated results, it can be seen that each particle in DBAS only shares the objective function value *P j best*, i.e., gradient with other particles, whereas the private information of the portfolio remains inaccessible to other portfolios.

#### *4.3. Three Portfolios of 10 Stock Companies*

For the second simulation scenario, we again selected *three* portfolios, each consisting of 10 companies. The values of hyper-parameters were once again chosen through trial and error, which are also shown in Table 3. In addition, the other parameters for the simulation include total Iterations *T* = 500, swarm population *D* = 3, dimension of each portfolio *K* = 10.

The simulation results are shown in Table 3, and the convergence profiles of *Gbest*, *Pbest*, *SR* and (**1** + *α*)*E* = 1 are shown in Figures 5–8b. For the *three* portfolios of 10 stock companies, the swarm best solution turns out to be 10−<sup>6</sup> . Its convergence profile is shown in Figure 5b. Likewise, the convergence of each particle, i.e., each portfolio, is also robust and shown in Figure 6b. Their convergence values turn out to be optimal, i.e., *Pbest* = [10−<sup>6</sup> , 10−<sup>6</sup> , 10−<sup>4</sup> ]. The Sharpe ratio curve is shown in Figure 7b, and it can be seen that each portfolio has achieved substantial profit with minimal risk. We have also shown the convergence profile of (**1** + *α*)*E* = 1 in Figure 8b, where it can be seen that all three investments converge to around 1, which is again required. The detailed results are also shown in Table 3.

**Figure 8.** It shows that as the portfolio selection problem converges toward the optimal solution, the sum of normalized investment (**1** + *α*)*E* ≈ 1. There are some spikes in the beginning; however, all the particles of the respective portfolio converge to 1. (**a**) shows the convergence of normalized investment (**1** + *α*)*E* ≈ 1 of 5 stocks. Likewise, (**b**) shows the convergence of normalized investment of 10 stocks. And finally, (**c**,**d**) shows the convergence of normalized investment of 15 and 20 stocks respectively.

#### *4.4. Three Portfolios of 15 Stock Companies*

For the third simulation scenario, we again selected *three* portfolios, each consisting of 15 companies. Once again, the values of the hyper-parameters were chosen through trial and error, which are also shown in Table 3.

The simulation results are shown in Table 3 and the convergence profiles of *Gbest*, *Pbest*, *SR* and (**1** + *α*)*E* = 1 are shown in Figures 5–8c. For the *three* portfolios of 15 stock companies, the swarm's best solution turns out to be 10−<sup>4</sup> . Its convergence profile is shown in Figure 5c. Likewise, the convergence of each particle, i.e., each portfolio, is also robust and shown in Figure 6c. Their convergence values turn out to be again optimal, i.e., *Pbest* = [10−<sup>4</sup> , 0.020, 0.001]. The Sharpe ratio curve is shown in Figure 7b, and it can be seen that each portfolio has again achieved substantial profit with minimal risk. We have also shown the convergence profile of (**1** + *α*)*E* = 1 in Figure 8c, and it can be seen that all three investments converge to around 1, which is required. The detailed results are also shown in Table 3.

#### *4.5. Three Portfolios of 20 Stock Companies*

For the fourth and the last simulation scenario, we selected *three* portfolios, each consisting of 20 stock companies. Hyper-parameters are also shown in Table 3.

The simulation results are shown in Table 3 and the convergence profiles of *Gbest*, *Pbest*, *SR* and (**1** + *α*)*E* = 1 are shown in Figures 5–8d. For *three* portfolios of 15 stock companies, the swarm's best solution turns out to be 10−<sup>7</sup> . Its convergence profile is shown in Figure 5d. Likewise, the convergence of each particle, i.e., each portfolio, is also robust and shown in Figure 6d. Their convergence values turns out to be optimal, i.e.,

*Pbest* = [10−<sup>7</sup> , 10−<sup>7</sup> , 10−<sup>6</sup> ]. The Sharpe ratio curve is shown in Figure 7b, and it can be seen that the ratio is again substantially high. We have also shown the convergence profile of (**1** + *α*)*E* = 1 in Figure 8d, and it can be seen that all three investments converge to around 1, which is required. The detailed results are also shown in Table 3.

The primary limitation of DBAS is the "Virtual particle," which means that for each iteration, we have to compute the objective function value for three times for *F<sup>r</sup>* , *Fl* , and *F*. It could make it computationally expensive and consume time. In the future, we will work on eliminating the "virtual particle" limitation, and we will also include some other meta-heuristic algorithms such as GSK [57] to compare with. Likewise, we will work on some additional statistical analysis including non-parametric statistical tests such as Wilcoxon Signed Rank Test and Friedman.

### **5. Conclusions**

In this paper, a framework to ensure the privacy of stock portfolios in the multiportfolio selection problem was proposed. This involved the design of a distributed variant of the BAS algorithm known as Distributed Beetle Antennae Search (DBAS). DBAS combines the swarm-like behavior of PSO with BAS's updating rule. Each particle in the swarm is assigned to optimize a single portfolio, and the particles only share the gradient of their respective portfolio with the swarm, avoiding the exposure of the private database and stock information of portfolios. The algorithm was then simulated on real-world stock data extracted from the NASDAQ stock market for 25 stock companies. The simulation is divided into *f our* categories, and in each category, *three* portfolio models were optimized. The simulation results show that DBAS not only ensures the privacy of portfolios but is also robust, computationally economical, and time efficient.

**Author Contributions:** A.T.K.: methodology, software, validation; X.C.: Conceptualization, resources; B.L.: funding acquisition, formal analysis; A.F.: data curation, visualization, writing—review and editing. All authors have read and agreed to the published version of the manuscript.

**Funding:** This work is supported by the National Natural Science Foundation of China under grant 61966014.

**Institutional Review Board Statement:** Not applicable.

**Informed Consent Statement:** Not applicable.

**Data Availability Statement:** Not applicable.

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

#### **References**


MDPI St. Alban-Anlage 66 4052 Basel Switzerland Tel. +41 61 683 77 34 Fax +41 61 302 89 18 www.mdpi.com

*Biomimetics* Editorial Office E-mail: biomimetics@mdpi.com www.mdpi.com/journal/biomimetics

Academic Open Access Publishing

www.mdpi.com ISBN 978-3-0365-8468-3