Abstract
1. Introduction
2. Literature Review
3. Background Knowledge
3.1. MeanVariance Optimization
Markowitz (1952) proposed the meanvariance (MV) model and was awarded the Noble Prize in Economics in 1990. The MV model made use of mean and variance, which are calculated from historical asset prices to quantify the expected return and risk of the generated portfolio. The MV model assumes that the investor would like to either maximize the expected return for a given level of risk or minimize risk for a given return (Kolm et al. 2014). However, in this study, we only show the optimization with minimum variance. The MV model is described as follows:
where N represents the total number of assets, which indicates the dimensionality of the optimization in the portfolio; ??�� is the weight of each i asset in the portfolio to be optimized; ?2�2 stands for the variance of the portfolio which generally refers to portfolio risk; ???��� is the covariance of return between asset i and j; ?� is the expected or target return; and ??�� is the average return on an individual asset i.
3.2. CNN
3.3. LSTM
Forget gate:
Input gate:
Output gate:
where ??��, ??��, and ??�� refer to forget gate, input gate, and output gate, respectively; w represents the weight of the matrix; ??��, ??��, and ??�� indicate the bias of the forget gate, input gate, and output gate, respectively; ?� stands for sigmoid function; ??�� and ℎ?ℎ� denote the input and current output at time t, respectively; ??�� is the value from the input gate at time t; and the hyperbolic function (tangent) is represented by tanh.
3.4. BiLSTM
Bidirectional long shortterm memory (BiLSTM) is an improved version of LSTM with the ability to access both forward and backward directions of the input feature (Dong et al. 2014). The key difference between BiLSTM and LSTM is that it uses two hidden layers. BiLSTM was shown to be better compared to LSTM in terms of timeseries data prediction (SiamiNamini et al. 2019). The hidden layer output of BiLSTM has the activation function for both forward and backward. The BiLSTM equations (Yang and Wang 2022) are described as follows:
where σ stands for the activation function of the model; ?� is the weight of the matrix; ??ℎ��ℎ is the weight of input (x) to the hidden layer (h); ??�� indicates the hidden layer input; and ??�� denotes the bias of the respective gates (x). The output is carried out by updating forward ℎ?→ℎ�→ and backward ℎ?←ℎ�← structures.
3.5. Robust Statistics
3.5.1. The Classical Robust Location Estimator
3.5.2. Huber’s Location Estimator
Huber (1964) proposed a good combination of mean and median, called the robust location estimator or Mestimator of a location, which can be described as follows:
where ?̂ �^ is a robust location estimator of the observation; ??�� is the variable of observation I; ?� stands for the error function. The robust location is a parameter ?� that minimizes the ?� function to ensure that the parameter provides the minimum error between the location estimator and all observations. Several methods have been proposed (Maronna et al. 2006) to find the local minimum of the ?� function such as the maximum likelihood estimator (MLE). In this paper, we use a numerical method, the Newton–Raphson method, to find the robust location estimator.
The Newton–Raphson method is an iterative method for solving nonlinear equations. To solve the equation ℎ(?)=0ℎ(�)=0, ℎℎ is set to be linearized for each iteration. In a location Mestimator, it is necessary to solve the equation ℎ(?)=0ℎ(�)=0 for ℎ(?)=???{?(?−?)}ℎ(�)=���{�(�−�)}. The iterations are defined as follows:
where ??�� is the value of the location estimator at iteration m. The ?� of observation ?� is defined by the following function with respect to a given positive constant of ?� as follows:
if ??�� is bounded, its derivative tends to be zero at infinity (Hampel et al. 2011). If ?� approaches infinity, then the ??�� is the mean. On the other hand, if ?� approaches zero, then the ??�� acts as the median. In this paper, we use ?=1.435�=1.435 in our proposed method. This value is similar to that used by Fox and Weisberg (2019).
4. Experimental Process
4.1. Data Preparation
4.1.1. Architecture of RCNNBiLSTM
4.1.2. Process of Training and Testing
4.1.3. Hyperparameter Setting

The number of epochs: An epoch is one round of full training. In our experiments, we set the number of epochs to 100 and performed our training. After training, we found that all training stops at a maximum of 100 to 120 epochs. Therefore, 100 is selected as the value for this hyperparameter.

