Diversification of Time-Varying Tangency Portfolio under Nonlinear Constraints through Semi-Integer Beetle Antennae Search Algorithm

In finance, the most efficient portfolio is the tangency portfolio, which is formed by the intersection point of the efficient frontier and the capital market line. This paper defines and explores a time-varying tangency portfolio under nonlinear constraints (TV-TPNC) problem as a nonlinear programming (NLP) problem. Because meta-heuristics are commonly used to solve NLP problems, a semi-integer beetle antennae search (SIBAS) algorithm is proposed for solving cardinality constrained NLP problems and, hence, to solve the TV-TPNC problem. The main results of numerical applications in real-world datasets demonstrate that our method is a splendid substitute for other evolutionary methods.


Introduction
Portfolio optimization models aid in the selection of financial assets by investors. As a result, when making financial decisions, portfolio management is critical. Nowadays, using modern optimization techniques, popular fields in finance such as securities trading, option replication, investment banking, risk management, and so on may be effectively handled. Nature inspired algorithms [1][2][3][4], conic programming [5], branch and bound technique [6], non-differential optimization and cutting planes techniques [7], Riesz-space theory [8,9] are some of these techniques. More precisely, the problem of finding a Markowitz based portfolio is tackled by nature inspired algorithms in [1,3,4] and by conic programming in [5]. To solve a portfolio insurance problem, the Riesz space theory is used in [8,9] and meta-heuristics are used in [2], whereas in [7], non-differential optimization and cutting planes techniques are employed to solve a conditional value at risk portfolio problem. This paper defines and explores a time-varying tangency portfolio under nonlinear constraints (TV-TPNC) problem as a nonlinear programming (NLP) problem. It is worth noting that the most efficient portfolio in finance is the tangency portfolio, which is formed by the intersection point of the the efficient frontier and capital market line (CML). Because metaheuristics are commonly used to solve NLP problems, a semi-integer beetle antennae search (SIBAS) algorithm is proposed to solve the TV-TPNC problem.
SIBAS is a hybrid algorithm that combines the beetle antennae search (BAS) algorithm from [10] with the binary BAS (BBAS) algorithm from [11]. Broadly, nature inspired optimization algorithms have been widely used in a variety of scientific domains in recent years, such as finance, computer science and engineering. BAS was chosen in this paper from a vast range of nature inspired meta-heuristics because of its minimal time consumption. BAS has been used to address problems in engineering portfolio optimization [12], asset distribution [13], assets' insurance selection [14], pattern classification [15], machine learning [16], mathematical programming [11], electro-hydraulic position systems [17], integrated circuits [18], tomography diagnosis [19]. This work's main points can be summarized as follows: • We define and explore the TV-TPNC problem as a NLP problem. • To tackle NLP problems with cardinality constraints, a hybrid algorithm, called SIBAS, is proposed. • We present the SIBAS efficiency against particle swarm optimization (PSO), differential evolution (DE) and slime mould algorithm (SMA) on a financial NLP problem.
The paper is constituted as follows. Section 2 defines and analyses the TV-TPNC problem. In Section 3, the SIBAS is provided for dealing with cardinality constrained NLP problems as well as the TV-TPNC problem. Section 4 offers two applications that employ real-world data to compare SIBAS performance to the PSO, SMA, and DE in various and somewhat large portfolio setups. The MATLAB repository that has been made available on GitHub is also mentioned in Section 4. This repository supports the readability and computational utility of this work by implementing all of the algorithms described in Section 3. Lastly, the final remarks are offered in Section 5.

