Beetle swarm optimisation for solving investment portfolio problems

A portfolio model is established after analysing the investment environment of the artificial intelligence concept stocks in China. To reduce the risk of investment, the beetle swarm optimisation (BSO) is proposed. BSO, based on the beetle antennae search (BAS) and the standard particle swarm optimisation (PSO), is derived from the standard PSO but the update rules of each particle originate from BAS. In global searching, BSO, making the model get a lower value at risk, is more capable than standard PSO, which is easily trapped in local optimal defects. This study tries to solve portfolio model by using BSO algorithm. The results prove that BSO can do better in dealing with optimisation problems of constrained multi-dimensional functions.


Introduction
Artificial intelligence (AI) studies and develops theoretical methods for simulating and extending human intelligence. Due to the great success of deep learning, AI has recently attracted great attention from the scientific and industrial community. It is speculated that the combination of AI and traditional industries will trigger the fourth industrial revolution. The popularity of AI has effectively driven the capital market. Furthermore, the AI industry has become a hot spot for investment in recent years. The AI concept stocks of A-share, with a remarkable performance, are far more than the stock index gains. In 2017, the total financing amount of global AI investment reached US$8.9 billion.
Financial research focuses on how to allocate capital effectively and efficiently in the market. How to optimise capital allocation in a complex system full of uncertainty is the issue of the investment portfolio [1]. The mean-variance model proposed by Markowitz in 1952 marked the advent of portfolio theory. However, for the investment portfolio problem with constraints, it is often difficult to find an effective solution using traditional numerical optimisation solutions.
Nowadays, the rapid development of AI has been very helpful in dealing with this kind of problems [2][3][4][5][6][7]. The application of the particle swarm algorithm is a good example [8][9][10]. However, the biggest drawback of the particle swarm algorithm is that it is easily trapped in the local optimal solution during the search process. To rectify this defect, combining beetle antennae search (BAS) with particle swarm optimisation (PSO) together, the beetle swarm optimisation (BSO) algorithm is established in this paper to solve the AI concept stock portfolio problem [11][12][13].

Introduction
A portfolio is the set of assets that people choose to invest in. For most investors, choosing the satisfactory optimal portfolio is a sophisticated process, which requires one predicts precisely the tendency of the assets under consideration and defines what the optimal is. To put it simply, the optimal portfolio is the one that maximises the return. To reduce the risk of investment, Markowitz defined it as [14], a set of efficient portfolios, which maximises the expected return while minimising the fluctuation, especially a portfolio with the lowest fluctuation while having the highest return.

Establishment of a portfolio model
Suppose that the total investment is S; the proportion vector of investment of n stocks held by the entire portfolio, X = (x 1 , x 2 , …, x n ); the proportion of investment in risk-free assets (assumed as national debt), x 0 ; the variance-covariance matrix of the n AI concept stocks to be invested, σ. The buying price per share of the ith stoke is p i i = 1, 2, …, n , the rate of return of the ith stoke is y i i = 1, 2, …, n . So, the objective function of Markowitz's mean-variance model is (where the total risk of the entire portfolio is V) In China's stock market, the minimum trading unit of the stock is a single lot, and the number of trading volume is an integer. Suppose the turnover of the ith stoke is n i , with the restrictions n i ∈ I, I is a non-negative integer, i = 1, 2, …, n. Because China's stock market does not allow short selling behaviour, funds can only be invested in n types of stocks, and the remaining funds can be invested in risk-free assets. At the same time, transaction costs, including taxes and transaction fees, are important considerations in the financial market and necessary in trading. Take the Shanghai Stock Exchange as an example, transaction costs consist of the following expenses [15]: (1) The entrustment fee, 5 yuan/time.
(2) Commissions. After the transaction is completed, the investor pays the broker a fee of 3‰ of the transaction amount, starting at five yuan.
(3) Transfer fee. After the stock is traded, the cost of changing the account name is paid. The transfer fee for the transaction is 0.3‰ of the number of shares traded. There is no minimum charge requirement.
Then all transaction costs of risk securities are k 1 n i = 5, 100μ 1 n i p i ≤ 5 100μ 1 n i p i , 100μ 1 n i p i > 5 k 2 n i = 1, 100μ 2 n i ≤ 1 100μ 2 n i , 100μ 2 n i > 1 The transaction costs are C 0 , C i n i when the transaction costs for risk-free assets and transaction costs for the ith stock trading lots are n. Entrustment fee k 0 = 5, when the ith stoke lots is n i , the trading commission is k i n i . Commissions have a cost coefficient of μ i = 0.3%, the transfer fee is k 2 n i , the cost coefficient is In addition, the risk-free investment is a one-year National debt, the annual interest rate is y = 1.95%, and the transaction cost coefficient is μ 0 = 0.1%. The transaction fee for national debt is Based on it, the total transaction costs of the portfolio can be as follows: The expected rate of return at a time T is Y 0 (the higher the expected rate of return, the greater the risk) when the price of the ith stock is p i , and the rate of return is y i . Therefore, the constraint condition is Hence, we can finally get the portfolio model as

