Portfolio Optimization in DSE Using Financial Indicators, LSTM & PyportfolioOpt

Due to its suitable power to anticipate using Non-Linear forecasting methodologies, LSTM (Long ShortTerm Memory) has changed the approach to time series prediction several folds. Process compatibilities of technical identifiers and various financial benchmarks that are defining financial decision-making in international markets are affecting Bangladesh Market as well. Issues like MACD and RSI as a technical investigator and financial ratio aspects of EPS and PE Ratio play an important role in the selection of assets in DSE. Given adequate training in line with intended functionality models, RNN has the potential to think through in a similar manner and the probable results are exhibited in this paper. Because of the Gated Structure, which refers to retaining important information and discarding irrelevant information through diminishing gradient and exploding gradient, LSTM has achieved significant advances in nonlinear forecasting that is based on human behavior. In this study, we compared two alternative portfolios that will be dependent on LSTM's future forecasting capabilities in terms of projecting the greatest potential output, which is demonstrated using Portfolio Optimization principles.


INTRODUCTION:
LSTM can handle time series problems using a feed forward network with fixed time windows (Gers et al., 2002). The job most closely connected with LSTM occurs inside the confines of training under a given data series, and this training forecasting relates to a future point of interest. Our traditional analysis of assets based on Current Ratio and EPS are dependent on the assets of NYSE in much better assigning views (HM . It has been shown that LSTM has accurately anticipated human motion and predictiveness in terms of their behavior influencing movement choices in congested areas (Alahi et al., 2016). Alahi et al. have effectively developed a behavioral track in terms of intelligent tracking systems that mimic human behavior and decision patterns in smart settings. Wang et al. Investing risk has been shown to be directly related to less financial knowledge, and better financial decisions always lead to better, profitable financial decisions (Wang et al., 2011).
Various technical indicators like MACD and RSI plays important role in financial assets behaviors in order to predict its future goals (Chong et al., 2008). It's also seen that highly volatile market such as FOREX market also performs under the boundary constraints of MACD indicators (Zida et al., 2013). There is evidence that in the United States and Germany, investors prefer local investments rather than foreign mixed portfolios (Kilka et al., 2000). Our research work will focus on an enlightened view of the statistical control process of portfolio asset selection and time series-based decision making through nonlinear methods. In our research, we would evaluate pure stock portfolios under the guide of picking them based on sound financial principles, and we would compare stocks using performance optimazations to improve financial performance. It's seen that due to MACD parameters and RSI indexing process major stock index like DJI & NASDAQ performed well through financial indicators (Chong et al, 2013). In terms of the accuracy of nonlinear forecasting and time series forecasting, deep reinforcement learning has been found to play an effective role in portfolio management. Thus, our paper would attempt to reduce the risk variance of investment by combining finance and stock with proper financial indications for long-only gains rather than pure statistical evidence for portfolio investment. This investigation process wills describe the following events (Pathiranage, 2021): Creating a Stock Portfolio from Scratch -(a) Each stock would be chosen on the basis of a strong financial ratio as proof for an investment recommendation within the context of EPS and PE Ratio. (b) We will also choose stocks using MACD and RSI. (c) The non-linear prediction process using LSTM shows that the best stocks perform well in the long-only investment method, so that in the case of judging the best stocks, the best port-folio returns are selected within a time period.

Literature Review
In the financial market, the most important factor is still financial knowledge and risk perception in the choice of assets for investment purposes (Aren et al., 2016). It has been discovered that when financial literacy improves, better human decisions are made. Since human thinking ability determines the overall investment outlook of market behavior (Caparrelli et al., 2004), it is better to simulate future asset price forecasts with bias factors based on the non-linear forecasting principle and combine the training asset selection option in LSTM. It can be observed that LSTM is the most successful choice of holistic feature selection when it comes to learning the pattern of choices depending on diverse scenarios. It is built on a dilated causal convolution network that seeks to learn multiple features that are entirely trait dependent and multi-dimensionality reduction associated with multi-conditional data, making nonlinear prediction successful (Shen et al., 2020). It's also being assessed in the context of multi-range and multi-level charac-teristics being utterly under predicted using fixed time intervals (Shen et al., 2020 andAlahi et al., 2016). For the price of commodities, LSTM also effectively predicts the price of gold (Livieris et al., 2020). The prediction model will be correlated with the veryfication of the linear regression of theming global indices (Cao et al., 2018;Livieris et al., 2020). Since the closed structure supports the feed forward network, the network model can learn appropriately and can make accurate predictions (Gers et al., 2002). LSTM is considered to be able to effectively predict the price of Bitcoin, and learning and training are the only features for making accurate predictions (Wu et al., 2018). For the purposes of the selection process, we will use favorable financial ratios as an indicative reference as well as MACD & RSI as favorable financial indicators for the asset selection (Chong et al., 2007;Chong et al., 2013). Ever since (Henry Markowitz, 1952;Markowitz, 1992) proposed the heyday of decision making on asset selection and portfolio performance optimization (Chen, 1981 andBeaver, 1966), people have seen the important role of financial ratios in asset selection. It has been observed that LSTM provides better predictability than ARIMA (Siami et al., 2018). Our predictability characteristics depend on several factors consistent with the financial dependence of the asset. This study will look at how we may use the K Nearest Neighbor algorithm to create asset choices (Chen et al., 2017;). Bodie's Principle of investing in stocks with low volatility still plays a crucial role for financial investment (Bodie, 1995). It has been discovered that EPS ratios play a crucial influence in asset selection for investing (Lin et al., 2011). We are also going to use MACD to make a list of stock that will do better. Then we will figure out which stock has both better EPS and favorable MACD. The final volumetric analysis will be performed using RSI indexing using the similar market parameters of NYSE, as the Bangladesh economy is highly correlated with the economic solidarity of foreign markets (Hassan et al, 2008). Combined with non-linear methods, LSTM is believed to be able to make accurate and positive predictions about the future aspects of any growth model (Livieris et al., 2020). For the fruit fly algorithm process, LSTM effectively predicts location attributes (Peng et al., 2020). Therefore, this document focuses entirely on LSTM, which is used for asset pricing related to future forecasts and accuracy (Sami & Arif, 2021).

Theoretical Framework K Nearest Neighbor Algorithm
It can be seen that the nearest neighbor algorithm K is very successful in locating the best group of employees for selection through defined quality settings . This study would also establish a collection of high-quality facts that could be used as standards for identifying the finest equities to invest in.

Point of Interest
EPS -According to CFI (Corporate Finance Institution) and main GAAP accounting standards, EPS is defined as the ratio of Net Income to Weighted Average Outstanding Shares.
MACD -There are two ways to ways to evaluate stock price. One is fundamental analysis and another is technical analysis. Moving Average Convergence Divergence (MACD) is technical analysis method for forecasting stock market.

PE Ratio -
The P/E ratio aids investors in determining a stock's market value in relation to its earnings. In a nutshell, the P/E ratio reflects how much the mark-et is prepared to pay for a company now based on its previous or projected profits. A high P/E ratio indicates that a stock's price is high in comparison to its earnings and may be overpriced. A low P/E, on the contrary, may suggest that the present stock price is cheap in comparison to earnings.

MACD (Moving Average Convergence & Divergence)
Gerald Appel created the MACD, a trend-follow-ing momentum indicator that depicts the connect-ion between two price moving averages (normally the close). Technical analysis is linear functions that are based on past trading data.

MACD = 12-Period EMA − 26-Period EMA
One can choose from variety of price data composition like opening price, high price, low price, closing price etc. MACD is the result of subtracting the long exponential moving average (EMA) from the short one, which offers a buying signal when the MACD crosses from zero to above, and a selling signal when the MACD crosses from zero to below. Moving averages are used to create the MACD; the value is determined by subtracting the longer exponenttial moving average (EMA) from the shorter EMA. Formula as follows: Where: t=today; y=yesterday; N=number of days in EMA; k=2÷(N+1) or smoothing constant.

RSI (Relative Strength Index)
The relative strength index (RSI) is a technical analysis indicator that evaluates the size of recent price fluctuations to determine if a stock or other asset is overbought or oversold. Values of 70 or higher on the RSI, according to traditional interpretation and use, signal that an investment is becoming overbought or overpriced, and may be poised for a trend reversal or corrective drop in price. A signal of 30 or below on the RSI suggests that the market is oversold or undervalued.
The RSI usually tracks a stock's rise over the previous 20 days.

Benchmark
Based on the evidence from accounting standards guidelines, it was found that most earnings per share of the major stock indices were shown to be greater than 1. Leong

Algorithm 1
Volume & Affordability of Sales Novy Marx mentioned that if we select stocks based on their quality attributes and then as quality increases, we can expect to increase the pay for high-quality stocks (Novy Marx, 2013). The basic technique suggests focusing on average-quality equities that are available at a discount and can be anticipated using market-determined movement patterns.

LSTM (Long Short-Term Memory)
LSTM is a neural network structure, mainly based on artificial recurrent neural network, which provides the exclusive right to predict the correct prediction phenomenon. Through its network structure, it gets the capacity to analyze data sequences. The organization of LSTM is to achieve its best failure solution by eliminating the gradient problem. The solution method is enabled by the constant flow of input across gradient LSTM units (Wu et al., 2018). In the case of nonlinear time series predictions involving vanilla RNN through back propagation, due to the calculation process and the participation of finite precision numbers (rounding errors), RNN continues to use gradients as missing or explosive basic feeds without changes (they tend to at zero) or infinite change (towards infinity). Generally, LSTM contains a forget gate, which allows you to sequentially ignore the error values propagating backward from the output layer and slowly cut them through the feed forward neural network through repetition (Siami et al., 2019). The loop only allows the LSTM to train those gradients whose weight updates seem to be valid for future value benchmarks (Alahi et al., 2016). Finally, the actual weight update reference and gradient growth indicate the propagation factor associated with the time series prediction based on any value of the training and test values in terms of precision.

Portfolio Optimization
Investment portfolio is the combination of different assets in different proportions as an investment Ina specific entity. It has been observed that, in contrast to the case where a single asset is used as an investment measure to obtain profit, which will define risk-return parity, in the case of the lowest level of risk, the best combination of assets is associated with the best profit ability. It is typically a selection process that uses the right investment tools in the right proportions to generate the best return and balances the measures of risk and return associated with investing (Baumann et al., 2012).
The overall profitability of the investment portfolio depends directly on the weighted distribution of the investment in each asset in the portfolio and the profitability defined for each of these assets according to the risk factor. The ideal return point should be the actual mix of return and risk, after which each additional unit of return would bring more than one additional unit of risk, as Markowitz Portfolio Theory directly relates return and risk as proportional to each other. As the probability of risk decreases with the introduction of less returning assets into the portfolio, the ideal return point should be the actual mix of return and risk, after which each additional unit of return would bring more than one additional unit of risk (Layard et al., 2008). As a result, when we achieve the highest Sharpe ratio, we may maximize the portfolio's effective return.
Research Processa) According to various online stock recommendation platforms, 100 stocks are randomly selected as investment assets, for example: for i in asset: If MACD> 0&&RSI < 70 Asset (K) Accept Else: Reject www.fknol.com; www.businessinsider.com; www.investing.com; and www.fools.com b) The closest K algorithm is used to select stocks within the given priority EPS and MACD recommended by effective research. c) The selected stock is then undergone through the RSI indexing process in order to check the volumetric approaches of the stock. d) Apply LSTM as a non-linear prediction method to each selected population for the priority time range for training purposes and subsequent testing purposes, so that the effective prediction quality of LSTM can be suggested in terms of accuracy. e) Associate well-performing stocks with their LSTM forecast prices in PyPortfolioOpt for portfolio optimization.
With reference to the value of the Sharpe ratio and the return on investment in the context of the returns of the portfolios to determine profitability.

