# Stock Portfolio Optimization Using a Combined Approach of Multi Objective Grey Wolf Optimizer and Machine Learning Preselection Methods

Authors: Nasrin Bagheri Mazraeh; Amir Daneshvar; Mahdi Madanchi zaj; Fereydon Rahnamay Roodposhti
Journal: Computational Intelligence and Neuroscience
 (2022)

---

## Abstract

The present paper deals with optimizing the stock portfolio of active companies listed on the Tehran Stock Exchange based on the forecast price. This paper is based on a combination of different filtering methods such as optimization of trading rules based on technical analysis (ROC, SMA, EMA, WMA, and MACD at six levels—Very Very Weak (VVW), Very Weak (VW), Weak (W), Strong (S), Very Strong (VS), and Very Very Strong (VVS)), Markov Chains, and Machine Learning (Random Forest and Support Vector Machine) Filter stock exchanges and provide buy signals between 2011 and 2020. In proportion to each combination of filtering methods, a buy signal is issued and based on the mean-variance (M-V) model, the stock portfolio is optimized based on increasing the portfolio return and minimizing the stock portfolio risk. Based on this, out of 480 companies listed on the Tehran Stock Exchange, 85 active companies have been selected and stock portfolio optimization is based on two algorithms, MOGWO and NSGA II. The analysis results show that the use of SVM learning machine leads to minor correlation error than the random forest method. Therefore, this method was used to predict stock prices. Based on the results, it was observed that if the shares of companies are filtered, the risk of transactions decreases, and the return on the stock portfolio increases. Also, if two filtering methods are applied simultaneously, the stock portfolio returns slightly and the risk increases. In the analysis, MOGWO algorithm has obtained 133.13% stock return rate with a risk of 3.346%, while the stock portfolio returns in NSGA II algorithm 107.73, with a risk of 1.459%. Comparison of solution methods shows that the MOGWO algorithm has high efficiency in stock portfolio optimization.


---

## Body

## 1. Introduction

Investment is defined as the investment of money to obtain additional or certain benefits relative to money. In addition to providing benefits (returns), the investment also has a risk borne by the investor. The higher the rate of return expected by an investor, the higher the risk to be covered by the investor [1]. The level of risk can be minimized at a certain rate of stock portfolio expectations by forming an appropriate portfolio. Therefore, stock portfolio optimization has an important role in determining investment portfolio strategies for investors. What investors hope to achieve through portfolio optimization is to maximize stock portfolio returns and minimize stock portfolio risk. Because returns vary based on risk, investors need to balance the contrast between risk and return on their investment. Therefore, there is no optimal basket that can satisfy all investors. The optimal portfolio is determined by the risk preferences and return of the investor [2].Based on this, many researchers have analyzed financial data and portfolio optimization because the financial market is full of uncertainty. For example, because of government policies, the global economy, social activities, psychology, and many assets such as stocks, futures, and options, the nonlinear nature and dynamics with high internal dependence have led to the challenge of researchers [3, 4]. The extreme sensitivity of the stock market to political and economic changes and the unstable and nonlinear properties of financial time series have made market forecasting challenging [5–7]. Also, drastic changes in prices and markets at different times require more attention and quick reactions to these changes [8].Given the importance of investing in portfolio optimization, in 1952, Markowitz proposed a popular model called the mean-variance (M-V) model for stock portfolio weight [9, 10]. Given the expected value at risk (VaR), the M-V model can be used to find the best portfolio that can maximize return on investment (ROI) and reduce their risks. Due to the large number of listed companies, it is impossible to optimize the stock portfolio with normal methods and there is a possibility of increasing the stock portfolio risk. Due to severe market fluctuations, new research on portfolio optimization in recent years has used the H&B method to optimize its portfolio [11]. In this method, regardless of market fluctuations, shares of listed companies are purchased and held until the end of the investment period. Although this method reduces the risk of investing, there is no expectation of high return on investment.Researchers, considering the higher investment risk used different methods to receive the buy, hold, or sell signal. These methods include machine learning models, time series, Markov chains, meta-heuristic algorithms, and so on. Different models of stock price forecasting, considering the high computational ability, offer the best combination of stock portfolio optimization by considering lower risks [12]. In these methods, stock transactions are reviewed based on existing theories and based on the training provided, the best time to enter or exit the market is presented. As a result, the risk of the transaction refers to the risk arising from the time of the transaction. This is the time due to an error in estimating future price movements, which causes the trader to place his or her order at the desired price based on his or her predictions, and faces the risk of not fulfilling the order at the desired price. In this case, it has to trade at a more unfavorable price than the market price at the time of ordering [13]. Therefore, there is always an exchange between cost and ordering risk in executing an order. This is an issue that has been described as a trade-off [14]. Therefore, balancing the market reaction cost with the opportunity cost risk requires designing trading strategies. In choosing a trading strategy, the investor, in addition to adjusting his or her preferences, must be prepared to change and adapt the strategy to changing market conditions. The task of designing an optimal transaction strategy is complex because it requires decisions about the best way to split the order, the investor’s entry point in order execution, the choice of order type, and how to measure transaction performance. In the past, the task of designing a trading strategy was usually the responsibility of experts (humans), but with the increase in the number of decisions, an automated approach is needed. Therefore, the method must be dynamic and responsive to market conditions in real time [15].According to market theory, investors cannot predict stock prices and market conditions based on past information [16]; therefore, they should quickly identify the information that affects the stock price and adjust their prices according to the information. It is impossible to control a large number of stocks at the same time. Therefore, market information must be transmitted through various filter processes and signals of purchase, sale, or maintenance [17–19]. Efficient market theory does not rule out the possibility of repetitive and short-term patterns. If these hidden patterns can be identified before they occur, the market’s future can be accurately predicted. Many projects have been undertaken to forecast financial markets. Some of these studies have used soft computing techniques such as genetic algorithms, neural networks, and fuzzy systems. Researchers therefore use sophisticated methods to reduce prediction error. Price forecasting in financial markets is an attractive topic of interest for market participants, both personal and institutional investors. Investment in today’s world faces major challenges that the methods of selecting and forming the appropriate portfolio algorithmically can address these challenges.In this paper, due to the importance of considering risk in investment, stock portfolio optimization with the aim of increasing eleven portfolios and reducing the risk of investing in the portfolio simultaneously on the shares of companies listed on the Tehran Stock Exchange is discussed. According to the information contained in the information site of the Tehran Stock Exchange Technology Management Company (TSETMC), there are 480 companies listed on the Tehran Stock Exchange between 2011 and 2020. Therefore, in this article, we first filter the active companies based on three categories of input information such as 8 technical variables (final price, number of buyers, number of transactions, trading volume, daily trading value, company day value,P/E ratio, and number of shares Per company), 7 fundamental variables (old design coin price, new design coin, dollar, index, gold, oil, euro), And the time series of the final price of the last 10 days of each share is considered and companies that have traded at least one day per month. The importance of market price forecasting has also led to different ways of filtering and presenting buy signals such as filtering “Optimization of trading rules based on technical analysis (Trading Rule Filter),” “Optimization of a strong trading system using Markov chain (Markov Model Filter),” and “Optimize and predict stock returns based on Predict Model Filter methods.” In Trading Rule Filter, 6 indicators RSI, ROC, SMA, EMA, WMA, and MACD in six levels, very very weak (VVW), Very weak (VW), Weak (W), Strong (S), Very Strong (VS), and very very strong (VVS) has been used. In the Predict Model Filter of data training, machine learning methods (random forest method and processing vector machine) are used. After determining the buy signal, the MOGWO and NSGA II algorithms for stock portfolio optimization based on the M-V model are discussed and the average stock portfolio return as well as the average stock portfolio risk are examined and compared.Based on the presented issue, the innovations of the paper can be summarized as follows:(i)
Using three filters for buy signal such as “Optimization of trading rules based on technical analysis (Trading Rule Filter),” “Optimization of a strong trading system using Markov chain (Markov Model Filter),” and “Optimize and predict stock returns based on Predict Model Filter methods”(ii)
Using M-V model to portfolio optimizing(iii)
Using MOGWO and NSGA II algorithms to optimization M-V modelIn the M-V model presented in this research, it is possible to simultaneously maximize stock portfolio profit and minimize investment risk, and the use of Meta heuristics algorithms leads to the optimization of the objective functions of the M-V model and the achievement of a various investment set.The structure of the paper is as follows. In the second part, the background of research related to stock portfolio optimization and stock portfolio risk is discussed. In the third part, a multi-objective stock portfolio selection and optimization model based on technical process, Markov decision-making and learning machine is presented, and a two-objective model for stock portfolio optimization is presented. In the fourth section, the results of the implementation of the approach on the data of listed companies operating in Iran are analyzed and presented. In the fifth section, conclusions and future recommendations of the research are presented.