The number of hidden layers: This is the number of layers between input and output layers. For the CNN network, we set the hidden convolutional layer counts to 100, 100, and 50. In the BiLSTM network, we set these numbers to 128 and 16.

Learning rate: This value is set for the accurate model convergence of the model in prediction. In our experiment, we set a learning rate to 0.0001. Many researchers recommend using a learning value lower than 0.01 (Hastie et al. 2017).

Optimizer: This is the optimization function used to obtain the best results. In our work, we use the Adam optimizer, as it works well for LSTM based networks.

Loss function: Mean Squared Error (MSE) was used as the loss function. Our implementation was written using MATLAB with GPU computing.
4.1.4. Stock Selection
Once all the stock prices are successfully predicted, highquality stocks are selected to perform in the optimization process one by one by ranking them in descending order based on the expected (average) return. The predicted stock price is used to calculate the stock return using Equation (17).
where ?̂ ?�^� is the return of the stock at time ?�, while ?̂ ?�^� is the predicted stock price at time ?� and ?̂ ?−1�^�−1 is the predicted stock price at time ?−1�−1.
4.2. Benchmark with Comparison Models
4.2.1. Comparison Model 1: RCNNBiLSTM+1/N
4.2.2. Comparison Model 2: Machine Learning+MV and Machine Learning+1/N
4.2.3. Comparison Model 3: Random+MV and Random+1/N
5. Experimental Results
5.1. Prediction Performance Results
5.1.1. Machine Learning Metrics
In this section, the predictive accuracy of machine learning models is evaluated by three criteria, mean absolute error (MAE), mean square error (MSE), and mean absolute percentage error (SMAPE), as they are extensively used as performance metrics (Jierula et al. 2021; Singh et al. 2021). These measures are described as follows:
where ?̂ ?�^� refers to the predicted price, ??�� represents the true value, and n indicates the total number of stocks used in the experiment.
5.1.2. Performance of the Prediction
5.2. Portfolio Optimization Results
5.2.1. Portfolio Metrics
In this section, the performance of different optimal portfolios is measured and compared using three criteria, the Sharpe ratio, mean return, and risk of the portfolio. These metrics are widely used to evaluate and compare the performance of stock portfolios (Lefebvre et al. 2020; Sikalo et al. 2022; Mba et al. 2022). Another portfolio metric is the Sharpe ratio, which can be described as follows:
where ??�� denotes the expected (average) return or mean return of the portfolio; ?� is the standard deviation or risk of the portfolio; and ??�� refers to riskfree assets. In this study, we use a riskfree asset rate of 0.022, according to the 10year Thai treasury rate.
5.2.2. Performance of DifferentSized Portfolios
6. Discussion and Conclusions
6.1. Discussion and Key Findings
6.2. Theoretical Implications
6.3. Limitations and Future Work
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Conflicts of Interest
Note
1 
RCNNBiLSTM is used for stock prediction before optimizing the portfolio using the 1/N model.