METHODOLOGY:
It's more vital to determine the standard ratio for which the companies may have better or higher priced future value in order to choose stocks based on effective financial ratio as a boundary line for criteria. According to Chen & Shimerda, the financial ratio values should be limited to the following:

EPS >>>> AS High as Possible 1.0
In the preliminary study, xi may be used as reference values for EPS. This research employs the K Nearest Neighbor clustering technique to pick assets that are effectively nearest to the desired point of reference recommended by expert re-search and conventional accounting rules. Ux denotes the average point for EPS.

Minimum Point of Difference
As a result, the optimal asset will have the smallest gap between the intended asset features and the target assets.
Min (ABS (K (Xi, Yi) -K (Mod X, Mod Y))) ABS stands for absolute value. K (xi, yi) denotes the weight characteristics of EPS for certain assets. K denotes the values associated with each variable.
for i in asset: If EPS >>>> As High as Possible&& Else if PE Ratio < PE Ratio (industry) Asset (K) Accept Else: Reject

Algorithm 2
The asset selection procedure is now complete based on the evaluated criteria. It is clear that, following the selection process, we must determine which asset would provide the greatest return on investment in the future. To make this procedure effective, we used a non-linear time series price forecast in conjunction with LSTM, which has the capacity to recall the required information for predicting while ignoring unnecessary data. In order to make the stock selection process much more effective, this research tends to analyze each quarterly returns of financial ratios with its previous ones