PSO algorithm principle
The PSO algorithm, based on the social behaviour metaphor, was put forward in 1995 by Eberhart and Kennedy [12]. It originated from the research on predatory behaviour of flock. The basic concept is individuals in a group share the information so that the whole group's movement will evolve from disorder to order in the problem-solving process and, ultimately, obtain the optimal solution to the problem. The PSO algorithm includes some parameters that have great impact on the algorithm performance, often stated as the exploration-exploitation tradeoff: exploration is the ability to test various regions and, hopefully, find a global optimum in the problem space.
The PSO algorithm simulates a bird in a flock by designing a massless particle. The particle has two properties: velocity v and position x, velocity represents the speed of movement, and position represents the direction of movement. Each particle individually searches for the optimal solution in the search space and records it as the extremum of the current individual P best . Then, the individual extremum is shared with other particles in the entire particle group, and the optimal individual extremum is defined as the current global optimal solution of the entire particle swarm G best . All particles in a particle swarm, based on their current individual extremum P best and the current global optimal solution G best shared by the entire particle swarm, adjust their own velocity and position variables [16][17][18]. The flowchart of the PSO is shown in Fig. 1.

BAS algorithm principle
The BAS algorithm, based on the foraging principle of the beetle, is a new technology to find the optimal solution proposed in 2017. When foraging, the beetle, not knowing the specific location of the food, uses two antennae to detect the odour of food and decides the direction of itself. Specifically, if the scent received by the left side of beetle is stronger than the right one, then, the beetle moves to the left, otherwise it moves to the right. Based on this simple principle, it can easily find food. Like the PSO, instead of knowing the specific formula, BAS uses an iterative approach to approximate the optimal solution step by step. In the BAS algorithm (see Fig. 2), there is only one individual.
The modelling steps are as follows: (1) The beetle head is assumed to be heading randomly toward any direction, so the direction of the vector from the right antenna to the left one must also be random. Accordingly, for an optimisation problem in an n-dimensional space, a random vector can be generated to represent and normalise it b = rands(k, 1) rands(k, 1) where k is spatial dimension and rand() is random function.
(2) Thus, the relationship between the left and right antennae can be obtained as follows: Moreover, x l , x r can be represented by the centroid where x l represents the left side of the search area, x r represents the right side.
(3) To determine the odour intensity of left and right antennae, substitute the left and right positions for f x l and f x r , where f x is the fitness function.
(4) In order to develop guidelines for the detection behaviour, this paper further generates the following iterative model, which detects odours by considering the search behaviour and iteratively updates the position of beetle x t represents the centroid coordinates at the tth iteration of the beetle, x lt represents left antenna coordinate at the tth iteration, x rt represents right antenna coordinate at the tth iteration. The step size at the tth iteration is δ t , sign x represents symbolic functions.

Establishment of BSO algorithm principle
2.5.1 Principle of BSO: As described in the previous two sections, BAS algorithm is aimed at individuals only and does not consider the connections between groups. PSO focuses on the impact of the population on a single particle, ignoring the particle's own judgment in the search process. Therefore, this paper proposes to integrate BAS and PSO models together, introducing the concept of BSO. Each particle in the PSO is characterised as a beetle and searches. The BSO constructed by this method can well overcome the problems of poor stability, tendency to fall into local optimum and others caused by the PSO algorithm [19]. The process of initial position and velocity of the beetle swarm is the same as that of the standard PSO. However, in the iterative process, the way of updating the position of the beetle swarm is no longer only relying on the historical best solution and the current global optimal solution of beetle individual, but adding the idea of Beetle Antennae Search. Individuals in the BSO will compare the fitness function values of their left and right sides during each iteration and compare the better values of the two, which can also be used to update the position of the beetle swarm. The updated formula for beetle swarm position can be expressed as follows [20]: where v i k + 1 represents the speed of the ith particle after the kth iteration, x i k + 1 indicates the position after the kth iteration, vb i represents the update rate generated by the BSO, and c 3 is the learning factor, sign is symbolic functions.
• By comparing the fitness of the current position of each beetle with P best and G best , the speed update rule is generated by the current individual optimal solution and the global optimal solution. • Combine the above two speed update rules to get the current update rules for speed of each antenna Current location update rules (16) • Updated learning factors and inertia weights c 1 , c 2 , c 3 , w, updated individual optimal solutions and global optimal solutions P best , G best . 4. After completing the iteration, the global optimal solution G best and f G best corresponding to the optimal solution position are obtained. The description is represented in Table 1.