## 2. Literature Review

Research conducted in foreign markets using a combination of different strategies to support foreign market optimization algorithms shows promising results. On the other hand, there are different approaches to evolutionary computing strategies, and machine learning algorithms, which include neural networks, genetic algorithms, and support vector machine algorithms. In research on financial market forecasting of artificial intelligence algorithms including artificial neural networks [20–23], recursive neural networks [24], genetic algorithms with neural networks, artificial [25, 26] and support vector neural networks [27] have been used. Quek et al. [28] proposed the use of fuzzy neural network (GenSoFNN) as a tool for stock portfolio balancing, which uses a supervised learning method to detect milestones in the stock price cycle and a modified weighted regression algorithm used to smooth the stock cycle. Hsu et al. [29] used Markov chains and fuzzy theory to create a stock market index forecasting model. Following the validation of the data, the results show not only the ability to improve the return on investment but also the prevention of losses. Chiu and Chian [30] designed new functional genetic algorithms to select investment targets based on stock price regardless of whether the stock market index is declining. This method can achieve sustainable returns. Leu and Chiu [31] described integrated genetic algorithms and pattern search methods for capital allocation and stock selection. Such experiments with the usual selection methods lead to good results with the roulette wheel method. Dastkhan et al. [32] used fuzzy time series to predict return on investment and then genetic algorithms to identify the optimal investment strategy. Experimental results showed this method for the performance of 60 Taiwanese market indices. Sefiane and Benbouziane [33] in a paper entitled Portfolio Selection Using Genetic Algorithm used the genetic algorithm on a simple example containing 6 shares. They note that the results are interesting and confirm the efficiency of the genetic algorithm for its rapid convergence to a better solution, as well as the computational time. Van de Vrande [34] by examining the effects of portfolio diversity on performance results and the conditions in which diversity is likely to occur and using a data set of strategic investments by pharmaceutical companies showed that the variance is in the relative technology proximity between the central company. And, its partners show the inverted relationship of U-shape with innovative performance, which is influenced by the diversity of external source modes used in the portfolio. Abounoori et al. [35] in a study entitled Predicting Fluctuations in the Tehran Stock Exchange with Markov GARCH approach evaluated several GARCH models in relation to their ability to predict fluctuations in the Tehran Stock Exchange. Chen and Hao [36] provide a technical analysis of a set of technical characteristics such as moving average and exponential moving average and convergence-divergence mean motion and volume ratio and relative power index and volume level and acceleration index for prediction with learning algorithms. Basak et al. [37] presented a stock market forecast using random forest. An empirical classification framework for stock price prediction, given the previous day's price increase or decrease, facilitates this relationship by using random forests and decision trees. Molchanov and Romasheva [38]. In order to achieve the goals and maximize profitability, companies suggested that indicators should be created for a balanced portfolio, which would allow portfolios to be evaluated and current and potential projects ranked to create flexibility with minimal risk. They analyzed modern approaches and benchmarking firms for portfolio management, current industry situation, identified risks, and indicators for evaluation. Chang and Young [39] in a study investigated the optimization of the stock portfolio by exploiting the cause-and-effect relationships of return and bias in behavioral stocks according to the return of the behavioral stock retention period. By mimicking real investment constraints, including test costs and statistical evidence, they found that by including short selling in stock portfolio selection, the investment flexibility available and the stock portfolio outperformed the benchmarks and the market. Jiang et al. [40] proposed a stock index forecasting model using deep learning algorithms. This input model of technical indicators along with macroeconomic indicators was used to forecast the stock price index on a monthly basis. Chowdhury et al. [41] presented stock price forecasting using the Black Scholes pricing model and machine learning. Different algorithms such as decision tree, machine learning method, and neural network have been used. Pungetmongkol et al. [44] examined the performance of a balanced portfolio and a shopping cart for five different market trends: uptrends, downtrends, and market sideways. They considered three asset classes, namely, equity, bonds, and gold, determined the initial weight of the portfolio using the Markowitz method, and used geometric Brownian motion to simulate prices.Bigerna et al. [43], considering the amount of oil imports and the risk associated with this amount, introduced a new approach to the concept of energy security, which from the perspective of the portfolio theory to examine these issues, from the perspective of four major Asian energy importers; Used by China, Japan, Korea and Taiwan. Wang et al. [44] proposed a reinforcement learning method for optimizing investment policy. To address the problem of balance of risk and return, they proposed a model that uses macro market conditions as a dynamic indicator to adjust the ratio between short and long funds to reduce the risk of market fluctuations. Óskarsson [45] conducted a study aimed at retesting theories and analyzing the impact of risk management tools on different collections, focusing on investing in Iceland, where stock price fluctuations and foreign exchange rates can change portfolio returns over time. And affect investor profitability. dos Santos et al. [46] conducted a study to identify which tools and techniques are more appropriate for the strategic selection and alignment of projects and the balance of the project portfolio. Papavasiliou and Bertrand [47] in a study aimed at developing a methodology that demonstrates the consequences of a balanced European market that undergoes a fundamental transformation through multiple market design schemes. Their method relies on analytical insights that can be obtained under the assumption of pricing behavior. They used a simulation model that demonstrates the European equilibrium market as a Markov decision-making process to confirm this. Hernandez-Vega [48] studied how the unexpected announcements of US monetary policy affect the inflow of foreign investment. They used a new set of data on debt and net daily flows. The results showed that both equity and liabilities reacted immediately to announcements, especially bad news. Sawik [49] proposed a model with the aim of determining the optimal investment in cyber security under a limited budget and a set of security controls for each supply chain node to balance cyber security throughout the supply chain. Using lattice conversion, together with Taylor’s first series estimation of natural logarithm, they approximated a nonlinear stochastic hybrid optimization model with its linear equivalent. Some authors have used meta-heuristic algorithms to optimize the portfolio, such as the HI algorithm [50], WOA algorithm [51, 52], ICA-FA algorithm [53], GWO algorithm [54, 55], and the IWO algorithm [56].According to the research background, it can be said that different methods have been used to optimize the stock portfolio and reduce the risk of the investment portfolio. However, there is no comprehensive model that uses both learning machines (random warfare and processing vector machines) and the Markov decision-making process for training and NSGA II and MOGWO algorithms for data testing.


## 3. Problem Definition and Solving Method

In this section, the paper optimizes the stock portfolio of stock companies based on the Markowitz mean-variance model. The main purpose of this section is to provide a model to increase the rate of return on the stock portfolio and reduce investment risk. For this purpose, the companies listed on the stock exchange have been studied. Since investing in all stocks of listed companies is impossible and the risk of investing in them is high, in this section, some of the listed companies are first filtered using predefined rules. The reason for this is to focus on companies that can be traded at least once a month. In order to filter active companies from other companies, three types of input data are used according to Figure1:(1)
Eight technical variables (final price, number of buyers, number of transactions, trading volume, value of daily transactions, daily value of the company,P/E ratio, and number of shares of each company)(2)
Fundamental variables (old design coin price, new design coin, dollar, index, gold, oil, euro)Figure 1
Proposed model general market timing.