LSTM (Long Short-Term Memory) -The LSTM is a customized RNN (Recurrent Neural Network) that
can recall important and necessary information instead of irrelevant information. In general, the activation function is the first step in the RNN process. The weighted sum of input is converted into an output from a node or nodes of a layer in the network using the activation function. The activation function is denoted by the symbol a<t>. The output function refers to the previous time step's output, which is based on the input x<t> and activation function a<t>, which is based on the input and activation function values of the previous time instance, x<t-1> and a<t-1>. Y<t> denotes the output based on the input at that particular time step x<t>. It is critical that all of the following options operate properly in order for the activation functions to create output successfully.
All of these parameters influence the RNN structure, which is utilized to produce the follow-ing outcomes:

EPS Ratio = Current Quarter EPS / Previous
Quarter EPS > 1 && PE Ratio = PE Ratio (Company) / PE ratio (Industry) < 1 Then Accept the Asset The bias of the activation function is connected to the weight allocation of Wax for input and Waa for activation function in the activation function. In the same way, for the output activity: The resulting activation is linked to the output bias factor and Wya as the output allocated weights. For price prediction, it is related to bias and market factor g1, while g2 remains the activation functions that take effect one after the other. The recurrent network is effective because of all of these functions. As a result, the entire RNN unit is defined as: Where each time steps motion enables successful training based on the provided data generated by the network. Each of these processes demonstrates the positive aspect of the prior asset price and its relationship to the current asset price. In order to train the information's to acquire appropriate information in response to situational developments, as many examples as possible would be incorporated in this feed forward neural network system. The RNN design selectively permits biased conditional methods to be entirely reliant on the training process. Because each stock is related to the market through beta, but also has its own performance capacity (Stosic et al., 2019), bias is the most important factor in price prediction. There are different gated structures in the LSTM process, such as the ones below. The RNN design selectively permits biased conditional methods to be entirely reliant on the training process. Because each stock is related to the market through beta, but also has its own performance capacity (Stosic et al., 2019), bias is the most important factor in price prediction. There are different gated structures in the LSTM process, such as the ones below: In the RNN procedure, represent the gate notation. The update gate, relevance gate, forget gate, and output gate are all represented by the symbols above. As a result, the gates allow for the remembering of features for price prediction or the cutting off of data for price prediction. The following function illustrates how gates are connected: The sigmoid function is shown here to conform with the requirements of gated construction, but the relay and soft max functions may also be incorporated in this equation with respect to the demand of the scenario. When it comes to creating predictions, each function has its own set of benefits and applications. g(z) is an output of the sigmoid function that exists between [0,1].
Tanh inadvertently refers to the valued answer of g (z) from [-1, 1]. Finally, relu The highest value between 0 and z that the recurrent neural network operation can achieve. LSTM is discovered to have multiple gates inside the processing unit when used in conjunction with RNN. As a result, the goal of LSTM is to aid in the development of effective evaluation and training revolutions that assists:

