Arti ﬁ cial intelligence model for building investment portfolio optimization mix using historical stock prices data

Purpose – Thepurposeofthispaperistoimplementageneticalgorithmicgearedtoward buildinganoptimized investment portfolio exploring data set from stocks of ﬁ rms listed on the Nigerian exchange market. To provide a research-drivenguidetowardportfoliobusinessassessmentandimplementationforoptimalrisk-return. Design/methodology/approach – The approach was to formulate the portfolio selection problem as a mathematical programming problem to optimize returns of portfolio; calculated by a Sharpe ratio. A genetic algorithm (GA) is then applied to solve the formulated model. The GA lead to an optimized portfolio, suggesting an effectiveassetallocationto achieve theoptimizedreturns. Findings – The approach enables an investor to take a calculated risk in selecting and investing in an investment portfolio best minimizes the risks and maximizes returns. The investor can make a sound investmentdecisionbased onexpected returns suggested from theoptimal portfolio. Research limitations/implications – The data used for the GA model building and implementation GA was limited to stock market prices. Thus, portfolio investment that which to combines another capital marketinstrument was used. Practical implications – Investment managers can implement this GA method to solve the usual bottleneck in selecting or determining which stock to advise potential investors to invest in, and also advise on which capital sharingratiotoreduceriskandattainoptimalportfolio-mixtargetedatachievinganoptimalreturnoninvestment. Originality/value – The value proposition of this paper is due to its exhaustiveness in considering the very important measures in the selection of an optimal portfolio such as risk, liquidity ratio, returns, diversi ﬁ cationandassetallocation.


Introduction
Portfolio optimization remains one among the essential info for investors before they create an investment selection attributable to its direct relationship with the performance of a corporation. The term portfolio refers to the mixture of assets having come and risk characteristics of their own, that conjure a portfolio (Donald and Ronald, 2013). The performance of a corporation refers to the result of the activities of people and units of a firm. This will be measured in numerous ways in which betting on the aim that the data is needed. Among the foremost basic tenets of the trendy money theory are that managers ought to act in a manner per maximizing the worth of owners' equity (Naqvi et al., 2016). For the banking system, business banks are by massive thought to be one of the most effective savings semen investment themes (Al-Tarawneh and Khataybeh, 2015).
Portfolio improvement has returned a protracted manner, and far from its evolution copied back within the USA. The USA mortgage market was primarily imploded between Gregorian calendar month and August 2007. The money crisis of 2007 modified the manner most functions at the money establishments operate and portfolio management is not any exception. The historical role of portfolio management remains. However, new restrictive necessities, particularly regarding capital adequacy and liquidity, increasing value and margin pressure, and altered market conditions have pushed portfolio management into a broader role and also they ought to align closely with alternative areas, such as finance, treasury, risk information and methodology and business-origination functions (Bank for International Settlements, 2015).
Strategic allocation is that the strategy of dividing your investment portfolio across varied stocks. Asset allocation is the selection on the way to invest in these broad plus categories to satisfy one's semi-permanent goal. The distributions can vary over time because of changes within the investment opportunities, the investment horizon and the semi-permanent economics risk factors like inflation and interest rates.
It has become necessary for the desirable managers of monetary services corporations to be at the forefront of development so as to boost the performance of their assets beneath management on top of that of their competition, whereas providing socially accountable merchandise and thence redistributing a number of the profits to specific target teams. Diversification is another crucial portfolio management strategy in money. This approach is additionally essential for investors. As investors will diversify their investment portfolio to extend the performance and to cut back the portfolio risk.
Portfolio management is among the numerous challenges facing investors and these individuals have without aim endowed heavily in unrelated areas that embody securities, properties, mortgages and loans. Creating a portfolio selection is one of the numerous policy problems in any investment trust. Investment associate in a very portfolio provides a sexy choice to investment trust because it permits for maximization of returns and minimization of risks in comparison to investment in white securities therefore the requirement to form an intelligent portfolio selection.
The outcome of this study can offer smart data that may change investors to accumulate and maintain a property competitive advantage and increase their market share through new market enlargement. This would possibly inform investors in Nigeria to take advantage of the economy of scale resulting in improved performance. It will additionally guide investment managers in creating investment selections for his or her companies. They request to extend the penetration quantitative relation within the market. Firm performance is thus stricken by the selections created by these managers. This study would possibly, be of help to them because it would possibly facilitate them to execute their role with efficiency and have the proper investment portfolio for his or her firm.