## 4. Time Series of the Final Price of the Last 10 Days of the Share per Month

The existence of different fundamental variables leads to an impact on stock prices, and therefore these variables are very effective in determining the purchase, maintenance, or sale of shares. Due to the existence of two different types of coins in Iran with different prices, in this section the term old and new design has been used.According to the three decision variables, the following techniques have been used to filter the studied shares of stock exchange companies based on the buying and selling signals of low-yielding companies:(i)
Optimization of trading rules based on technical analysis (Trading Rule Filter)(ii)
Optimize a robust trading system using the Markov Model Filter(iii)
Optimization and prediction of stock returns based on machine learning methods (Predict Model Filter)The following is a description of each of the filters based on receiving a buying signal and eliminating low-yield companies:


### 4.1. Technical

Technical analysis is a business discipline that is used to evaluate investments and identify trading opportunities by analyzing the statistical trends collected from trading activities, such as price and volume movements. Technical analysis often uses a variety of chart tools to generate short-term trading signals, and it can also help improve the valuation of the strength or weakness of a security over a wider market or segment. This information helps analysts improve their overall valuation estimate. In technical methods, disabilities can be considered as signposts for a route. This paper out of 6 indicators RSI, ROC, SMA, EMA, WMA and MACD in six levels Very Very Poor (VVW), Very Poor (VW), Weak (W), Strong (S), Very Strong (VS) and Very Very Strong (VVS) is used to filter stock companies. According to Figure2, if at least 3 of the indicators issue a buying signal, that share of the company will be considered for the next day’s purchase.Figure 2
Performance of the technical rule to provide a buying signal.


### 4.2. Markov Chain

A Markov process is a stochastic process that satisfies the Markov property (sometimes characterized as “memorylessness”). In simpler terms, it is a process for which predictions can be made regarding future outcomes based solely on its present state and—most importantly—such predictions are just as good as the ones that could be made knowing the process’s full history. In other words, conditional on the present state of the system, its future and past states are independent. A Markov chain is a type of Markov process that has either a discrete state space or a discrete index set (often representing time), but the precise definition of a Markov chain varies. For example, it is common to define a Markov chain as a Markov process in either discrete or continuous time with a countable state space (thus regardless of the nature of time), but it is also common to define a Markov chain as having discrete time in either countable or continuous state space (thus regardless of the state space).The system’s state space and time parameter index need to be specified. Table1 gives an overview of the different instances of Markov processes for different levels of state space generality and for discrete time v. continuous time.Table 1
Different examples of Markov processes for different levels.
Countable state spaceContinuous or general state spaceDiscrete-time(Discrete-time) Markov chain on a countable or finite state spaceMarkov chain on a measurable state space (for example, Harris chain)Continuous-timeContinuous-time Markov process or Markov jump processAny continuous stochastic process with the Markov property (for example, the Wiener process)Note that there is no definitive agreement in the literature on the use of some of the terms that signify special cases of Markov processes. Usually the term “Markov chain” is reserved for a process with a discrete set of times, that is, a discrete-time Markov chain (DTMC), but a few authors use the term “Markov process” to refer to a continuous-time Markov chain (CTMC) without explicit mention. In addition, there are other extensions of Markov processes that are referred to as such but do not necessarily fall within any of these four categories. Moreover, the time index need not necessarily be real-valued; like with the state space, there are conceivable processes that move through index sets with other mathematical constructs. Notice that the general state space continuous-time Markov chain is general to such a degree that it has no designated term.While the time parameter is usually discrete, the state space of a Markov chain does not have any generally agreed-on restrictions: the term may refer to a process on an arbitrary state space. However, many applications of Markov chains employ finite or countably infinite state spaces, which have a more straightforward statistical analysis. Besides time-index and state-space parameters, there are many other variations, extensions, and generalizations. For simplicity, most of this article concentrates on the discrete-time, discrete state-space case, unless mentioned otherwise.According to the contract, we assume that there is always the next case and as a result the process continues forever. According to this method, groups of data similar to today’s data are examined based on the time series of the data in question and the amount of increase or decrease of the average price is calculated. Therefore, based on the current day price and the forecast for the next day price, a buy signal will be issued.


### 4.3. Machine Learning

Machine learning is the scientific study of statistical algorithms and models used by computer systems that use patterns and inference to perform tasks instead of using explicit instructions. It is a science that allows computers to learn a particular subject without the need for an explicit program. As a subset of artificial intelligence, machine learning algorithms create a mathematical model based on sample data or “training data” for predicting or making decisions without obvious planning. The goal of machine learning is for computers and systems to be able to perform their tasks gradually and with increasing data. The scope of this task can range from automatic face recognition by seeing a few examples of the desired face to learning how bipedal robots walk by receiving a stock buy signal. The range of research that can be done on machine learning is wide. Theoretically, researchers believe that they should create new learning methods and study the feasibility and quality of learning for their methods, and on the other hand, some researchers try to apply machine learning methods to new problems. Of course, this spectrum is not discrete and the researches have components of both approaches. Machine learning helps a lot in saving operating costs and improving the speed of data analysis.In this paper, two different types of machine learning methods based on support vector machine (SVM) and random forest (FR) are used. The machine learning method, in addition to filtering company stocks, also issues a buy/hold/sell signal for the next day. Also, in the vector machine processing method, 20 similar basic learning models have been used to reduce the prediction error. In the following, each of the mentioned methods is described.


### 4.4. Random Forest

Random forest or random forests (RF) is a combination learning method for classification, regression, which is based on a structure consisting of a large number of decision trees, on the training time and output of classes (classification) or for each tree predictions. They work in a separate form. Random forests are suitable for decision trees that are overfitted in the training complex. Random forest performance is usually better than the decision tree, but this performance improvement depends in part on the type of data. Stochastic forest is a supervised learning algorithm. As the name implies, this algorithm builds a forest randomly. The “forest” created is actually a group of “Decision Trees.” The construction of the forest using trees is often done by the method of “bagging.” The main idea of the bagging method is that a combination of learning models enhances the overall results of the model. Simply put, a random forest decides several trees and merges them together to make more accurate and consistent predictions. One of the advantages of random forest is that it can be used for both classification and regression problems, which make up the majority of current machine learning systems. Here, the function of random forest for “classification” will be described, as classification is sometimes considered the building block of machine learning. Random forest adds added randomness to the model as trees grow. Instead of searching for the most important properties when splitting a “node,” the algorithm looks for the best properties among a random set of properties. This leads to a lot of variety and ultimately a better model. Thus, in a random forest, only one subset of features is considered by the algorithm to split a node. By increasing the random threshold for each attribute instead of searching for the best possible threshold, trees can be made even more random. Figure3 shows the random forest method made of a tree.Figure 3
Random forest performance.


### 4.5. Support Vector Machine

Support vector machine (SVM) is one of the supervised learning methods used for classification and regression. This method is one of the relatively new methods that have shown good performance in recent years compared to older methods for classification. The basis of SVM classifier work is linear classification of data, and in linear segmentation of data we try to choose the line that has the most reliable margin. Solving the optimal line finding equation for data is done by QP methods, which are known methods for solving constrained problems. One of the methods that are currently widely used for the classification problem is the support vector machine (SVM) method. Perhaps, the current popularity of the support vector machine method can be compared to the popularity of neural networks over the past decade. The reason for this is the ability to use this method to solve various problems, while methods such as the decision tree cannot be easily used in various problems. The vector machine often uses binary classification. It is assumed that there is anL observation that each observation consists of pairs in which there is an input vector and a two-state value (1− or +1). The idea of a backup vector machine tries to draw hyperpages in space that optimally differentiate samples of different data classes.In this paper, after using a combination of the above methods to filter the stocks of listed companies, the Markowitz mean-variance model is used to optimize the stock portfolio. In this model, from the acceptedN companies, m companies are selected to optimize the stock portfolio. The main goal is to determine the percentage of investment in each company Wi,i∈m. To determine the exact amount of investment, two objective functions are considered in accordance with equations (1) and (2). In relation (1), the goal of maximizing the stock portfolio based on the projected profit Ritpredict,i∈m and in relation (2) the goal of minimizing investment risk or in other words minimizing the covariance between the two shares of the company covij,i,j∈m. The investment must be made in such a way that in accordance with equation (3) the total volume of transactions does not exceed 1.(1)maxμp=∑i=1mRitpredict.Wi,(2)minRisk=∑i=1m∑j=1mcovijWiWj,s.t.:(3)∑i=1mWi=1,(4)Wi≥0.According to the Markowitz model, NSGA II and MOGWO algorithms have been used to optimize the stock portfolio based on the two mentioned objective functions. In the following, the mentioned solution methods are presented.