Application through LSTM
a) The right number of trainings to help you in projecting the desired value for future forecasting. b) The output values that would help the activation functions for future values are highlighted using RNN trimmed techniques to purposefully manage the exploding gradient problem since RNN encounters both exploding gradient and vanishing gradient problems. RNN reduces the possibility of infinite by preserving a parallelism during the boundary line clipping process. While RNN is capable of solving the exploding gradient problem, it is incapable of solving the vanishing gradient problem. When we examine the gated structure of the RNN unit in the LSTM, we can see that there are four gates in the unit. C-<t> has a primary output function. Previous activation functions and current input are linked to relevance gates. The situational bias is introduced to make the primary output effective in conjunction with the activation functions, which can be softmax, relu, tanh, sigmoid, and so on.
The primary output associated with the update gate structure and the forget gate model will be added to previous output in the case of final out-put function c<t> in order to determine if any required information is supposed to be remembered or not in order to make the prediction process much more efficient. As a result of this gated feature, the vanishing gradient problem is eliminated.
Furthermore, this procedure makes the activation function for the following stage very efficient, because the activation function remembers which important information is necessary for the pre-diction process at each phase of the final output.
Relevance with Financial Forecasting -Because financial forecasting relies heavily on nonlinear movements, LSTM provides far more accurate forecasts than linear prediction approaches such as linear regression and the ARIMA process (Abediyi et al., 2013). Each stage of the pricing process is referenced against a set level of prior level prices. We have included the following number of observation phases in the study process: Epochs for Loss Reduction -When the prior step supplies irrelevant information to the forward step in an RNN, the loss function is designated under the jurisdiction of loss occurrence during the training process. Here, we can see that if the main output begins with less loss than the final output, then the prior information should be used in the feed forward process.
Because LSTM prefers to accomplish the exact step of loss reduction through its gated structure method, the loss in reference to predictions has been decreesed with successful training. With favorable data, the epoch of 75 has produced effective forecasts for the process to be successful, as shown in our expanded Epoch calculation.
Back propagation Method -The derivative of loss L with regard to matrix W must be updated in reference to each time step in order to make the financial price forecasting issue suggestively good with respect to time-based propagations. It has been discovered that when the necessary information is updated and sent through the activation phases, the corresponding weights that will be applied for predicting the price will be changed in each step.
It can be shown that by using LSTM's observation stages and feed forwarding mechanism, the loss function may be decreased over time for big datasets. If we practice taking the same number of training steps on smaller datasets, the loss does not become decreesed. Furthermore, it has been observed that the losses are decreased positively with smaller datasets and shorter training steps.
Portfolio Optimization-A portfolio is a collection of assets that, when correctly integrated, include the following factors: a) Appropriate Time for Investment b) Appropriate Amount for Overall Investment c) Putting the correct amount of money into each asset Would yield the highest potential return on a financial market investment. As a result, the expected portfolio return will be defined as follows: E (Pr) = Wai * Rai + ………………. + Wan* Ran refers to all of the assets in the portfolio, while n refers to the portfolio's ultimate asset number. W stands for the portfolio's weight, or how much of an investment contribution we made. The return of each individual item in the portfolio is represented by the letter R. The reason for reducing risk-free earnings in relation to getting a return from the portfolio is that risk-free earnings are already making an acceptable profit throughout all investment processes, so the actual profit accrues only when the portfolio return is greater than the risk-free rate and the return difference is greater than portfolio risk.