References
 Abrami, Rizkar, and Santoso Marsoem. 2021. Optimal portfolio Formation with Single Index Model Approach on Lq45 Stocks on Indonesia Stock Exchange. International Journal of Innovative Science and Research Technology 6: 1301–1309. [Google Scholar]
 Albawi, Saad, Tareq A. Mohammed, and Saad AlZawi. 2017. Understanding of a convolutional neural network. Paper presented at 2017 International Conference on Engineering and Technology (ICET), Antalya, Turkey, August 21–23. [Google Scholar]
 Alizadeh, Meysam, Roy Rada, Fariboz Jolai, and Elnaz Fotoohi. 2010. An adaptive neurofuzzy system for stock portfolio analysis. International Journal of Intelligent Systems 26: 99–114. [Google Scholar] [CrossRef]
 Almahdi, Saud, and Steve Y. Yang. 2017. An adaptive portfolio trading system: A riskreturn portfolio optimization using recurrent reinforcement learning with expected maximum drawdown. Expert Systems with Applications 87: 267–79. [Google Scholar] [CrossRef]
 Beheshti, Bijan. 2018. Effective stock selection and portfolio construction within US, International, and emerging markets. Frontiers in Applied Mathematics and Statistics 4: 17. [Google Scholar] [CrossRef]
 Ben Salah, Hanen, Jan G. De Gooijer, Ali Gannoun, and Mathieu Ribatet. 2018. Mean–variance and mean–semivariance portfolio selection: A multivariate nonparametric approach. Financial Markets and Portfolio Management 32: 419–36. [Google Scholar] [CrossRef]
 Bodnar, Taras, Stepan Mazur, and Yarema Okhrin. 2017. Bayesian estimation of the global minimum variance portfolio. European Journal of Operational Research 256: 292–307. [Google Scholar] [CrossRef][Green Version]
 Brown, David B., and Jame E. Smith. 2011. Dynamic portfolio optimization with transaction costs: Heuristics and dual bounds. Management Science 57: 1752–70. [Google Scholar] [CrossRef][Green Version]
 Chen, Wei, Haoyu Zhang, Mukesh Kumar Mehlawat, and Lifen Jia. 2021. Mean–variance portfolio optimization using machine learningbased stock price prediction. Applied Soft Computing 100: 106943. [Google Scholar] [CrossRef]
 Dixon, Matthew F., Igor Halperin, and Paul Bilokon. 2020. Machine Learning in Finance. Berlin and Heidelberg: Springer International Publishing. [Google Scholar]
 Dong, Li, Furu Wei, Chuanqi Tan, Duyu Tang, Ming Zhou, and Ke Xu. 2014. Adaptive Recursive Neural Network for Targetdependent Twitter Sentiment Classification. In Proceedings of the 52nd Annual Meeting of the Association for Computational Linguistics (Volume 2: Short Papers). Baltimore: Association for Computational Linguistics, pp. 49–54. [Google Scholar] [CrossRef][Green Version]
 Fischer, Thomas, and Christopher Krauss. 2018. Deep learning with long shortterm memory networks for financial market predictions. European Journal of Operational Research 270: 654–69. [Google Scholar] [CrossRef][Green Version]
 Fox, John, and Sanford Weisberg. 2019. An R Companion to Applied Regression. New York: SAGE Publication, Inc. [Google Scholar]
 Gao, Yo, Rong Wang, and Enmin Zhou. 2021. Stock prediction based on optimized LSTM and GRU models. Scientific Programming 2021: 4055281. [Google Scholar] [CrossRef]
 Hampel, Frank, Christian Hennig, and Elvezio Ronchetti. 2011. A smoothing principle for the Huber and other location Mestimators. Computational Statistics & Data Analysis 55: 324–37. [Google Scholar] [CrossRef]
 Hastie, Trevor, Jerome Friedman, and Robert Tisbshirani. 2017. The Elements of Statistical Learning: Data Mining, Inference, and Prediction. Berlin and Heidelberg: Springer. [Google Scholar]
 Henrique, Bruno M., Vinicius A. Sobreiro, and Herbert Kimura. 2019. Literature review: Machine learning techniques applied to financial market prediction. Expert Systems with Applications 124: 226–51. [Google Scholar] [CrossRef]
 Hochreiter, Sepp, and Jurgen Schmidhuber. 1997. Long shortterm memory. Neural Computation 9: 1735–80. [Google Scholar] [CrossRef] [PubMed]
 Huang, ChienFeng. 2012. A hybrid stock selection model using genetic algorithms and support vector regression. Applied Soft Computing 12: 807–18. [Google Scholar] [CrossRef]
 Huang, Ripeng, Shaojian Qu, Xiaoguang Yang, Fengmin Xu, Zeshui Xu, and Wei Zhou. 2021. Sparse portfolio selection with uncertain probability distribution. Applied Intelligence 51: 6665–84. [Google Scholar] [CrossRef]
 Huber, Peter J. 1964. Robust estimation of a location parameter. The Annals of Mathematical Statistics 35: 73–101. [Google Scholar] [CrossRef]
 Jierula, Alipujiang, Shuhong Wang, TaeMin OH, and Pengyu Wang. 2021. Study on accuracy metrics for evaluating the predictions of damage locations in deep piles using artificial neural networks with acoustic emission data. Applied Sciences 11: 2314. [Google Scholar] [CrossRef]
 Katsikis, Vasilios N., Spyridon D. Mourtas, Predrag S. Stanimirović, Shuai Li, and Xinwei Cao. 2021. Timevarying meanvariance portfolio selection under transaction costs and cardinality constraint problem via beetle antennae search algorithm (BAS). Operations Research Forum 2: 18. [Google Scholar] [CrossRef]
 Khan, Ameer Hamza, Xinwei Cao, Vasilio N. Katsikis, Predrag Stanimirovic, Ivona Brajevic, Shuai Li, Seifedine Kadry, and Y. Nam. 2020. Optimal portfolio management for engineering problems using nonconvex cardinality constraint: A computing perspective. IEEE Access 8: 57437–50. [Google Scholar] [CrossRef]
 Khan, Ameer Tamoor, Xinwei Cao, Inova Brajevic, Predrag S. Stanimirovic, Vasilio N. Katsikis, and Shuai Li. 2022. Nonlinear activated beetle antennae search: A novel technique for nonconvex taxaware portfolio optimization problem. Expert Systems with Applications 197: 116631. [Google Scholar] [CrossRef]
 Khan, Ameer Tamoor, Xinwei Cao, Shuai Li, Bin Hu, and Vasilio N. Katsikis. 2021. Quantum beetle antennae search: A novel technique for the constrained portfolio optimization problem. Science China Information Sciences 64: 152204. [Google Scholar] [CrossRef]
 Kolm, Petter N., Reha Tütüncü, and Frank J. Fabozzi. 2014. 60 years of portfolio optimization: Practical challenges and current trends. European Journal of Operational Research 234: 356–71. [Google Scholar] [CrossRef]
 Le Caillec, JeanMarc, Alya Itani, Didier Guriot, and Yves Rakotondratsimba. 2017. Stock picking by probability–possibility approaches. IEEE Transactions on Fuzzy Systems 25: 333–49. [Google Scholar] [CrossRef]
 Lefebvre, William, Gregoire Loeper, and Huyen Pham. 2020. Meanvariance portfolio selection with Tracking Error Penalization. Mathematics 8: 1915. [Google Scholar] [CrossRef]
 Li, Ting, Weiguo Zhang, and Weijun Xu. 2015. A fuzzy portfolio selection model with background risk. Applied Mathematics and Computation 256: 505–13. [Google Scholar] [CrossRef]
 Lozza, Sergio Ortobelli, Enrico Angelelli, and Daniele Toninelli. 2011. Setportfolio selection with the use of market stochastic bounds. Emerging Markets Finance and Trade 47: 5–24. [Google Scholar] [CrossRef][Green Version]
 Ma, Yilin, Ruizhu Han, and Weizhing Wang. 2021. Portfolio optimization with return prediction using Deep Learning and machine learning. Expert Systems with Applications 165: 113973. [Google Scholar] [CrossRef]
 Markowitz, Harry. 1952. Portfolio selection*. The Journal of Finance 7: 77–91. [Google Scholar] [CrossRef]
 Maronna, Ricardo A., Douglas Martin, and Víctor J. Yohai. 2006. Robust Statistics: Theory and Methods. Hoboken: John Wiley & Sons. [Google Scholar]
 Maronna, Ricardo A., Douglas Martin, Victor J. Yohai, and Matías SalibiánBarrera. 2019. Robust Statistics Theory and Methods (with R). Hoboken: John Wiley & Sons. [Google Scholar]
 Mba, Jules Clement, Kofi Agyarko Ababio, and Samuel Kwaku Agyei. 2022. Markowitz meanvariance portfolio selection and optimization under a behavioral spectacle: New empirical evidence. International Journal of Financial Studies 10: 28. [Google Scholar] [CrossRef]
 Milošević, Nemanja, and Milos Racković. 2019. Classification based on missing features in deep convolutional neural networks. Neural Network World 29: 221–34. [Google Scholar] [CrossRef]
 Mitra Thakur, Gour Sundar, Rupak Bhattacharyya, and Seema Sarkar (Mondal). 2018. Stock portfolio selection using Dempster–Shafer Evidence theory. Journal of King Saud UniversityComputer and Information Sciences 30: 223–35. [Google Scholar] [CrossRef][Green Version]
 Nguyen, Than Thi. 2014. Selection of the right risk measures for portfolio allocation. International Journal of Monetary Economics and Finance 7: 135. [Google Scholar] [CrossRef]
 Ortiz, Roberto, Mauricio Contreras, and Cristhian Mellado. 2021. Improving the volatility of the optimal weights of the Markowitz model. Economic ResearchEkonomska Istraživanja, September 29. [Google Scholar] [CrossRef]
 Paiva, Felipe D., Rodrigo T. Cardoso, Gustova P. Hanaoka, and Wendel M. Duarte. 2019. Decisionmaking for financial trading: A fusion approach of machine learning and portfolio selection. Expert Systems with Applications 115: 635–55. [Google Scholar] [CrossRef]
 Rahiminezhad Galankashi, Masoud, Farimah Mokhatab Rafiei, and Maryam Ghezelbash. 2020. Portfolio selection: A fuzzyANP approach. Financial Innovation 6: 17. [Google Scholar] [CrossRef]
 Rather, Akhter M., Arun Agarwal, and V. N. Sastry. 2015. Recurrent neural network and a hybrid model for prediction of Stock returns. Expert Systems with Applications 42: 3234–41. [Google Scholar] [CrossRef]
 Sadouk, Lamyaa. 2019. CNN approaches for Time Series Classification. Time Series AnalysisData, Methods, and Applications, November 5. [Google Scholar] [CrossRef][Green Version]
 Sharpe, William F., and Harry M. Markowitz. 1989. Meanvariance analysis in portfolio choice and capital markets. The Journal of Finance 44: 531. [Google Scholar] [CrossRef]
 SiamiNamini, Sima, Neda Tavakoli, and Akbar S. Namin. 2019. The performance of LSTM and BiLSTM in forecasting time series. Paper presented at 2019 IEEE International Conference on Big Data (Big Data), Los Angeles, CA, USA, December 9–12. [Google Scholar]
 Sikalo, Mirza, Almira ArnautBerilo, and Azra Zaimovic. 2022. Efficient Asset Allocation: Application of game theorybased model for superior performance. International Journal of Financial Studies 10: 20. [Google Scholar] [CrossRef]
 Singh, Upma, Mohammad Rizwan, Muhannad Alaraj, and I. Alsaidan. 2021. A machine learningbased gradient boosting regression approach for wind power production forecasting: A step towards Smart Grid Environments. Energies 14: 5196. [Google Scholar] [CrossRef]
 Soeryana, E., N. Fadhlina, Sukono, E. Rusyaman, and S. Supian. 2017. Meanvariance portfolio optimization by using time series approaches based on logarithmic utility function. IOP Conference Series: Materials Science and Engineering 166: 012003. [Google Scholar] [CrossRef][Green Version]
 Ta, VanDai, ChuanMing Liu, and Direselign A. Tadesse. 2020. Portfolio optimizationbased stock prediction using longshort term memory network in quantitative trading. Applied Sciences 10: 437. [Google Scholar] [CrossRef][Green Version]
 Tu, Juntu, and Guofu Zhou. 2010. Incorporating economic objectives into bayesian priors: Portfolio choice under parameter uncertainty. Journal of Financial and Quantitative Analysis 45: 959–86. [Google Scholar] [CrossRef]
 Wan, Yuqing, Raymond Y. Lau, and YainWhar Si. 2020. Mining subsequent trend patterns from financial time series. International Journal of Wavelets, Multiresolution and Information Processing 18: 2050010. [Google Scholar] [CrossRef]
 Wang, Wuyu, Weizi Li, Ning Zhang, and Kecheng Liu. 2020. Portfolio formation with preselection using deep learning from longterm financial data. Expert Systems with Applications 143: 113042. [Google Scholar] [CrossRef]
 Yang, Mo, and Jing Wang. 2022. Adaptability of Financial Time Series prediction based on bilstm. Procedia Computer Science 199: 18–25. [Google Scholar] [CrossRef]
 Zaimovic, Azra, Adna Omanovic, and Almira ArnautBerilo. 2021. How many stocks are sufficient for equity portfolio diversification? A review of the literature. Journal of Risk and Financial Management 14: 551. [Google Scholar] [CrossRef]