### 4.6. NSGA II Algorithm

One of the most efficient and well-known multi-objective optimization algorithms is the NonDefeatable Genetic Algorithm II (NSGA II). This algorithm is one of the fastest and most powerful optimization algorithms that have less operational complexity than other methods. This algorithm comes to the conclusion that it has an optimal range in terms of changing the objective functions and gives the designer the freedom to choose her desired design from among the optimal designs. In NSGA II, the preservation of elitism and dispersion is considered simultaneously. The selection of a new population in each step of this method is based on the principle of dominance, and using elitism and population ranking in each step of the solution, the best undefeated answers are selected and they go to the next step.If there are two maximization objective functionsf1 and f2, then for the two answers x and y, the answer x beats the answer y if we have f1x≥f1y and f2x≥f2y or f1x>f1y and f2x>f2y. Also, in order to observe the proper distribution of the density of the answers in this algorithm, a concept called congestion distance is used. In general, to sort a population of size n based on nondefeat levels, each answer is compared to all the other answers in the population to determine if that answer is defeated. Finally, there are a number of solutions, neither of which overcomes each other, so these solutions form the first boundary of the invincible boundary. These answers are passed to set F1. To determine the answers in the next boundaries, the answers in the first boundary are temporarily ignored and the above process is repeated; this time the answers are transferred to the F2 set and take second place. This process continues for all the unanswered answers of the population. One of the criteria of the evolutionary algorithm in order to reach the optimal Pareto boundary is to maintain the variety and breadth of the answers in the set of obtained answers. In fact, arranging nondefeats is a procedure in order to achieve better answers and the mechanism of diversity also seeks to maintain diversity and breadth in these answers. In this algorithm, this is done by swarming distance in this way. The smaller the swarming distance of an answer, the greater the density of answers around it. For the next step, select the answers that are in the area with less density or in other words with more congestion distance. This increases the diversity and dispersion of the obtained answers. The purpose of using congestion spacing in NSGA II is to create diversity in population responses and to indicate the density of responses alongside a specific response. Figure 4 also shows the pseudo code of NSGA II algorithm in stock portfolio optimization. The swarm interval for the ordered answers is ascending and specific to set F is obtained from.(5)CDX1=CDXS=∞,CDXi=Z1Xi+1−Z1Xi−1Z1XS−Z1X1+Z2Xi+1−Z2Xi−1Z2XS−Z2X1,i=2,…,S−1.Figure 4
NSGA II algorithm pseudocode in stock portfolio optimization.In the above relation,CDXi is the amount of congestion distance for the answer Xi. After merging the parent-child population, the undefeated sorting is performed and Steps 7 and 8. Based on Step 10, the swarm distance criterion is used to create a subset of the last undefeated set due to the subsequent increase in population size:Step 1.
Create the initial populationP0 of size N with random answers and set t=0,Step 2.
If the stop condition is not met, return toPt,Step 3.
Using the binary selection operator, selectN parents from the population Pt,Step 4.
By applying the intersection and mutation operators on the populationPt, generate the population of Qt children to size N,Step 5.
SetRt=Pt∪Qt,Step 6.
Use the invincible ranking method to determine the ParetoFi sets in the Rt population,Step 7.
SetPt+1=∅ و i=1,Step 8.
UntilPt+1+Fi<N:(a)
Add the answers of the setFi to the population Pt+1, and(b)
Puti=i+1.Step 9.
Arrange theFi set answers in descending order of congestion,Step 10.
SizeN−|Pt+1| Transfer from the first answers Fi to the population Pt+1, andStep 11.
Sett=t+1 and return to Step 2.


### 4.7. MOGWO Algorithm

The MOGWO like the NSGA II is a population-based algorithm based on the behavior of gray wolves. In this method, each wolf is introduced as an initial solution (determine the exact amount of investment) which aims to achieve the initial solution that has the highest expected profit and the lowest investment risk. From the MOGWO algorithm based on the equations discussed below; it changes the random response generated in each iteration, which improves the objective functions. Finally, the best initial solution is known as Alpha Wolf, and the result is the highest expected profit and the lowest investment risk. The gray wolf Canis Iupus belongs to the Candidate family. Gray wolves are predators at the top of the food pyramid, meaning they are at the top of the food chain. Gray wolves mostly prefer to live in groups. The average group size is 5–12 wolves. Leaders consist of a male and a female called Alpha. Alpha is primarily responsible for decisions about hunting, where to sleep, when to wake up, and so on. Alpha decisions are communicated to the group; however, some democratic behaviors have also been observed in which an Alpha follows the other wolves in the group. In communities, the whole herd endorses Alpha. Alpha wolf is also known as the dominant wolf, because the commands must be executed by the group. Alpha wolves are only allowed to mate in the herd. It is important to note that Alpha is not necessarily the strongest member of the herd, but the best member in terms of management in the herd. The second level in the gray wolf hierarchy is Beta. Beta are wolves that help Alpha make decisions or other herd decisions. The Beta wolf can be male or female, and he or she is the best replacement for Alpha in the event of his death or aging. Beta executes Alpha commands across the herd and gives feedback to Alpha. The Omega wolf is the lowest class in the gray wolf hierarchy. The Omega Wolf plays the victim. Omega wolves usually have to follow all the high-level and dominant wolves. They are the last wolves allowed to eat. If the wolf is not an Alpha or Omega, it is called a Delta. Delta wolves must be subject to Alpha and Beta. However, they dominate Omega. Figure5 also shows the pseudo code of MOGWO algorithm in stock portfolio optimization. In mathematical modeling of wolf social hierarchy, α Alpha is considered as the most appropriate solution. Subsequently β Beta and δ Delta are the second and third most suitable solutions, respectively. The rest of the candidate solutions are assumed to be Omega X. To hunt, gray wolves must find and surround their prey. Therefore, the following equations update the wolves’ positions around the prey.(6)D⟶=C⟶.Xp⟶t−X⟶t,(7)X⟶t+1=X⟶t−A⟶.D⟶.Figure 5
MOGWO algorithm pseudo-code in stock portfolio optimization.In the above relationsC⟶ and A⟶ are coefficient vectors. Xp⟶ is the hunting position vector and X⟶ is the gray wolf position vector. This is an equilibrium equation between siege and hunting. Therefore, the search radius must be optimized during the process. For this purpose, the equations related to the two coefficients used in the above relations are as follows.(8)A⟶=2a⟶.r1⟶−a⟶,(9)C⟶=2r2⟶.The above equations enable the gray wolves to update their position around the prey. As a result, the following equations are used to hunt.(10)D⟶α=C⟶1.X⟶α−X⟶,D⟶β=C⟶2.X⟶β−X⟶,D⟶δ=C⟶1.X⟶δ−X⟶,(11)X⟶1=X⟶α−A⟶1.D⟶α,X⟶2=X⟶β−A⟶2.D⟶β,X⟶3=X⟶δ−A⟶3.D⟶δ,(12)X⟶t+1=X⟶1+X⟶2+X⟶33.


## 4.1. Technical