Tangency Portfolio Optimization
The mean-variance optimization theory of Markowitz provides a mechanism for selecting assets (or securities) portfolios that trades off expected returns and risk of prospective portfolios. For a given level of risk, investors that utilize mean-variance resolution to maximize their expected return always prefer portfolios that are on the CML. If a feasible portfolio has the highest expected return among all portfolios with the same variance, or if it has the lowest variance among all portfolios with at least a specific expected return, it is said to be efficient. The efficient frontier of the portfolio universe is made up of a collection of efficient portfolios. The most efficient portfolio, dubbed the tangency portfolio, is found at the point where the CML intersects with the efficient frontier.
Any portfolio p with one or more risky assets and one risk-free asset may have a linear connection between its expected return r p and its risk σ p , according to Sharpe Ratio (SR) [20]. Mathematically, this can be stated in the following way: where r f denotes the risk-free asset's return and S p denotes the portfolio's SR, which is the risk premium per risk unit. The tangency portfolio optimization given in [21] is the foundation of our approach to the TV-TPNC problem. A rationalistic risk averse investor's endowment will be divided, with a proportion γ invested in a risk-free asset and the rest (1 − γ) in a time-varying portfolio of risky assets p(t), t ⊆ N, whereas S p (t) is determined by the composition of p(t), which is based on the common capital market hypothesis of one risk-free and many risky assets. Consider the market space X(t) = [x 1 (t), x 2 (t), . . . , x n (t)] ∈ R n that contains n assets prices, the investor would choose the weights p i (t), for the assets i = 1, 2, . . . , n, included in the portfolio p(t) = [p 1 (t), p 2 (t), . . . , p n (t)] ∈ R n to optimize S p (t). It is worth emphasizing that γ reflects the investor's risk aversion, and that all investor's p i (t) must be the alike. As a result, the time-varying tangency portfolio p(t) can be computed without considering the risk aversion or utility function of the investor.
Moreover, investors prefer portfolios with a lower number of different assets since handling portfolios with a big number of various assets may be time intensive [22]. A key consideration during the portfolio selection process is that most of a portfolio's risk diversification may be achieved with a small but well-selected collection of assets [21]. Mathematically, a cardinality constraint (CC) can be used to any portfolio optimization problem to achieve this. Thus, the fixed number K denotes the exact amount of assets an investor can own, avoiding over-diversification, while CC is expressed as the binary vector D(t) = [D 1 (t), D 2 (t), . . . , D n (t)] ∈ R n , which signify the assets in the portfolio and can have a value of 1 or 0, where D i (t) = 1 signifies that the investor owns the asset i and D i (t) = 0 signifies the opposite. Thus, the time-varying CC function can be formulated as follows: MPT frequently considers an ideal market in which short sales are prohibited but shares are infinitely separable and hence may be sold in any non-negative partition, free of taxes and transaction costs (TC). TC can refer to a variety of expenses like fund loads, taxes, bid-ask spreads, brokerage charges, and so on. Inline with [23], we will consider θ − , θ + the fixed charges prices generated from the sell and buy of an asset i, and ζ − , ζ + the cost charges generated from the sell and buy of an asset i. Thus, TC generated from the sell and buy of an asset are separate, and the time-varying TC function can be formulated as follows: and Apart from the case of zero costs, (3) is nonconvex.
According to the aforementioned, if a market X(t) of n assets exists, in which only K of them have to be included in p(t), the TV-TPNC problem can be formulated as follows: where r i (t) signifies the expected return of asset i at time t, and σ ij (t) signifies the covariance among the expected returns of assets i and j at time t.
The following improvements are made to transform the TV-TPNC to an NLP problem and make it more realistic. We use past values (or delays) to construct the variance (risk), covariance matrix and expected return of the market X(t). Representing the delays with the constant number β ∈ N, we consider . . , n, expected return at time t, and C(t) ∈ R n×n the covariance matrix of X(t) based on β in number delays. In this way, we can set r p (t) = p T (t)r(t) and σ p (t) = p T (t)C(t)p(t). It is worth noting that X(t) contains both risk-free and risky assets. However, when it comes to investing, there is no such thing as an asset that is risk-free because nothing can be guaranteed 100 percent. As a result, in our model, risk-free assets are defined as market assets with a variance below a small fixed value α. Thus, setting with signifying the Hadamard (or element-wise) product. It is also worth noting that the price of each asset x i is normalized inline with its β in number delays.
The TV-TPNC problem may be expressed in the following NLP formation based on the aforementioned analysis: where 0, 1 ∈ R n signify a zero vector and a vector of ones, respectively.