RAMJ
This study also will be helpful to regulative authority's particularly financial institutions in Nigeria likes the Nigerian Security and Exchange Commission within their role of guaranteeing that there is an honest play within the market by all relevant market players in the trade. As most investment organizations pay annual bonuses to the shareholders who support the performance recorded within the preceding fiscal year, with attempts to vary the payments supported an individual's contribution. The earnings shortfalls recorded by shareholders within the last fiscal year resulted from a mixture of things among them deteriorating portfolio optimization challenges. The study recommendations would possibly strengthen the performance stock prices in the market.
The analysis provided a background for future analysis of investment portfolio optimization in Nigeria. It will serve as a reference for future researchers on investment portfolio optimization. This study illustrates investment portfolio optimization for investors within the exclusive corporations listed on the Nigerian stock market; as a model for future investment portfolio optimization for investors.

Literature review 2.1 Genetic algorithmic rule
The genetic algorithms (GA) taking "survival of the fittest" approach as a basis were initially developed by Hollan and his students in the 1960s and 1970s (Holland, 1975;Küçüksille, 2009) with the basic idea evolving a group (also called generation) of possible candidate solutions (also called chromosomes) to any problem at hand, using several operators (such as crossover, mutation and/or inversion) which are inspired by natural selection and evolution theory proposed by Charles Darwin (Wang, 2001). It explains the processes of the naturally operating systems, to develop software package using such natural systems (Emel and Tas kın, 2005, p. 6) and useful in quite a wide range of areas of human endeavor that can be characterizes as system by yielding very fast and reliable results (Can and Gersil, 2017). GA is a family of evolutionary computing meant for solving combinatorial optimization problems which is understood as an area of computer intelligence (Urbšien_ e and Dubinskas, 2017). GA mimic the biological process in nature (Bolat et al., 2004, p. 264). It is an approach created to attain vital discoveries each in natural and artificial systems (Holland, 1975). According to Urbšien_ e and Dubinskas (2017), there are advantages of GA application in optimizing the investments portfolio. These includes: These algorithms work with a set of parameters, rather than with each parameter separately.
A parallel search can be carried out for the optimal solution through a number of points, not through a single point. A direct presentation of the problem domain could be used without any additional parameters. Probabilistic rules may be used instead of deterministic search algorithms" (Augusto et al., 2006;Plikynas and Daniušis, 2010).
Thus, the operational principle of the GA as reported by Das et al. (2006); Can and Gersil (2017) and applied in this study are as follows: "Generating a random initial resolution area.
Here, the answer area is within 0-1.
Generating an objective perform for the matter that is desired to be solved and subjecting the weather within the resolution area to the therefore generated objective perform, dominant whether the individual is match or not. The fitness Artificial intelligence model perform, on the opposite hand, is to make your mind up on whether the worth is acceptable for the determined solutions. The people in resolution area unit applied choice method succeeding being subject to the target perform and the fitness performs. There exist completely different approaches to choose method, for example, elitism and game equipment. Crossover is performed for making new people out of the chosen people. One or many of crossover strategies such as single purpose, multiple purposes is applied. Mutation is applied to the people once crossover method. Same method is applied for ever-changing the search direction. It should be applied at a particular magnitude relation. New people area unit generated, in any case, these strategies, replacement the recent people with the new ones within the resolution area. As a result, the fittest individual(s) is/are elite within the calculation of the population, and therefore resolution the matter".
Over the years several models of portfolio optimization have evolved, several studies are done on portfolio management, as an example is the study by Chang (2014), investigation whether/not and the way companies within the retail trade sector might profit by spreading their boundaries inside and across regional boundaries. They found that, the intra-regional diversification contains a parallel S-curve relationship and interregional diversification has an S-curve reference to firm performance. They established that unrelated product diversification has an adverse analgesic result on the connection between inter-regional diversification and firm performance. In the work of Yijun (2014), on the result of credit risk administration practices influences on the profitableness performance of European industrial banks in Europe. The study inferred that there's an affiliation among come back on assets (ROA) of investment firm. Furthermore, Cacho and Simmons (1999) enforced a genetic algorithmic rule to make a farm portfolio model. The farm portfolio model is such with two risky enterprises and a riskless quality which can be control in the short or long-run by the farmer. The model resolved numerically employing a GA rule. The result shows that the idea of competitive adaptation ends up in a violation of normative potency. Those that survive are not the foremost economical in an exceedingly normative sense. A similar work using GA was done by Hou et al. (1994), who enforced a GA rule for digital computer planning. The study used an economical methodology supported GA to unravel the digital computer planning downside. Thus, the illustration of the search node was supported the order of the tasks being dead in every individual processor. The genetic operator planned was supported the precedence relations between the tasks within the task graph. In addition, a simulation results scrutiny the planned GA rule, the list planning algorithmic rule, and the best schedule mistreatment random task graphs, and a mechanism inverse dynamics machine task graph.
According to Shadrokh and Kianfar (2007), an enforced genetic algorithmic rule for finding a category of project planning issues is also known as resource investment downside. The timing of project is allowable with outlined penalty thereby making parts of algorithmic rule like body structure, unfitness operate, crossover, mutation, immigration and native search operations to be explanatory. The performance of this GA rule was compared with the performance of different revealed algorithms for resource investment downside. Moreover, 690 issues square measure resolved, and their best solutions square measure used for the performance tests of the genetic algorithmic rule which was quite satisfactory. RAMJ Lin et al. (2004) enforced GA rule to securities market data processing and it absolutely was inferred that GA loses little or no exactitude, however, save heaps of time period. So, it is used in a true analysis system, and the results just like the best one. It may also be used as a basic tool for different application, such as ranking mercantilism rules.
The term portfolio deals with the issues around how best could investors or potential investors allocate theirs wealth among stocks or any assets in anticipation for returns. According to Chang et al. (2009), the portfolio optimization problems have been one of the important research fields and concerns to practitioners in the modern risk management. As investors generally always prefers to have the higher return on their portfolio with lower risk as small as possible. Conversely, a larger return in most investment always comes with almost commensurate if not a higher risk. Yılmaz and Kucuksille (2014), therefore, submitted that optimization is an effort of generating solutions to a problem under bounded circumstances with a desire to use existing resources in the best possible way.
In this paper, therefore, we used GA to search out the higher parameter price combination in an existed mercantilism rule. From the result, GA algorithmic rule performed higher than the manual methods. Extensive research studies on investment portfolio optimization revealed several efforts made both in Nigeria and globally by researchers to identify key influencers that could impact a portfolio mix. The major problem highlighted in building a competitive portfolio mix are selection of investment/eligible stock that guarantee high returns amidst mitigating lower risk and how asset should be allocated based on the optimized selection. This study takes the approach of using artificial intelligence model in building an investment portfolio optimization mix using historical data of stock prices, which is believed to reflect almost all dynamics that could affect a business, as far as researchers are aware, it is the first study in Nigeria that construct optimum portfolios from NSE top 30 indexes using GA framework.