Technical analysis is a business discipline that is used to evaluate investments and identify trading opportunities by analyzing the statistical trends collected from trading activities, such as price and volume movements. Technical analysis often uses a variety of chart tools to generate short-term trading signals, and it can also help improve the valuation of the strength or weakness of a security over a wider market or segment. This information helps analysts improve their overall valuation estimate. In technical methods, disabilities can be considered as signposts for a route. This paper out of 6 indicators RSI, ROC, SMA, EMA, WMA and MACD in six levels Very Very Poor (VVW), Very Poor (VW), Weak (W), Strong (S), Very Strong (VS) and Very Very Strong (VVS) is used to filter stock companies. According to Figure2, if at least 3 of the indicators issue a buying signal, that share of the company will be considered for the next day’s purchase.Figure 2
Performance of the technical rule to provide a buying signal.


## 4.2. Markov Chain

A Markov process is a stochastic process that satisfies the Markov property (sometimes characterized as “memorylessness”). In simpler terms, it is a process for which predictions can be made regarding future outcomes based solely on its present state and—most importantly—such predictions are just as good as the ones that could be made knowing the process’s full history. In other words, conditional on the present state of the system, its future and past states are independent. A Markov chain is a type of Markov process that has either a discrete state space or a discrete index set (often representing time), but the precise definition of a Markov chain varies. For example, it is common to define a Markov chain as a Markov process in either discrete or continuous time with a countable state space (thus regardless of the nature of time), but it is also common to define a Markov chain as having discrete time in either countable or continuous state space (thus regardless of the state space).The system’s state space and time parameter index need to be specified. Table1 gives an overview of the different instances of Markov processes for different levels of state space generality and for discrete time v. continuous time.Table 1
Different examples of Markov processes for different levels.
Countable state spaceContinuous or general state spaceDiscrete-time(Discrete-time) Markov chain on a countable or finite state spaceMarkov chain on a measurable state space (for example, Harris chain)Continuous-timeContinuous-time Markov process or Markov jump processAny continuous stochastic process with the Markov property (for example, the Wiener process)Note that there is no definitive agreement in the literature on the use of some of the terms that signify special cases of Markov processes. Usually the term “Markov chain” is reserved for a process with a discrete set of times, that is, a discrete-time Markov chain (DTMC), but a few authors use the term “Markov process” to refer to a continuous-time Markov chain (CTMC) without explicit mention. In addition, there are other extensions of Markov processes that are referred to as such but do not necessarily fall within any of these four categories. Moreover, the time index need not necessarily be real-valued; like with the state space, there are conceivable processes that move through index sets with other mathematical constructs. Notice that the general state space continuous-time Markov chain is general to such a degree that it has no designated term.While the time parameter is usually discrete, the state space of a Markov chain does not have any generally agreed-on restrictions: the term may refer to a process on an arbitrary state space. However, many applications of Markov chains employ finite or countably infinite state spaces, which have a more straightforward statistical analysis. Besides time-index and state-space parameters, there are many other variations, extensions, and generalizations. For simplicity, most of this article concentrates on the discrete-time, discrete state-space case, unless mentioned otherwise.According to the contract, we assume that there is always the next case and as a result the process continues forever. According to this method, groups of data similar to today’s data are examined based on the time series of the data in question and the amount of increase or decrease of the average price is calculated. Therefore, based on the current day price and the forecast for the next day price, a buy signal will be issued.


## 4.3. Machine Learning

Machine learning is the scientific study of statistical algorithms and models used by computer systems that use patterns and inference to perform tasks instead of using explicit instructions. It is a science that allows computers to learn a particular subject without the need for an explicit program. As a subset of artificial intelligence, machine learning algorithms create a mathematical model based on sample data or “training data” for predicting or making decisions without obvious planning. The goal of machine learning is for computers and systems to be able to perform their tasks gradually and with increasing data. The scope of this task can range from automatic face recognition by seeing a few examples of the desired face to learning how bipedal robots walk by receiving a stock buy signal. The range of research that can be done on machine learning is wide. Theoretically, researchers believe that they should create new learning methods and study the feasibility and quality of learning for their methods, and on the other hand, some researchers try to apply machine learning methods to new problems. Of course, this spectrum is not discrete and the researches have components of both approaches. Machine learning helps a lot in saving operating costs and improving the speed of data analysis.In this paper, two different types of machine learning methods based on support vector machine (SVM) and random forest (FR) are used. The machine learning method, in addition to filtering company stocks, also issues a buy/hold/sell signal for the next day. Also, in the vector machine processing method, 20 similar basic learning models have been used to reduce the prediction error. In the following, each of the mentioned methods is described.


## 4.4. Random Forest

Random forest or random forests (RF) is a combination learning method for classification, regression, which is based on a structure consisting of a large number of decision trees, on the training time and output of classes (classification) or for each tree predictions. They work in a separate form. Random forests are suitable for decision trees that are overfitted in the training complex. Random forest performance is usually better than the decision tree, but this performance improvement depends in part on the type of data. Stochastic forest is a supervised learning algorithm. As the name implies, this algorithm builds a forest randomly. The “forest” created is actually a group of “Decision Trees.” The construction of the forest using trees is often done by the method of “bagging.” The main idea of the bagging method is that a combination of learning models enhances the overall results of the model. Simply put, a random forest decides several trees and merges them together to make more accurate and consistent predictions. One of the advantages of random forest is that it can be used for both classification and regression problems, which make up the majority of current machine learning systems. Here, the function of random forest for “classification” will be described, as classification is sometimes considered the building block of machine learning. Random forest adds added randomness to the model as trees grow. Instead of searching for the most important properties when splitting a “node,” the algorithm looks for the best properties among a random set of properties. This leads to a lot of variety and ultimately a better model. Thus, in a random forest, only one subset of features is considered by the algorithm to split a node. By increasing the random threshold for each attribute instead of searching for the best possible threshold, trees can be made even more random. Figure3 shows the random forest method made of a tree.Figure 3
Random forest performance.


## 4.5. Support Vector Machine

Support vector machine (SVM) is one of the supervised learning methods used for classification and regression. This method is one of the relatively new methods that have shown good performance in recent years compared to older methods for classification. The basis of SVM classifier work is linear classification of data, and in linear segmentation of data we try to choose the line that has the most reliable margin. Solving the optimal line finding equation for data is done by QP methods, which are known methods for solving constrained problems. One of the methods that are currently widely used for the classification problem is the support vector machine (SVM) method. Perhaps, the current popularity of the support vector machine method can be compared to the popularity of neural networks over the past decade. The reason for this is the ability to use this method to solve various problems, while methods such as the decision tree cannot be easily used in various problems. The vector machine often uses binary classification. It is assumed that there is anL observation that each observation consists of pairs in which there is an input vector and a two-state value (1− or +1). The idea of a backup vector machine tries to draw hyperpages in space that optimally differentiate samples of different data classes.In this paper, after using a combination of the above methods to filter the stocks of listed companies, the Markowitz mean-variance model is used to optimize the stock portfolio. In this model, from the acceptedN companies, m companies are selected to optimize the stock portfolio. The main goal is to determine the percentage of investment in each company Wi,i∈m. To determine the exact amount of investment, two objective functions are considered in accordance with equations (1) and (2). In relation (1), the goal of maximizing the stock portfolio based on the projected profit Ritpredict,i∈m and in relation (2) the goal of minimizing investment risk or in other words minimizing the covariance between the two shares of the company covij,i,j∈m. The investment must be made in such a way that in accordance with equation (3) the total volume of transactions does not exceed 1.(1)maxμp=∑i=1mRitpredict.Wi,(2)minRisk=∑i=1m∑j=1mcovijWiWj,s.t.:(3)∑i=1mWi=1,(4)Wi≥0.According to the Markowitz model, NSGA II and MOGWO algorithms have been used to optimize the stock portfolio based on the two mentioned objective functions. In the following, the mentioned solution methods are presented.


## 4.6. NSGA II Algorithm