The Semi-Integer Beetle Antennae Search Model
The computational procedures utilized to handle the given financial NLP problem in a brief period of time with great accuracy are the main emphasis of this paper. As a result, a hybrid algorithm called SIBAS is developed, which is based on a nature inspired algorithm called BAS, whose primary advantage is its low time consumption. SIBAS combines BAS and BBAS to better handle cardinality constrained NLP problems.

The SIBAS Algorithm
BAS is a nature inspired algorithm that finds the best solution to an optimization problem by mimicking the behavior of a beetle [10], while a binary type of BAS named BBAS was presented in [11]. In these algorithms, the way the beetle's two antennae detect the intensity of a smell and use it to track food is related to finding the minimum of an objective function. Due to the fact that these algorithms are only applicable to optimization without constrains, a complementary procedure have to be used to keep solutions inside the acceptable range. The penalty method [24] is chosen as the supplementary procedure for manipulating nonconvex or convex constraints more effectively in this study.
Penalty methods work in a succession of steps, each time altering a set of penalty parameters and initiating a new one using the previous. Throughout the building of any sequence, the penalty function that follows is minimized: where f (w) signifies the objective function. Furthermore, U(R, q(w)) signifies the penalty term, where q(w) denotes the inequality/equality constraint and R denotes a set of penalty parameters. Commonly, this procedure has the benefit of being able to indulge any nonconvex or convex constraint. Inhere, the penalty method incorporates the bracket operator · to manage U(R, q(w)). If the input value is positive, the bracket operator returns 0, else it returns the input value. Thus, penalty term can be formulated as follows: where q j (w) signifies the j-th inequality/equality constraint. The SIBAS may be described as follows. At i-th time moment, consider the position of the beetle as a vector x i , i = 1, 2, . . . . Then, the gathering of odour is the objective functions F 1 (x) and F 2 (x) at position x. As a result, the minimum value of F 1 (x) and F 2 (x) is linked to the odour's source spot. Note the F 1 (x) is (13) with only the CC of the NLP problem, while F 2 (x) is (13) with all the rest inequality/equality constraints of the NLP problem. The model of seeking behavior is defined as follows by a random searching path of the beetle: where rnd(·) and round(·) signify a random and a round function, respectively, while n signifies the position's dimensions. The right (x R ) and left (x L ) antennae are composed as bellow to replicate the seeking behaviors of the beetle's antennae: Moreover, assuming the candidate optimal solution as bellow: the behavior of detecting may be formulated as bellow: Note that i signifies the iteration number. Given that y is the optimal solution of F 1 (·), a new random seeking path is created for optimizing F 2 (·). Hence, setting g = rnd(n, 1) at position x i−1 , the random path is as bellow: Imitating the antennae motions, we have: where the detecting diameter of the antennae is denoted by d, which is related to the ability to exploit. In addition, considering the candidate optimal solution: where the term δ refers to a size step that corresponds to the pace of convergence following an increase in i during the search. In this way, the optimal solution of F 1 (·) is merged with the solution of F 2 (·), while only specific elements of x C are allowed to be modified. Hence, the behavior of detecting may be formulated as bellow: Finally, the d and δ update rules are as follows:

SIBAS Approach on the TV-TPNC Problem and the Complete Process
Given the market dataset M, which comprises of assets prices time-series, the market space X(t) along with the span of time-period t are determined based on the delays number β. In addition, C(t) and R(t) = r(t) − H(t) r(t) can be constructed based on the analysis presented in Section 2. Setting the initial position of the beetle as the initial portfolio of the TV-TPNC problem as well as the penalty functions according to the analysis presented in Section 3.1, the TV-TPNC problem of (9)-(12) can be solved with the SIBAS algorithm.
More precisely, the penalty functions for the TV-TPNC problem of (9)-(12) can be written in MATLAB routines as follows: where sum(·) signifies the MATLAB routine for summing the elements of an input array and f (p) is (9). The complete process to solve the TV-TPNC problem of (9)-(12) using the SIBAS approach is presented in Algorithm 1, where the zeros(·), mean(·), var(·) and cov(·) signify regular MATLAB routines.