Empirical analysis:
To test whether the BSO algorithm is more superior for solving the portfolio problem, this paper compares the BSO algorithm with the standard PSO algorithm and contrasts the value-at-risk obtained by the two in solving the portfolio and the number of iterations needed to achieve the convergence.

Data source and index selection:
To test the results of AI investment portfolio model by the BSO, the paper selects nine stocks from the AI concept stocks and the weekly rates of return from 23 June 2017 to 18 August 2017 (9 weeks). The calculated covariance matrix measures the risk of the nine stocks. Table 2 shows the covariance matrix. The yield and stock quotes select the weekly yield and price approximating the average of the 9-week return and the average price, which are shown in Table 3. The data used comes from the 'Wind' database. At the same time, one-year national debt is used as risk-free assets (a yield of 1.95%) on the assumption that a total of 1 million assets can be used for investment and no securities have been purchased before investment [21,22].

Parameter settings
In this paper, the trading lot number vector is used as the position variable of the particle and the beetle. PSO and BSO algorithms set the number of particles and beetles, a number of iterations set by the particle swarm and number of iterations set for the beetle swarm to 40, 8000 and 4000, respectively. The learning factors of PSO algorithm are set to c 1 = 0.5, c 2 = 2; the learning factors used by BSO algorithm, c 1 = 0.5, c 2 = 2, c 3 = 3; both inertia weights are the same, taking w = 0.9. Both the learning factors are timevarying. Penalty method is adopted to deal with constraint conditions [23] (see Table 4).

Results and discussion
To verify the effectiveness and the algorithm's performance, based on the weekly returns and prices of the nine stocks, PSO and BSO are used, respectively, setting the expected portfolio returns to 0.06, 0.08 and 0.10, respectively. The two algorithms solve the investment proportion of risk-free investment and stock investment in each case, as well as the value-at-risk under this ratio respectively. All the experiments are carried out with MATLAB 9.2.0.538062 (R2017a) running on a PC with Intel (R) Core (TM) i7-7700 CPU 3.60 GHz and 8.00 GB RAM on Win 10 operation system. Initialise the algorithm parameters, get the initial individual optimal solution and the global optimal solution P best ,G best Iteration While(End condition) { 1. Calculate the position of each beetle, the fitness x of left and right antennae. 2. According to the calculated fitness, produce the updated rules for the speed and position of each beetle. 3. Update the velocity v and position x of each beetle. 4. Update the learning factor, inertia weight, current individual optimal solution P best and the global optimal solution G best . }

Output
The global optimal solution position G best , fitness function f G best  From the results in Table 5, it can be noticed that, for different expected return rates, the value-at-risk calculated by BSO is lower than that of PSO. In another word, BSO can obtain relatively better results at the same expected rate of return. This shows that the BSO algorithm has a stronger global search ability, and the algorithm is easier to find the global optimal solution. On the other hand, when the expected rate of return increases, the risk values obtained by both algorithms increase, and the proportion of risk-free investment drops significantly, and that of high-yield stocks rises significantly. It shows that the investment portfolio model constructed in this paper is in line with the actual market conditions.
Figs. 3 and 4 show the convergence of the two algorithms. From the perspective of the convergence of the algorithm, PSO algorithm converges around 3000 iterations, and BSO algorithm only 1500 iterations approximately to converge. It shows that, compared with the standard PSO, after the concept of the beetle group is introduced, each particle's updating method no longer only relies on its own historical optimal solution and the group's global optimal solution. Instead, the particle's own independent judgment is added during each iteration, which makes the particle's iterative method more flexible and more intelligent, making the number of iterations needed for convergence less, and the result better.

Summary
In this paper, we introduced the concept of beetle swarm in the particle swarm algorithm and proposed the BSO. BSO is used to solve the investment portfolio problem of today's AI concept stocks. After empirical analysis, BSO shows greater global searching ability than that of standard PSO and it is easier to find the global optimal solution when solving multi-dimensional constraints problems.
In addition, in terms of algorithm convergence, by introducing the concept of BSO, the particle has its own judgment of the environment space in each iteration, so that the number of iterations required for the beetle to converge is less.  c 1 = 0.5, c 2 = 2 c 1 = 0.5, c 2 = 2, c 3 = 3 learning factor update method c 1 = 0.5 + 2 * t/t max c 1 = 0.5 + 2 * t/t max c 2 = 2 − 2 * t/t max c 2 = 2 − 2 * t/t max c 3 = 3 + 2 * t/t max inertia weight w = 0.9 w = 0.9 inertia weight update method w = 0.9 − 0.5 * t/t max w = 0.9 − 0.5 * t/t max