Sharpe Ratio > 1 ………… Acceptable Sharpe Ratio <= 1 ………. Unacceptable
The concept is related to a lower contribution margin. The selected assets were therefore employed for financial performance and optimized performance within the boundaries of these.

RESULTS AND ANALYSIS:
We have gathered 100 stocks that have been considered for investment-by-investment portals from an internet portal of proposals for the purpose of study. After using the K closest Neighbor clustering method, it was discovered that a sample of 8 stocks with higher EPS values, lower PE ratios, positive MACD indicator and less than 70 as RSI indicator. With the list of assets that are required to be the best possible mix therefore within the boundary of volumetric suggestions, it has been determined that the following list maintains the best possible asset selection list while posing minimal risk. Our research process also tends to evaluate the selected stocks in reference MACD & RSI Indicator, the resultants values are described below: Our research analysis uses relative association where it speaks to say if more of data in close by days suggests good MACD indication or RSI indication. It was discovered that LSTM has considerable effectivity in connection to error calculations for the forecasting process when they are effectively going through a particular number of epoch steps in order to anticipate future prices for stocks of DSE. The LSTM method has been conducted through numerous epoch stages in our research procedure in order to conform to a common pattern of comparable number epoch practices to decrease the loss calculation. The graph above depicts the average loss accumulation that occurs throughout the LSTM training process. Because the loss count virtually becomes null after the 50-60 th Epoch, the total number of epochs for stocks is set at 75 to speed up the calculation procedure. The accuracy results for the stocks are detailed below in order to assess the accuracy by predicting for each individual stock.