Applications
This section compares and contrasts SIBAS' performance with those of state-of-the-art meta-heuristics algorithms such as PSO of MATLAB, DE of [25] and SMA of [26] in solving the TV-TPNC problem of (9)- (12). The daily close prices of the stocks shown in Figure 1 are the real-world data employed. This figure contains stocks' ticker symbols divided into two portfolio's cases. This section also contains information regarding the data and code availability. Moreover, in all experiments along with all the nature inspired algorithms used inhere, the penalty parameter has been set to R = 10 5 , and the maximum iterations to 10 3 . The SIBAS parameters have been set to d = 0.2 and δ = 0.5, the PSO used with its default settings and the population size of SMA and DE have been set to 30 and 50, respectively.The variance (risk) number has been set to α = 10 −3 , and the delays number has been set to β = 40, while the parameters in (3) have been set to ζ − = 2, ζ + = 4 and θ − = θ + = 1.

Real-World Data Portfolio Cases
In the s-th portfolio case, s = 1, 2, we assume the market dataset to be M ∈ R 123×w . Note that s = 1 has w = 40 and K = 20, while s = 2 has w = 80 and K = 40. Based on this and the number of delays, we construct the market X(t) = [x 1 , x 2 , . . . , x w ] ∈ R w for t = 1 to 83. That is, X(t) contains 83 daily prices of w in number stocks that correspond to the time-period 3/2/2020-1/6/2020. Because of the cardinality number, the optimal portfolio p opt (t) holds exactly K in number stocks, at least one of which is risk-free. The findings for solving the TV-TPNC problem with initial portfolio p in = 1/w ∈ R w are presented in Figure 2a-f for the portfolio case 1, and in Figure 2g-l for the portfolio case 2.   On the one hand, Figure 2a,g depict the SR of the portfolios under a market containing 40 and 80 stocks, respectively. Therein, it can be observed that the SR produced by the optimal portfolio of SIBAS is always higher than the optimal portfolios produced by PSO, SMA, and DE. Figure 2b,h show the TC, where it is observable that SIBAS optimal portfolios have always lower TC compared to PSO, SMA, and DE. The TC of the PSO, SMA, and DE optimal portfolios are similar in portfolio case 1, however they are not in portfolio case 2. Figure 2c,i show the average SR during the time period for the portfolio cases 1 and 2, respectively. According to these figures, SIBAS optimal portfolios produce the highest SR during the specific time period in both portfolio cases, while DE optimal portfolios produce the second highest SR and SMA optimal portfolios produce the lowest SR. Figure 2d,j show the average TC during the time period for the portfolio cases 1 and 2, respectively. Based on these figures, SIBAS optimal portfolios produce the lowest TC during the specific time period in both portfolio cases, while DE optimal portfolios produce the second lowest TC and SMA optimal portfolios produce the highest TC. Figure 2e,k show the total assets owned from the optimal portfolios produced by SIBAS, PSO, SMA, and DE during the time period along with the cardinality number K for the portfolio cases 1 and 2, respectively. Therein, it is observable that all portfolios always owns K in number assets and, hence, the CC is satisfied in both portfolio cases. Figure 2f,l show the sum of the optimal portfolios assets weights, which is the left part of (10), produced by SIBAS, PSO, SMA, and DE during the time period for the portfolio cases 1 and 2, respectively, along with the equality constraint (EC) number of (10), which is equal to 1. Therein, it is observable that the outcome of the SIBAS optimal portfolios always have the least noise and are closest to 1 in both portfolio cases. That is, SIBAS produces the best outcome in both portfolio cases, while SMA produces the second best outcome and DE the worst in portfolio case 1, and DE produces the second best outcome and SMA the worst in portfolio case 2. Figure 3a,b present the SIBAS, PSO, SMA, and DE convergence in the portfolio cases 1 and 2, respectively, for t = 1, while the corresponding time consumption of SIBAS, PSO, SMA, and D at each iteration is presented in Figure 3c,d, respectively. That is, the value of (9) at each iteration of the SIBAS, PSO, SMA, and DE when the time-period for solving the TV-TPNC problem is 3 February 2020 is depicted in Figure 3a,b. In Figure 3a,b, we observe that SIBAS has the best convergence in both portfolio cases, whereas SMA has the worst, with PSO having the second best convergence in portfolio case 1 and DE having the second best convergence in portfolio case 2. In Figure 3c,d, we observe that SIBAS has the lowest time consumption in both portfolio cases, whereas DE has the highest time consumption in portfolio case 1 and SMA has the highest time consumption in portfolio case 2. Furthermore, the time consumption of PSO is non-linear and quite noisy in both portfolio cases. However, PSO has the second lowest time consumption in both portfolio cases at iteration 1000. SIBAS has the lowest computational complexity, as shown in Figure 3a,b, since it converges faster to the optimum solution in less iterations than PSO, SMA, and DE. Furthermore, SIBAS has the lowest time complexity, as shown in Figure 3c,d, since it takes less time to complete an iteration than PSO, SMA, and DE. As a result, SIBAS outperforms PSO, SMA, and DE when it comes to solving the TV-TPNC problem.
The average time consumption demanded from SIBAS, PSO, SMA, and DE to generate the optimal solutions for the TV-TPNC problem in both portfolio cases, on the other hand, is contained in Table 1. It is evident from this that SIBAS is always the quickest algorithm. More particularly, SIBAS is about 5 times faster in portfolio case 1 than the second fastest PSO, and more than 10 times faster in portfolio case 2. Moreover, SIBAS is about 28 times faster than the third faster DE in both portfolio cases, while it is more than 40 times faster in portfolio case 1 than the slowest SMA, and about 60 times faster in portfolio case 2.
The above analysis leads to the conclusion that SIBAS performed admirably and effectively in resolving the TV-TPNC problem. According to Figures 2 and 3 and Table 1 results, the SIBA produces more effective optimal portfolios than the PSO, SMA, and DE, whereas SMA produces the least effective ones. When contrasted to PSO, SMA, and DE, the average time consumption of SIBAS is the shortest, whereas as the market dimension grows, its accuracy falls less than that of PSO, SMA, and DE. This implies that market size has a significant impact on SIBAS, PSO, SMA, and DE performance.