One of the most efficient and well-known multi-objective optimization algorithms is the NonDefeatable Genetic Algorithm II (NSGA II). This algorithm is one of the fastest and most powerful optimization algorithms that have less operational complexity than other methods. This algorithm comes to the conclusion that it has an optimal range in terms of changing the objective functions and gives the designer the freedom to choose her desired design from among the optimal designs. In NSGA II, the preservation of elitism and dispersion is considered simultaneously. The selection of a new population in each step of this method is based on the principle of dominance, and using elitism and population ranking in each step of the solution, the best undefeated answers are selected and they go to the next step.If there are two maximization objective functionsf1 and f2, then for the two answers x and y, the answer x beats the answer y if we have f1x≥f1y and f2x≥f2y or f1x>f1y and f2x>f2y. Also, in order to observe the proper distribution of the density of the answers in this algorithm, a concept called congestion distance is used. In general, to sort a population of size n based on nondefeat levels, each answer is compared to all the other answers in the population to determine if that answer is defeated. Finally, there are a number of solutions, neither of which overcomes each other, so these solutions form the first boundary of the invincible boundary. These answers are passed to set F1. To determine the answers in the next boundaries, the answers in the first boundary are temporarily ignored and the above process is repeated; this time the answers are transferred to the F2 set and take second place. This process continues for all the unanswered answers of the population. One of the criteria of the evolutionary algorithm in order to reach the optimal Pareto boundary is to maintain the variety and breadth of the answers in the set of obtained answers. In fact, arranging nondefeats is a procedure in order to achieve better answers and the mechanism of diversity also seeks to maintain diversity and breadth in these answers. In this algorithm, this is done by swarming distance in this way. The smaller the swarming distance of an answer, the greater the density of answers around it. For the next step, select the answers that are in the area with less density or in other words with more congestion distance. This increases the diversity and dispersion of the obtained answers. The purpose of using congestion spacing in NSGA II is to create diversity in population responses and to indicate the density of responses alongside a specific response. Figure 4 also shows the pseudo code of NSGA II algorithm in stock portfolio optimization. The swarm interval for the ordered answers is ascending and specific to set F is obtained from.(5)CDX1=CDXS=∞,CDXi=Z1Xi+1−Z1Xi−1Z1XS−Z1X1+Z2Xi+1−Z2Xi−1Z2XS−Z2X1,i=2,…,S−1.Figure 4
NSGA II algorithm pseudocode in stock portfolio optimization.In the above relation,CDXi is the amount of congestion distance for the answer Xi. After merging the parent-child population, the undefeated sorting is performed and Steps 7 and 8. Based on Step 10, the swarm distance criterion is used to create a subset of the last undefeated set due to the subsequent increase in population size:Step 1.
Create the initial populationP0 of size N with random answers and set t=0,Step 2.
If the stop condition is not met, return toPt,Step 3.
Using the binary selection operator, selectN parents from the population Pt,Step 4.
By applying the intersection and mutation operators on the populationPt, generate the population of Qt children to size N,Step 5.
SetRt=Pt∪Qt,Step 6.
Use the invincible ranking method to determine the ParetoFi sets in the Rt population,Step 7.
SetPt+1=∅ و i=1,Step 8.
UntilPt+1+Fi<N:(a)
Add the answers of the setFi to the population Pt+1, and(b)
Puti=i+1.Step 9.
Arrange theFi set answers in descending order of congestion,Step 10.
SizeN−|Pt+1| Transfer from the first answers Fi to the population Pt+1, andStep 11.
Sett=t+1 and return to Step 2.


## 4.7. MOGWO Algorithm

The MOGWO like the NSGA II is a population-based algorithm based on the behavior of gray wolves. In this method, each wolf is introduced as an initial solution (determine the exact amount of investment) which aims to achieve the initial solution that has the highest expected profit and the lowest investment risk. From the MOGWO algorithm based on the equations discussed below; it changes the random response generated in each iteration, which improves the objective functions. Finally, the best initial solution is known as Alpha Wolf, and the result is the highest expected profit and the lowest investment risk. The gray wolf Canis Iupus belongs to the Candidate family. Gray wolves are predators at the top of the food pyramid, meaning they are at the top of the food chain. Gray wolves mostly prefer to live in groups. The average group size is 5–12 wolves. Leaders consist of a male and a female called Alpha. Alpha is primarily responsible for decisions about hunting, where to sleep, when to wake up, and so on. Alpha decisions are communicated to the group; however, some democratic behaviors have also been observed in which an Alpha follows the other wolves in the group. In communities, the whole herd endorses Alpha. Alpha wolf is also known as the dominant wolf, because the commands must be executed by the group. Alpha wolves are only allowed to mate in the herd. It is important to note that Alpha is not necessarily the strongest member of the herd, but the best member in terms of management in the herd. The second level in the gray wolf hierarchy is Beta. Beta are wolves that help Alpha make decisions or other herd decisions. The Beta wolf can be male or female, and he or she is the best replacement for Alpha in the event of his death or aging. Beta executes Alpha commands across the herd and gives feedback to Alpha. The Omega wolf is the lowest class in the gray wolf hierarchy. The Omega Wolf plays the victim. Omega wolves usually have to follow all the high-level and dominant wolves. They are the last wolves allowed to eat. If the wolf is not an Alpha or Omega, it is called a Delta. Delta wolves must be subject to Alpha and Beta. However, they dominate Omega. Figure5 also shows the pseudo code of MOGWO algorithm in stock portfolio optimization. In mathematical modeling of wolf social hierarchy, α Alpha is considered as the most appropriate solution. Subsequently β Beta and δ Delta are the second and third most suitable solutions, respectively. The rest of the candidate solutions are assumed to be Omega X. To hunt, gray wolves must find and surround their prey. Therefore, the following equations update the wolves’ positions around the prey.(6)D⟶=C⟶.Xp⟶t−X⟶t,(7)X⟶t+1=X⟶t−A⟶.D⟶.Figure 5
MOGWO algorithm pseudo-code in stock portfolio optimization.In the above relationsC⟶ and A⟶ are coefficient vectors. Xp⟶ is the hunting position vector and X⟶ is the gray wolf position vector. This is an equilibrium equation between siege and hunting. Therefore, the search radius must be optimized during the process. For this purpose, the equations related to the two coefficients used in the above relations are as follows.(8)A⟶=2a⟶.r1⟶−a⟶,(9)C⟶=2r2⟶.The above equations enable the gray wolves to update their position around the prey. As a result, the following equations are used to hunt.(10)D⟶α=C⟶1.X⟶α−X⟶,D⟶β=C⟶2.X⟶β−X⟶,D⟶δ=C⟶1.X⟶δ−X⟶,(11)X⟶1=X⟶α−A⟶1.D⟶α,X⟶2=X⟶β−A⟶2.D⟶β,X⟶3=X⟶δ−A⟶3.D⟶δ,(12)X⟶t+1=X⟶1+X⟶2+X⟶33.


## 5. Analysis of Results