Data and methodology
All stocks from 167 companies listed on the Nigerian Stock Exchange Market between (July 1, 2014-July 1, 2019) formed the population of this study. The study relies on stratified secondary data that groups stocks based on Market capitalization and liquidity ratio. In addition, a total of top 30 companies on the 2019 NSE 30 Index made up the sample size for this study. Closing price of stocks of these 30 companies from July 1, 2014 to July 1, 2019 were collected and analyzed.
Historical figures for each stock between July 1, 2014-July 1, 2019 was collected from an online secondary source (investing.com) a leading platform where investors visit regularly for insight on investment options. Time series trends and data visualization/descriptive statistics of data are performed using power business intelligence (BI) analytics software.
A constrained Sharpe ratio function was implemented to calculate return on investment while a GA enforced using R-programming analytics platform to predict the optimum allocation of asset that yields the most stable curve from all possible return on investment curves. The algorithm predictive capability was tested for a five-year period (June 1st, 2014 -July 1st, 2019). Stock directional movement prediction performance was also assessed. Thus, portfolio optimization using GA will rely on post-hoc information.

Portfolio composition
The investor has selected N financial assets he/she wants to invest in. They can be stocks, funds, bonds, treasury bills and so on; moreover, this research focuses on stocks alone. Each one of them has many historical returns that are the price relative difference from one period Artificial intelligence model to another. Periods can be days, weeks, months, etc. The return of the i-th asset between period t and period tÀ1 is defined as: To build an investment portfolio, involving many stocks mixed together, allocating a fraction x of our capital to each one of them. Each fraction is called weight.
The portfolio return at time t is then: The goal of our portfolio optimization is to find the values of the weights that maximize some performance metric of our portfolio according to the weight's constraints, which are: This then makes the problem a constrained optimization problem.