Portfolio Optimization Process
The basic stock portfolio generated the following results using Portfolio Optimizer. As a result of LS-TM's excellent recommendations about these companies and their future price projections, such gains were attainable. After the adjusted portfolio optimazation three stocks remained anonymous and various other stocks turned the portfolio gainer. Real prices are contrasted to properly anticipated prices in terms of stock allocations and actual stock gains vs predicted stock gains. In terms of anticipated pricing and resource allocation, the predicted portfolio is 95.72 percent accurate. The best potential assets were effectively identified by the projected portfolio using LSTM; however the asset allocation for the real and predicted portfolios were somewhat different. The revised Sharpe ratios show a little discrepancy between the anticipated and real portfolios of 17.29 and 17.63, respectively. Because financial predictors are always in use, the best possible depiction of prices is taken into account for that given time period. The goal of this study was to depict the market performance of a mixed portfolio and a pure stock portfolio in a strongly optimistic market environment, using the quarters of January, February, and March of 2021 as the testing period. Due to the great profitability of the general market, this study procedure was purposefully designed to see if statistical and nonlinear forecasting methods might make the investment process more effective than the general market return scenario. The Sharpe ratio in this diversified portfolio is over 16.5, indicating that each stock made sustainable gaining of around 65% throughout this 9-month period. Although we can see that three different stocks were present in this portfolio was included in the portfolio, the quarter-year jump is less than 6%, hence portfolio optimization automatically reduced them from getting selected.

Drawbacks & Further Improvements
It can be seen that the overall initialization of stock selection is solely based on financial ratios and market factor indicators, but this study requires more data because there are nearly ten additional financial ratios that are important for stock classification and selection. There are various statistical indicators such as EMA, MACD, and Bollinger bands that can be used as de facto investment indicators, but this process has become solely reliant on financial ratios, and only in EPS for investment purposes, which appears to be a narrow section for research preview. Furthermore, it was discovered that only LSTM was utilized in this study article to show the price predicting procedure based on ideas from previous studies. More study suggests that LSTM is the best approach, and its evidence should be successful in the investment based fore-casting procedure.

CONCLUSION:
Profit earnings for pure stock portfolios are greater, despite the fact that the observed Sharpe ratio lower for pure stock portfolios. So, in terms of profit poten-

ACKNOWLEDGEMENT:
Because this research paper is heavily data-driven, all data providers and internet resources will be completely reliant on the research paper's success.

CONFLICTS OF INTEREST:
In relation to the research, writing, and publishing of this paper, the authors have disclosed no potential conflicts of interest.