After presenting different solution methods, in this section, the results of data analysis of companies listed on the Tehran Stock Exchange are reviewed. Based on this, data analysis is done in two stages. In the first stage, companies active in the Tehran Stock Exchange are selected, and in the next stage, after training the data, the return of the portfolio is reduced and the risk of the portfolio is reduced. According to the information extracted from the information site of Tehran Stock Exchange Technology Management Company (TSETMC), 480 companies listed on the Tehran Stock Exchange between 2011 and 2020 have been extracted along with all the stock information of the companies and filtered based on various inputs. To filter and select active stock exchange companies from 2011 to 2020, eight technical variables (final price, number of buyers, number of trades, trading volume, daily trading value, company daily value,P/E ratio, and number of shares of each company), seven fundamental variables (price of old design coin, new design coin, dollar, index, gold, oil, and euro), and time series of the final price of the last 10 days per share are considered and companies that have traded at least one day a month have been selected. Based on this, 85 companies active in the Tehran Stock Exchange have been identified and selected. After selecting 85 companies active in the Tehran Stock Exchange, to receive a buy signal from different combinations of three types of filters: “Optimization of trading rules based on technical analysis (Trading Rule Filter),” “Optimization of a strong trading system using Markov chain” (Markov Model Filter), and “Optimizing and Predicting Stock Returns Based on Predict Model Filter Methods.” In Trading Rule Filter, 6 indicators RSI, ROC, SMA, EMA, WMA, and MACD in six levels, namely, Very Very Poor (VVW), Very Poor (VW), Weak (W), Strong (S), Very Strong (VS), and very very strong (VVS) have been used. Finally, in the Predict Model Filter data training, machine learning methods are used between 2011 and 2015. In this study, the threshold value of determining the ascending and descending trend is 2% profit and 2% loss, respectively. Figure 6 shows the machine learning error based on 3 sets of input data based on random forest method (FR) and support vector machine (SVM).Figure 6
Comparison histogram error for training, evaluation, and testing of data between different machine learning methods. (a) FR method. (b) SVM method.
(a)(b)Figure6(a) shows the results of machine learning based on the RF method and Figure 6(b) shows the results of machine learning based on the SVM method. According to the results of the two graphs presented in Figure 6, the data based on the three sets of input data are well trained and the presented results are more accurate. The linear regression diagram for training, evaluation, and testing of data obtained from machine learning by RF and SVM methods is also shown in Figure 7.Figure 7
Linear regression diagram for training, evaluation, and testing of data. (a) FR method. (b) SVM method.
(a)(b)Based on the linear regression diagram of Figure7, the correlation between trained and predicted data obtained from machine learning by the RF method (Figure 6(a)) is equal to 0.9931 and the correlation between trained and predicted data obtained from machine learning by the SVM method (Figure 7(b)) is equal to 0.9977. Therefore, in the continuation of the analysis, the learning machine method with SVM method has been used.After training the data with RF and SVM machine learning methods, the SVM learning machine is selected because of its high correlation. To optimize the stock portfolio based on the purchase signal from Trading Filter Rule, Markov Model Filter, and Predict Model Filter, among 85 selected active stock exchange companies. Therefore, NSGA II and MOGWO algorithms have been used to optimize the stock portfolio based on the objectives of maximizing stock portfolio returns and minimizing stock portfolio risk in the Markowitz mean-variance model. Therefore, 7 different scenarios have been considered to investigate the solution methods. In scenarios 1 to 3, the stock buying signal of Tehran Stock Exchange companies is applied based on the performance of each of the filters, namely, Trading Rule Filter, Markov Model Filter and Predict Model Filter. In the fourth scenario, the buy signal is based on the combination of Trading Filter Rule, Markov Model Filter; in the fifth scenario, the purchase signal is based on the combination of Trading Filter Rule, Predict Model Filter, and in the sixth scenario, the purchase signal is based on the combination of Predict Model Rule, Markov Model Filter. Finally, in the seventh scenario, the purchase signal is examined based on the simultaneous application of all three filters.In each scenario, after presenting the stock purchase signals of the company in the coming days, NSGA II and MOGWO algorithms will be used to optimize the stock portfolio between 2016 and 2020. Therefore, in order to increase the efficiency of algorithms in maximizing stock portfolio returns and minimizing stock portfolio risk, the initial parameters of both algorithms should be adjusted by the Taguchi method. Therefore, 9 experiments are designed by the Taguchi method and the proposed algorithms are performed based on the levels presented in Table2. The mean and mean S/N ratio graphs for selecting the optimal level of meta-heuristic algorithm parameters are shown in Figures 8 and 9.Table 2
Parametric adjustment of meta-heuristic algorithms by Taguchi method.
AlgorithmParameterLevel 1Level 2Level 3NSGA IINpop100150200Maxit150200300Pc0.20.50.7Pm0.50.50.7MOGWONwolf100150200Maxit150200300A123C123Figure 8
Average charts ofS/N ratio and average in NSGA II algorithm.Figure 9
Mean charts ofS/N ratio and average in MOGWO algorithm.According to Figures7 and 9, it can be stated that the highest point in the average diagram of the S/N ratio is the selection of the desired level for setting the parameter of the meta-heuristic algorithm. Therefore, in order to increase the efficiency of the algorithms in optimizing the Markowitz mean-variance portfolio, in the NSGA II algorithm, the Npop parameter is 200, the Max it parameter is 200, and the P_c and P_m parameters are 0.7, and in the MOGWO algorithm, the N Wolf parameter. 300, Max it parameter 200 and parameters A and C are assigned values 1 and 2, respectively.After setting the parameter of meta-heuristic algorithms, Table3 shows the average stock portfolio return as well as the average stock portfolio risk obtained from different solution methods in 7 scenarios between 2016 and 2020.Table 3
The amount of stock portfolio returns and investment risk in different scenarios.
ScenarioObjectiveH&B (%)NSGA II (%)MOGWO (%)Scenario 1Mean ofμp12.5576.96102.19Scenario 212.6269.01107.65Scenario 312.5882.0994.72Scenario 412.94100.52124.89Scenario 512.9597.38124.03Scenario 612.9893.38125.51Scenario 713.08107.73133.13Scenario 1Mean of risk1.0472.3504.459Scenario 21.0452.3504.596Scenario 31.0122.4814.879Scenario 40.9802.0773.713Scenario 50.9802.2093.710Scenario 60.9871.9953.662Scenario 70.9461.4593.346According to the results obtained from Table3, it can be seen that the MOGWO algorithm has a higher return than the NSGA II algorithm and the hold-and-buy (H&B) investment method. Also, the risk of investing in this algorithm in all scenarios is higher than the investment method with NSGA II and H&B methods. It is also observed by comparing stock portfolio returns and stock portfolio risk, if filters are used individually, stock portfolio returns are lower and investment risk is increased due to the possibility of a wrong buy signal. After training the data with RF and SVM machine learning methods, the SVM learning machine is selected because of its high correlation. To optimize the stock portfolio based on the purchase signal from Trading Filter Rule, Markov Model Filter and Predict Model Filter, among 85 selected active stock exchange companies. Thus, if all three filters mentioned in the literature are used, the average return of the portfolio by H&B method is 13.08% with a risk of 0.946%, while the use of meta-innovative algorithms as well as the use of all three filters in providing a buy signal has led to an average stock portfolio yield of 107.73% for the NSGA II algorithm and a portfolio yield of 133.13% for the MOGWO algorithm. The algorithm of Figure 10 compares the changes in stock portfolio returns and stock portfolio risk in different scenarios.Figure 10
Bar chart comparing stock portfolio returns and investment risk in different scenarios.Also, based on the following relationships, the rate of return on investment (ROI) can be calculated in each of the scenarios for different solution methods. The amount of return on investment can be calculated based on relationships (13) and (14) per day of investment.(13)ROIt=1+μt100,∀t=1.(14)ROIt=ROIt−11+μt100,∀t>1.In equation (13), t = 1 shows the rate of return on investment for the first period and in equation (14) for other periods. Table 4 shows the rate of return on investment in different scenarios and with different solution methods.Table 4
Amount of rate of return on capital in different scenarios.
ScenarioH&BNSGA IIMOGWOScenario 1100.72106.76109.31Scenario 2100.73105.99109.88Scenario 3100.73107.26108.55Scenario 4100.76109.14111.73Scenario 5100.76108.82111.58Scenario 6100.77108.92111.67Scenario 7100.77109.88112.56Based on relations (7) and (8), it can be concluded that with the increase of the stock portfolio rate, the rate of return on capital increases. Therefore, the rate of return on capital obtained from the MOGWO algorithm is between 109.31 and 112.56 and the NSGA II algorithm is between 106.76 and 109.88. Also, if the filters are used simultaneously to provide a buy signal, the rate of return on investment will increase due to increased stock portfolio returns and reduced stock portfolio risk. Figure 11 shows a comparison of the average portfolio return, portfolio risk, as well as the rate of return on investment in different scenarios for each method.Figure 11
Comparison of average rate of return on capital in different scenarios.In the following, the return on investment portfolio between 2016 and 2020 in different scenarios with different solution methods is discussed. Therefore, Table5 shows the average stock portfolio rate, stock portfolio risk, and return on investment in different years and in different scenarios.Table 5
Comparison of rate of return, stock portfolio risk and return on investment in different years (percentage).
ScenarioYearμpRiskROIH&BNSGA IIMOGWOH&BNSGA IIMOGWOH&BNSGA IIMOGWO12016−0.4262.0686.990.571.974.0299.99101.20101.662017−0.2667.6193.270.481.994.07100.01103.62105.05201810.2772.4697.731.012.164.28100.18106.38108.84201938.1489.25114.221.622.454.63101.07109.30112.88202014.8893.42118.751.573.175.31102.40113.34118.1222016−0.3254.4392.790.571.934.1699.99101.06101.782017−0.1659.9298.570.481.964.20100.01103.20105.38201810.3764.31103.551.012.214.47100.19105.62109.39201938.2581.68119.311.612.454.73101.08108.21113.68202014.9984.75124.031.563.205.42102.41111.88119.1932016−0.3566.6479.700.542.094.5499.99101.28101.522017−0.1973.1885.760.442.124.50100.01103.90104.64201810.3377.8090.530.972.324.69100.18106.86108.10201938.2194.38106.411.582.624.99101.07110.02111.82202014.9498.47111.241.533.265.68102.41114.28116.68420160.0185.54110.570.511.683.27100.00101.64102.1020170.1691.52116.290.411.743.26100.03104.97106.41201810.7096.11121.380.941.913.47100.21108.69111.18201938.57112.47136.811.542.193.81101.12112.64116.29202015.31116.97142.501.502.874.51102.47117.80122.72520160.0182.27109.160.511.823.31100.00101.58102.0820170.1788.39114.810.421.823.32100.03104.78106.33201810.7093.24119.700.942.083.52100.22108.38111.03201938.57109.18135.551.542.293.86101.12112.19116.06202015.31113.82140.981.503.034.54102.47117.19122.43620160.0583.44109.960.521.603.31100.00101.60102.0920170.2089.16115.640.421.653.31100.03104.84106.37201810.7394.06120.740.951.803.55100.22108.47111.11201938.60110.33136.231.552.133.86101.13112.33116.19202015.35114.93141.891.502.794.53102.48117.38122.60720160.1592.74118.210.471.062.90100.00101.77102.2620170.3098.70124.720.381.113.00100.04105.38106.87201810.83103.42128.550.901.283.16100.23109.40111.99201938.70119.56144.621.511.613.48101.14113.68117.45202015.45124.23149.551.462.254.20102.49119.20124.28According to the results of Table5, the highest rate of return is related to the year 2020, in which the rate of return has increased due to the sharp growth of corporate stocks. The portfolio risk has also increased sharply this year. Figures 12 and 13 compare the stock portfolio rate of return and investment risk in each scenario with different solution methods.Figure 12
Comparison of stock portfolio rate in different scenarios and years (percentage).Figure 13
Comparison of stock portfolio risk in different scenarios and years (percentage).Based on the obtained results, it can be seen that if all filters are used to provide a buy signal, the stock portfolio rate has been higher than other scenarios. However, in this method, the investment risk was lower than other methods due to providing a more accurate signal. Table6 compares the effect of different filtering methods in providing a buy signal on the stock portfolio rate and portfolio risk.Table 6
:Comparison of different filtering methods on stock portfolio optimization.
ScenarioMethodThe best rank in earning theμpThe best rank in earning the risk1Trading filter rule662Markov model filter573Predict model filter754Trading filter rule + Markov model filter345Trading filter rule + predict model filter436Markov model filter + predict model filter227Trading filter rule + Markov model filter + predict model filter11Due to the ideal of the hybrid filter method, Figure14 compares the trend of changes in stock portfolio rate of return, investment risk, and return on investment in the 60 months leading to 2016 to 2020 with different solution algorithms.Figure 14
Comparison of trends in stock portfolio rate of return, investment risk, and return on investment in different months.After analyzing different solution methods in investing portfolio optimization, it was observed that the MOGWO algorithm has obtained the best average stock portfolio return in all years under test. The NSGA II algorithm, on the other hand, has a lower investment risk than the MOGWO algorithm.Therefore, using the TOPSIS method and using various criteria, such as objective functions value, NPF, MSI, SM, MID, CPU-Time, it can be stated that the MOGWO algorithm with a utility weight of 0.652 has a higher efficiency than the NSGA II algorithm with a utility weight of 0.276 in determining the optimal stock portfolio.