MATLAB Repository
The whole design and implementation of the computational approaches suggested in this paper may be seen on GitHub: https://github.com/SDMourtas/TV-TPNC (accessed on 5 January 2021).
There, we created a MATLAB repository for solving the TV-TPNC problem inline with Algorithm 1. The MATLAB repository includes thorough installation instructions along with a meticulous implementation of the real-world data applications mentioned in Section 4. Furthermore, anyone may draw conclusions from their own findings by providing the repository's main MATLAB function with their own data and adjusting the parameter values. Notice that the MATLAB repository's data comes from Yahoo Finance (https://finance.yahoo.com/) (accessed on 9 November 2021) and contains some of the market's most active stocks daily close prices.

Conclusions
The TV-TPNC problem is introduced in this paper as a NLP financial problem. The SIBAS algorithm for solving cardinality constrained NLP problems is introduced and then it is employed to solve the TV-TPNC problem. SIBAS effectiveness and accuracy have been demonstrated in two applications in different and somewhat large portfolio setups. In addition, SIBAS was compared to PSO, SMA, and DE, which are all popular meta-heuristics procedures. Based on our applications, we concluded that the SIBAS approach gives such a solution to the TV-TPNC problem, making it a very competitive option to PSO, SMA, and DE. The applications' findings reveal that the proposed procedure is accurate in two market configurations based on real-world data.
Some potential research areas can be identified.

1.
The SIBAS could be compared to other popular meta-heuristics approaches in larger portfolios and other financial portfolio optimization problems.

2.
The use of SIBAS in constraint optimization problems in different scientific domains.

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