Objective function
Using the Sharpe ratio, defined as: where E(p) is the expected returns and E(r) is the risk-free returns and Var(p) is the variance.
For this research, we will not be considering the risk-free return. So, the portfolio shape ratio formula to be used is: Our weight must be positive. The sum must be equal to 1 to cover our entire capital

Penalty function
Our inequality constraints give us the following penalty functions: It is useful to square the penalty function to make it completely different from each other.

RAMJ
Our equality constraints then become: We are transforming a constrained problem into an unconstrained one, so we are forcing the global minimum search. Multiplying the penalty function by a number, it is usually 10, but we will be multiplying by 100 to enhance the optimization mix. So, the final function we must minimize to have our optimal return as follows: Þþ 100 Thus, the GA has been used to optimize the Sharpe function (Sharpe, 2000) ( Table 1).

Results of analysis
Over a five-year period stocks from six companies (Okomu, Presco, Mobil, Nestle, IBTC, Guaranty and DANGSUG are likely to be profitable (Table 2, Figure 1). Building a portfolio mix of the NSE top 30, after (3030 Iterations) the asset allocation distribution from the optimized Sharpe ratio function using GA was generated, and the optimization technique advised that for an investment portfolio consisting of NSE top 30, 8% of the investment capital should be allocated to Unilever, 6.3% to international breweries, 6.2% to PZ, 5.2% to Nigerian breweries, 4.7% to UBA [. 4.1 Optimal investment returns 4.1.1 Optimal returns against individual returns. From the analysis above, drawing a comparison between the optimal returns, that is, anticipated result using the optimum allocation and individual returns, we could observe that the optimal returns performed more than 60% of the individual returns and the optimal returns curve is the most stable curve compared to the individual returns curve. From the optimal returns curve the investor is likely to have the 29% profit margin at peak performance and À46% losses at worst.

Finding the right mix (reducing the portfolio size)
It could an arduous task for an investor to invest in 30 stocks at once and monitor profit overtime, hence this research further tried to optimize the investment portfolio by further using a portfolio mix of not more than 5 stocks, although these will expose the investor to an higher risk as compared to the earlier NSE 30 mix. The selection was done according to the best five performing individual stocks and the top five stocks according to the optimal investment allocation result from the GA (Table 3).
4.3 Findings from reduced portfolio mix 4.3.1 Sample A. The optimized Sharpe ratio Function using GA performs better than two other individual stocks (NB and PZ) and shares similar return with another stock (Unilever) while international breweries and UBA perform better than the optimal. An investor allocating capital to this portfolio is advised to allocate 28.8%, 26.1%, 24.3%, 11% and 9.3% to international breweries, Unilever, UBA, PZ and Nigerian Breweries, respectively.

Artificial intelligence model
Investing in these portfolio mixes using the optimum allocation will likely yield 70% profit at peak performance and À44% losses at worst. Investing in these portfolio mixes using the optimum allocation will likely yield 99% profit at peak performance and À16% losses at worse (Figure 7). analysis result shows three optimal result while Sample B is likely going to yield the highest profit should an investor consider building a portfolio. From the analysis, it is evident that investing in stocks across different sectors will enhance the performance of our investment portfolio. From the optimal portfolio mix, an investor is advised to look at the financial, agriculture and oil and gas sectors when considering diversification (investing in stocks from different sectors). This is in line with Chakrabarti et al. (2007), who argues that diversification contributes to improving performance in investment.
From the analysis, it is evident that optimal allocation of asset will enhance performance of our investment portfolio. As it is evident in Figures 1-6, while some stocks perform better than the optimized function, some also performed poorer. However, optimum allocation of asset within the portfolio mix will ensure a greater percentage of our asset is allotted to bestperforming stocks and a lower percentage to stocks with lower performance as a way of minimizing risk, and ensuring a balance.
There is an inherent risk associated with every investment option, from the analysis result, it is evident that optimizing the investment portfolio can help lower the risk of losing out on an investment. Optimization ensures that the loss is minimized, should it occur, and profit is maximized for an investment portfolio mix. This is in line with Tai (2014), who argues his study that numerical methods need to be hired to control the non-conformity from the ordinary mode of operation, when dealing with issues of risk management. RAMJ This study was undertaken to implement a GA with an aim of optimizing an investment portfolio mix and effectively manage risk associated with such investment. Data for this research was collected from a reliable secondary source. Information collected was prepared for analysis. Data mining technique was employed in developing and implementing the GA. Microsoft excel was used in data cleaning and data processing, Microsoft Power BI was used for all data visualization and R programming was used in deriving the Sharpe function and also the optimization of the function and optimum asset allocation using the GA (which can be accessed as an AI library on R platform). The 30 companies (NSE 30) that made up the sample size were drawn from 6 sectors (agriculture, oil and gas, financial services, construction/real estate, industrial goods, consumer goods). The research draws inferences based on five-year historical data of each company stock prices in the Nigerian Stock Exchange.

Conclusion
This research sufficed in illustrating how GA can be implemented to arrive at an informed decision as an investor and have the right-mix in an investment portfolio. This agrees with (Ha, 2013), who postulate that GA performs better than assent method in portfolio optimization. The result from the research indicates that GA model implementation can be deployed to help investment managers and stockbrokers assess the potential return on investment and advice on potential investment portfolio mix. Investment managers can implement this method to solve the usual bottleneck in selecting or determining which stock to advise potential investors to invest in, and also Optimal returns vs individual returns for Sample A RAMJ advice on which capital sharing ratio to reduce risk and attain optimal portfolio mix targeted at achieving an optimal return on investment: It is recommended that investment manager should adopt this algorithm in choosing an appropriate portfolio investment for potential investors, adopting this method will help reduce greatly the stress of having to comb through a lot of journals, newsletter and expert opinion on a lot of stocks or investment options available. Expert knowledge on companies/stocks/investment options is viable and this research does not disprove that, but the research will aid in the technical analyses, and help reduce the number of viable options to a considerable size, which domain expert knowledge can then be sort for. However, except for extreme conditions and sudden incidence, making decisions on investing on stocks using historical data of prices combined with appropriate statistical tool aimed at drawing insight from the data will suffice in arriving at an informed decision. Because in prices are others inherent dynamics that could influence the price, which domain expert will just be providing clarification on.
This research work has lent a voice to the adoption of artificial intelligence in making informed decision about investment options. In a bid to harness the potentials artificial intelligence has to offer. Due to limitation in the data available for this research, the option of an investment portfolio that comprises of stocks, bond, fixed deposits, treasury bills, etc., was not explored. Further research could explore that option. This research can be improved using a deterministic optimization algorithm likes analytic hierarchy process after the GA, to reach a certain exactness. More so, further research could try to draw up a comparison on optimal returns for long-term and short-term investment decisions, using historical data for a longer period (say 10 to 20 years).

Artificial intelligence model
Algorithm - Figure Figure A18. Excel output result Figure A19.
Raw data Artificial intelligence model