## 6. Concluding Remarks and Future Suggestions

In this paper, a model for optimizing the stock portfolio of active companies listed on the Tehran Stock Exchange based on the Markowitz mean-variance model was presented. The main purpose of this model was to maximize the rate of return of the portfolio based on the forecasted price and reduce the risk of the portfolio simultaneously. Accordingly, 480 companies listed on the Tehran Stock Exchange between 2011 and 2020, along with all company stock information, have been extracted and filtered based on various inputs. To filter and select active stock exchange companies from 2011 to 2020, eight technical variables (final price, number of buyers, number of trades, trading volume, daily trading value, company daily value,P/E ratio, and number of shares of each company), seven fundamental variables (price of old design coin, new design coin, dollar, index, gold, oil, and euro), and time series of the final price of the last 10 days per share are considered and companies that have traded at least one day a month have been selected. Based on this, 85 companies active in the Tehran Stock Exchange have been identified and selected. After selecting 85 companies active in the Tehran Stock Exchange, to receive a buy signal from different combinations of three types of filters: “Optimization of trading rules based on technical analysis (Trading Rule Filter),” “Optimization of a strong trading system using Markov chain” (Markov Model Filter), and “Optimizing and Predicting Stock Returns Based on Predict Model Filter Methods.” In Trading Rule Filter, 6 indicators RSI, ROC, SMA, EMA, WMA, and MACD in six levels, namely, Very Very Weak (VVW), Very Weak (VW), Weak (W), Strong (S), Very Strong (VS), and very very strong (VVS) were used. Finally, in the Predict Model Filter, data were learned from machine learning methods based on two methods: random forest (FR) and support vector machine (SVM). In order to optimize the stock portfolio based on the Markowitz mean-variance model, two meta-innovative algorithms, MOGWO and NSGA II, as well as the hold and buy method (H&B) were used. Seven different scenarios were considered to investigate the methods. In scenarios 1 to 3, the stock buying signal of Tehran Stock Exchange companies is applied based on the performance of each of the filters, namely, Trading Rule Filter, Markov Model Filter, and Predict Model Filter. In the fourth scenario, the buy signal is based on the combination of Trading Filter Rule, Markov Model Filter; in the fifth scenario, the purchase signal is based on the combination of Trading Filter Rule, Predict Model Filter, and in the sixth scenario, the purchase signal is based on the combination of Predict Model Rule, Markov Model Filter. Finally, in the seventh scenario, the purchase signal is examined based on the simultaneous application of all three filters. The results of the analysis showed that the seventh scenario resulted in the highest stock portfolio return with the lowest investment risk. This is due to the provision of valid signals by three simultaneous filtering methods. In this scenario, the MOGWO algorithm obtained a 133.13% stock portfolio rate of return with a risk of 3.346%, while the stock portfolio rate of return on the NSGA II algorithm was 107.73, with a risk of 1.459%. Comparison of solution methods shows that the MOGWO algorithm has high efficiency in stock portfolio optimization.By examining different solution methods in solving the stock portfolio optimization model, some suggestions can be made in developing and improving the quality of the article. Therefore, researchers can consider the uncertainty in stock portfolio investment and use uncertainty control methods such as robust programming. Also, in this paper, two meta-heuristic algorithms were used. Different and new meta-algorithms can be used to develop solution methods and compare them with each other. On the other hand, the existence of different methods of machine learning and their use is suggested.



---

*Source: 5974842-2022-08-29.xml*