Stock Selection Using Machine Learning Based on Financial Ratios

: Stock prediction has garnered considerable attention among investors, with a recent focus on the application of machine learning techniques to enhance predictive accuracy. Prior research has established the effectiveness of machine learning in forecasting stock market trends, irrespective of the analytical approach employed, be it technical, fundamental, or sentiment analysis. In the context of ﬁscal year-end selection, the decision may initially seem straightforward, with December 31 being the apparent choice, as discussed by B. Kamp in 2002. The primary argument for a uniform ﬁscal year-end centers around comparability. When assessing the ﬁnancial performance of two ﬁrms with differing ﬁscal year-ends, substantial shifts in the business environment during non-overlapping periods can impede meaningful comparisons. Moreover, when two ﬁrms merge, the need to synchronize their annual reporting often results in shorter or longer ﬁscal years, complicating time series analysis. In the US S&P stock market, misaligned ﬁscal years lead to variations in report publication dates across different industries and market segments. Since the ﬁnancial reporting dates of US S&P companies are determined independently by each listed entity, relying solely on these dates for investment decisions may prove less than entirely reliable and impact the accuracy of return prediction models. Hence, our interest lies in the synchronized ﬁscal year of the TW stock market, leveraging machine learning models for fundamental analysis to forecast returns. We employed four machine learning models: Random Forest (RF), Feedforward Neural Network (FNN), Gated Recurrent Unit (GRU), and Financial Graph Attention Network (FinGAT). We crafted portfolios by selecting stocks with higher predicted returns using these machine learning models. These portfolios outperformed the TW50 index benchmarks in the Taiwan stock market, demonstrating superior returns and portfolio scores. Our study’s ﬁndings underscore the advantages of using aligned ﬁnancial ratios for predicting the top 20 high-return stocks in a mid-to-long-term investment context, delivering over 50% excess returns across the four models while maintaining lower risk proﬁles. Using the top 10 high-return stocks produced over 100% relative returns with an acceptable level of risk, highlighting the effectiveness of employing machine learning techniques based on ﬁnancial ratios for stock prediction.


Introduction
When considering the fiscal year-end selection, our primary focus is aligning it with the Taiwanese stock market's fiscal year to conduct a comprehensive analysis of mid-tolong-term stock trends.This alignment is instrumental for comparing various companies' business performances.Our stock analysis encompasses three fundamental aspects: Technical Analysis [1]: This approach involves using stock prices and trading volumes to make predictions.such as financial statements, products, and management quality, to make predictions.
Sentiment Analysis: This analysis entails using data from social media, news, and other sources to make predictions.
Given the stock market's high volatility and daily fluctuations, stock prices may not always accurately reflect their intrinsic values due to external factors like economic indicators, geopolitical events, and market sentiment.Fundamental analysis, in contrast, provides insights into a company's financial health and future performance.This analysis is primarily suited for making predictions over medium to long-term periods, typically spanning quarters and years.
While most published studies primarily concentrate on the US S&P market using fundamental analysis, the misalignment of publishing timeframes in US S&P financial reports poses a challenge.Different companies in the US have varying fiscal year-end dates, making it challenging to compare their quarterly data effectively.For instance, Company A's fiscal year ends on 24 September, and its first quarter runs from 26 September to 25 December, whereas Company B's fiscal year ends on 30 June, with its first quarter running from 1 July to 30 September.This misalignment necessitates comparing data from different quarters to establish a unified timeframe as in Figure 1.
It is important to note that a fiscal year (FY) refers to a specific start and end time chosen by a company based on its business nature and revenue cycle.While many companies align their fiscal year with the calendar year, US stock market companies are allowed to freely choose their fiscal year start date, which does not necessarily begin on 1 January.In Taiwan, financial reports follow standardized release dates, with Q1 quarterly reports released before 15 May, Q2 before 14 August, Q3 before 14 November, and annual and Q4 financial reports before 31 March of the following year, as shown in Figure 2. To eliminate the influence of the misaligned fiscal year in the US stock market, we opt to focus on the TW stock market, as depicted in Figure 2. In the S&P stock market, some companies, such as Company A, start their fiscal year in September, and others, such as Company B, start their fiscal year in April.The misaligned starting point of the fiscal year makes the publishing of financial reports time misaligned due to different market businesses.

Figure 1.
In the S&P stock market, some companies, such as Company A, start their fiscal year in September, and others, such as Company B, start their fiscal year in April.The misaligned starting point of the fiscal year makes the publishing of financial reports time misaligned due to different market businesses.
It is important to note that a fiscal year (FY) refers to a specific start and end time chosen by a company based on its business nature and revenue cycle.While many companies align their fiscal year with the calendar year, US stock market companies are allowed to freely choose their fiscal year start date, which does not necessarily begin on 1 January.In Taiwan, financial reports follow standardized release dates, with Q1 quarterly reports released before 15 May, Q2 before 14 August, Q3 before 14 November, and annual and Q4 financial reports before 31 March of the following year, as shown in Figure 2. To eliminate the influence of the misaligned fiscal year in the US stock market, we opt to focus on the TW stock market, as depicted in Figure 2.
Utilizing financial statements for fundamental analysis in the stock market, inconsistent financial statement release times, such as in the US S&P, can lead to temporal inconsistencies when training models.This inconsistency can decrease the accuracy of model predictions.Using the financial report for S&P stock prediction, Y. Huang et al. [2] proposed a machine learning model of random forest with a portfolio score of 0.414 and an FNN model with a portfolio score of 0.202.Z.Y.Lu et al. [3] proposed deep reinforcement learning for portfolio management in the S&P market.The RF model obtained a portfolio score of 0.466, and the FNN model obtained a portfolio score of 0.547.Utilizing financial statements for fundamental analysis in the stock market, inconsistent financial statement release times, such as in the US S&P, can lead to temporal inconsistencies when training models.This inconsistency can decrease the accuracy of model predictions.Using the financial report for S&P stock prediction, Y. Huang et al. [2] proposed a machine learning model of random forest with a portfolio score of 0.414 and an FNN model with a portfolio score of 0.202.Z.Y.Lu et al. [3] proposed deep reinforcement learning for portfolio management in the S&P market.The RF model obtained a portfolio score of 0.466, and the FNN model obtained a portfolio score of 0.547.
We believe that utilizing aligned financial reports will enhance the accuracy of predicting returns further.As such, our focus remains on the TW market stock pool, where the fiscal year aligns with January, allowing financial reports to more clearly reflect economic trends.With this alignment, the modeling of machine learning and deep learning can help select the top 10 or 20 stocks with the highest returns to suggest to investors.
Our approach involves calculating 18 financial ratios [4] to predict medium to longterm stock market performance and the potential return of each stock for the next quarter.We employ quarterly models to predict return values, rank stocks in the pool, and recommend the most profitable stocks for the subsequent quarter.
In summary, our models showed their effectiveness in predicting stock returns in their respective markets, with several key findings: 1. Aligning data time periods enhances return prediction accuracy and can be applied to other stock markets with fixed fiscal years.2. Four different types of nonlinear models were tested, each with its own strengths and limitations in handling temporal and spatial data dependencies.3. The top 10 and top 20 stock portfolios generated by our models outperformed the TW50 index with substantial excess returns.4. Our model-selected portfolios also demonstrated lower risk compared to random stock selection or the TW50 index.
In the Taiwanese stock market, investors can now choose 10 or 20 stocks from the stock pool to achieve significant relative returns with acceptable risk, thanks to our modelgenerated portfolios, in contrast to random stock selection or relying on the TW50 index, which uses a company's capitalization size as an index.
This paper is organized as follows.We first review the relevant literature in Section 2, followed by presenting the relevant methodologies as in Section 3. Section 4 describes our methodology details.We report the experimental results in Section 5, conclusions in Section 6, and future work in Section 7. In the TW stock market, the fiscal year is aligned to start in January as Q1 for all companies.And the yearly financial report will be public before March the next year.
We believe that utilizing aligned financial reports will enhance the accuracy of predicting returns further.As such, our focus remains on the TW market stock pool, where the fiscal year aligns with January, allowing financial reports to more clearly reflect economic trends.With this alignment, the modeling of machine learning and deep learning can help select the top 10 or 20 stocks with the highest returns to suggest to investors.
Our approach involves calculating 18 financial ratios [4] to predict medium to longterm stock market performance and the potential return of each stock for the next quarter.We employ quarterly models to predict return values, rank stocks in the pool, and recommend the most profitable stocks for the subsequent quarter.
In summary, our models showed their effectiveness in predicting stock returns in their respective markets, with several key findings: 1.
Aligning data time periods enhances return prediction accuracy and can be applied to other stock markets with fixed fiscal years.

2.
Four different types of nonlinear models were tested, each with its own strengths and limitations in handling temporal and spatial data dependencies.

3.
The top 10 and top 20 stock portfolios generated by our models outperformed the TW50 index with substantial excess returns.4.
Our model-selected portfolios also demonstrated lower risk compared to random stock selection or the TW50 index.
In the Taiwanese stock market, investors can now choose 10 or 20 stocks from the stock pool to achieve significant relative returns with acceptable risk, thanks to our modelgenerated portfolios, in contrast to random stock selection or relying on the TW50 index, which uses a company's capitalization size as an index.
This paper is organized as follows.We first review the relevant literature in Section 2, followed by presenting the relevant methodologies as in Section 3. Section 4 describes our methodology details.We report the experimental results in Section 5, conclusions in Section 6, and future work in Section 7.

Literature Review
In recent years, numerous studies have explored the application of machine learning techniques in stock prediction.H. Yu et al. [10] introduced SVM and PCA in 2014, while X.D. Zhang et al. [11] experimented with AdaBoost in 2016.Additionally, K. Sabbar et al. [12] ventured into stock prediction in 2023, incorporating machine learning and deep learning models.Notably, V. Dhingra et al. [13] in 2021 and K. Olorunnimbe et al. [14] in 2023 delved into deep learning models for this purpose.Most of these studies center on technical and sentiment analysis.
Beyond predictive modeling, there have been surveys and reviews in recent years.I. Ibidapo et al. [15] conducted a study in 2017, and R. M. Dhokane et al. [16] carried out a review in 2023.
In a historical context, the works of B. Graham [17] in 1962 profoundly influenced stock selection and investment.These works span diverse topics, encompassing value investing, fundamental analysis, behavioral finance, risk management, and various investment philosophies rooted in Graham's enduring principles.
In 1999, Quah and Srinivasan [18] developed a model employing a Feedforward Neural Network (FNN) for stock selection based on quarterly fundamental financial factors.The model demonstrated remarkable success in outperforming the market during testing.
In 2003, Eakins and Stansell [19] employed neural networks to predict stock prices using financial ratios and yearly financial data from 1975 to 1996.Their portfolio of the predicted top 50 stocks outperformed the S&P 500 and Dow Jones Industrial Average.
In 2008, T.S. Quah [20] focused on applying neural networks to fundamental analysis for stock selection in the Dow Jones Industrial Average (DJIA).This research aimed to enhance decision-making processes, offering valuable insights for portfolio management.
In 2018, Namdari and Li [1] utilized an FNN for fundamental analysis to predict stock trends by analyzing 12 financial ratios.Their dataset included 578 companies listed on Nasdaq between June 2012 and February 2017.The FNN model employing fundamental analysis outperformed the one using historical prices.
In 2021, Z.Y.Lu and S.M. Yuan [3] employed an FNN model with 18 financial ratios and sector dummy variables to predict potential stock returns for the next quarter.This approach improved prediction accuracy by incorporating sectors as dummy variables.
In the same year, Huang Y., Capretz L.F., and Ho D. [2] used FNN, Random Forest (RF), and the Adaptive Neural Fuzzy Inference System (ANFIS) to predict potential stock returns by analyzing 20 financial statements and returns.Their portfolio selections yielded substantial excess returns.W. Chen [21] et al. proposed a novel model, the Graph Convolutional Feature-based Convolutional Neural Network (GC-CNN), for stock prediction in 2021.This model incorporates both individual stock information and stock market data, demonstrating superior performance and adaptability for long-term stock trend prediction.
In 2021, D. Zhang et al. [22] explored the backpropagation algorithm in neural networks for stock price pattern classification and prediction, offering valuable insights for investors and traders.
In 2022, J. Hong et al. [23] introduced a correlational strategy focusing on the analysis of stock technical indicators (STI) and stock movement using neural networks and other machine learning tools.This approach aims to improve prediction accuracy and reduce error rates in stock market analysis, catering to various stockholders' investment decisions.

Preliminaries
In [2], the RF and FNN have better portfolio scores.The GRU and FinGAT models can capture temporal and spatial dependency.Therefore, we chose these four models for our study.

Random Forest (RF)
Random Forest (RF) stands out as an ensemble learning technique purposefully tailored for stock selection.It draws its inspiration from the concept of decision trees and, during the training process, constructs a multitude of trees.Initially developed by Leo Breiman [5] and Adele Cutler [6], this algorithm is engineered to forge a predictive model for a target variable's value by assimilating straightforward decision rules from the dataset's features.
In the realm of stock selection, Random Forest employs a strategic approach.It leverages a random subset of training data and input characteristics to craft each tree within the set.This approach serves the dual purpose of mitigating overfitting concerns and bolstering the model's capacity to generalize effectively when confronted with unseen data.By incorporating the practice of bootstrap aggregation (bagging), the algorithm further augments tree diversity and curtails variance.
The paramount aim of employing Random Forest for stock selection revolves around forecasting stock performance and behavior, guided by a mosaic of characteristics and factors.Via an examination of historical data and patterns, this model can furnish insights into the potential value or trajectory of stocks, as depicted in Figure 3.Such insights are of paramount importance to investors and traders as they navigate the terrain of making well-informed decisions.

Feedforward Neural Network (FNN)
The Feedforward Neural Network (FNN) [7,19,[24][25][26][27][28][29] emerges as a robust artificial neural network model with notable relevance in the domain of stock selection.Typically, it consists of three or more layers, encompassing an input layer, at least one hidden layer, and an output layer.As depicted in Figure 3, each neuron within a layer establishes connections with every neuron in the subsequent layer.
In the context of stock selection, FNNs are harnessed to model and dissect intricate non-linear relationships between input variables and desired outcomes, such as forecasting stock returns or identifying potential investment prospects.The FNN's prowess in grasping complex data patterns and dependencies positions it as a highly suitable tool for this endeavor.
The inception of FNN can be traced back to 1990 when Kimoto et al. [24] published its use for forecasting buying and selling signals for the TOPIX index, spanning from January 1987 to September 1989.
In summary, the FNN plays an invaluable role in stock selection by adeptly modeling and scrutinizing non-linear associations between inputs and outputs.Leveraging the backpropagation algorithm, the FNN can be trained to enhance its performance and elevate the precision of stock predictions and investment decisions.

Gate Recurrent Unit (GRU)
The Gated Recurrent Unit (GRU) is a recurrent neural network (RNN) architecture introduced by Kyunghyun Cho et al. [8] in 2014.It exhibits similarities with the long-shortterm memory (LSTM) [26] network and delivers comparable performance.Nevertheless, GRU stands out for its efficiency, as it necessitates fewer parameters, resulting in computational savings compared to LSTM.You can observe the architecture of GRU in Figure 3.
GRU is expressly tailored to handle sequential data, enabling the smooth flow of information from one step to the next.In 2018, M.A. Hossain et al. [30] successfully demonstrated its efficiency in capturing temporal dependencies in sequential data, making it a promising tool for stock selection.Notably, when tested with S&P500 data, it exhibited superior capability in managing the stochastic nature of stock price movements, thus minimizing errors.
In summary, GRU, with its adept handling of sequential data, proves highly effective in analyzing historical stock data and uncovering influential patterns and trends that can impact future stock performance.As a result, GRU assumes a pivotal role in stock prediction models, contributing to the precision of stock selection for investment purposes.

Graph Attention Network (GAT)
An escalating body of research is delving into the application of graph neural networks (GNNs) within the financial realm, driven by their aptitude for capturing the intricate interconnections between stocks.A study published in 2021 [29] synthesized the typical architectures of GNNs deployed in the financial sector.
The Graph Attention Network (GAT) [31] is a specific subtype of graph neural network (GNN) renowned for its proficiency in dissecting the intricate relationships prevalent in stock markets.The financial domain has witnessed a growing number of investigations delving into the utilization of graph neural networks (GNNs) due to their adeptness at comprehending the intricate linkages between stocks.This research has neatly outlined the prevailing structural patterns of GNNs as applied in finance.

Financial Graph Attention Network (FinGAT)
In 2021, Hsu, Y. L. et al. [9] introduced an innovative network named FinGAT, which amalgamates the capabilities of the Gated Recurrent Unit (GRU) and the Graph Attention Network (GAT) to forecast stock returns using price data.This method ranked stocks based on their predicted returns and constructed portfolios accordingly.The dataset encompassed 100 stocks in the Taiwan stock market, 424 in the S&P500 index, and 1026 in the NASDAQ index.Impressively, FinGAT outperformed other competing models, including FNN, GRU, and RankLSTM.
FinGAT stands as an advanced neural network meticulously designed for the precise prediction of stock returns.It effectively harnesses the power of graph attention mechanisms to grasp the intricate relationships between diverse stocks.The system comprises three pivotal components: the Gated Recurrent Unit (GRU) for sequential learning, the intra-sector relationship within the Graph Attention Network (GAT), and the inter-sector relationship of GAT, as visualized in Figure 3.The synergy of GAT and GRU is the defining attribute of FinGAT, enabling it to efficiently comprehend and leverage the relationships both within and among sectors of stocks.[32] and GAT [31]; temporal dependency: RNN [33] and GRU [26]; external factor: MLP, FNN [7], and Random Forest [5,6]; and spatial and temporal dependency: FinGAT [9].

Stock Pool of TW 97 Stocks
In the context of the Taiwan stock market, our stock pool consists of a fixed set of 97 stocks.These selections were made based on their capitalization rankings on the Taiwan Stock Exchange as of March 2022 and are immutable once established.To benchmark our analysis, we utilize the TW50 [34] index, a stock market index comprising the top 50 companies listed on the Taiwan Stock Exchange, arranged according to market capitalization.These 50 entities collectively represent approximately 70% of the entire market capitalization of the Taiwanese equity market.

Methodology 4.1. Stock Pool of TW 97 Stocks
In the context of the Taiwan stock market, our stock pool consists of a fixed set of 97 stocks.These selections were made based on their capitalization rankings on the Taiwan Stock Exchange as of March 2022 and are immutable once established.To benchmark our analysis, we utilize the TW50 [34] index, a stock market index comprising the top 50 companies listed on the Taiwan Stock Exchange, arranged according to market capitalization.These 50 entities collectively represent approximately 70% of the entire market capitalization of the Taiwanese equity market.
We curated these 97 stocks within the stock pools, spanning from 2013Q1 to 2020Q2, encompassing a total of 27 quarters' worth of financial data.We employed this comprehensive dataset to construct four distinct models aimed at predicting relative returns.Our objective is to identify the top 10 and top 20 stocks which will form our investment portfolio.As a point of reference, the return rate baseline is the portfolio tracked by the TW50 index, which comprises the top 50 companies sorted by market capitalization.

Financial Ratios of 18 Ratios as Attributes
We use 18 financial ratios as input for models, which are the same as those used in research [3].The 18 financial ratios are listed, and the calculation formula is given in Table 1.
Table 1.Financial ratios used for the training model.

Liquidity Ratios Current
• Liquidity ratios: Liquidity ratios measure a company's ability to pay off its shortterm debts.

•
Leverage ratios: Leverage ratios measure the amount of debt a company has relative to its assets or equity.These ratios are often used by investors and creditors to assess the riskiness of a company's operations and its ability to meet long-term debt obligations.

•
Asset efficiency ratios: Asset efficiency ratios measure how effectively a company uses and manages its assets to generate revenue.

•
Market value ratios: Market value ratios are used to evaluate a company's stock price in relation to its earnings, sales, and book value.
• Profitability ratios: Profitability ratios measure a company's ability to generate profits.

Moving Time Period
In Table 2, the RF and FNN models encompass a total of 27 quarters for each moving time period.The initial data from the moving time period span from 2013Q1 to 2019Q4, and so forth.We partitioned these data into three segments: the training set, the validation set, and the test set, comprising 20 quarters, 6 quarters, and 1 quarter, respectively.The training set facilitates model weight optimization, and the validation set aids in finetuning hyperparameters, ensuring model convergence without overfitting.Subsequently, we employ the test set to predict the relative return of the 97 stocks within the pool.A comprehensive analysis of the model prediction results is presented in Section 4. In Table 3, the GRU and FinGAT models span a total of 30 quarters for each moving time period, with the initial data originating from 2013Q1 to 2020Q2 and so on.We segment this data into the training set, validation set, and test set, consisting of 20 quarters, 6 quarters, and 4 quarters, respectively.Similar to the previous models, the training set facilitates model weight optimization, and the validation set aids in hyperparameter fine-tuning, guaranteeing model convergence without overfitting.The test set is then leveraged to predict relative returns across a total of 11 models.A detailed evaluation of the model prediction results is expounded upon in Section 4. Via these distinct moving time periods, we established 11 trained models, each attuned to specific temporal data segments.This approach enables us to effectively glean insights into the stock trends within our stock pool.It serves as the foundation for our training and testing datasets for RF, FNN, GRU, and FinGAT, empowering comprehensive analysis and evaluation.

Evaluation Metrics
To assess the performance of portfolios assembled with each model, we employ four key metrics: excess return, top-k precision, and portfolio score.These metrics collectively address both the return profitability and risk associated with the portfolios.

Excess Return
Excess returns are a useful measure to evaluate the performance of an investment portfolio.By comparing portfolio returns to those of a benchmark, investors can determine whether the portfolio is generating value above the benchmark.
The excess return on a benchmark (ER benchmark ) of portfolio p for quarter q is formulated as follows in Equation (1): where R p (q) is the actual absolute return, and R TW50 (q) is the actual absolute return of our TW stock benchmark of the TW50 index.

Top-k Precision
The precision of k is used to measure the percentage of overlap between a list of top k stocks with the highest predicted returns, which is 'predicted top k stocks', and a list of top k stocks with the highest actual return, which is 'actual top k stocks'.The higher the precision of the top-k, the more accurate the prediction of the model will be.
Top-k precision can be calculated as follows via Equation (2): L@K R S q is the expected top-k precision of a portfolio consisting of randomly selected k stocks as Equation (3).In that case, top-k precision can be served as follows: The benchmarks for the precision of top-10 and top-20 in the Taiwan stock market are 10.3% (calculated as 10/97) and 20.6% (calculated as 20/97), respectively.

Portfolio Score
When assessing a portfolio's performance, it is crucial to account for not only the return's profitability but also the inherent risk associated with the investment.Both elements collectively paint a more comprehensive picture of the portfolio's performance.For instance, even if a portfolio exhibits the potential for high returns if its performance is marked by significant volatility from one quarter to the next, it may not be an attractive choice for investors.
In our study, we use the same modified portfolio score [2] to measure the equally weighted portfolio p as used in previous research.In Equation (4), a higher portfolio score indicates the selection of a portfolio with high return and low risk.
R p in Equation ( 5) is the average actual relative return that had subtracted with the TW50 index quarterly, as given below: R p (q) is the actual absolute return for quarter q.After data collection, the following steps are 'data standardization' to ensure the mean of the characteristic is at 0 and the standard deviation is at 1 for all features.Data standardization can help create a more consistent and reliable dataset.Moreover, it can help the algorithm to search the effective path for relative global minimum and not be easily trapped by local minimum during model training.We use the z score to standardize the vector of features x with the following formula: where µ is the mean of x, and σ is the standard deviation of x.

Relative Return as Target y in Training
The absolute returns quarterly of stock is defined as follows in Equation ( 6): price(q end price(q start − 1 The price ( q end is the stock's price on the last day of quarter q, and the ( q start is the stock's price on the first day of quarter q. The optimization variable y is the relative quarterly return of a stock as in Equation ( 7): R(q) − R TW50 (q) R(q) is the quarterly absolute return of stock for quarter q, and the R TW50 (q) is the quarterly return of the TW50 index as a benchmark portfolio.
The absolute return of a stock is susceptible to influence not just from the company's performance but also from the broader stock market conditions.This inherent volatility makes it a less stable target for model learning.Consequently, we perform preprocessing by converting absolute returns into relative returns, which serves as the training target for our modeling efforts.

Training Procedure
The training set, validation set, and test set are constructed by progressing via different time periods, as elucidated in Section 3.3.
Once a model has been meticulously trained and fine-tuned, the test data are fed into the respective moving time period model.This process yields predicted returns for all 97 stocks within the portfolio.Subsequently, the returns are sorted in descending order for each moving time period.Following this sorting, the top 10 stocks with the highest returns and the top 20 stocks with the highest returns are chosen to constitute the top 10 and top 20 portfolios across all moving time periods, as depicted in Figure 4.
For each model, we use the scikit-learn library in Python to develop models.And we list the hyperparameters of each model in Sections 3.1-3.5,including RF, FNN, GRU, and FinGAT.

Random Forest Hyperparameters
We use Pytorch to develop the FNN models.Hyperparameters of random forest are tuned with the validation set for preventing overfitting where the number of estimators is 1000 and the optimization criterion used squared_error.
The test result shows that the random forest model for generating top-10 as a portfolio with a 109.2%relative return of 109.2% to the TW50 index and top-20 as a portfolio with a 50.1% relative return of 50.1% to the TW50 index.The 97 composite index achieves only a 24.5% relative return of 24.5% to the TW50 index.
In Figure 5, the importance of the random forest characteristics shows that all 16 financial indices are similar in importance with no redundant features.Once a model has been meticulously trained and fine-tuned, the test data are fed into the respective moving time period model.This process yields predicted returns for all 97 stocks within the portfolio.Subsequently, the returns are sorted in descending order for each moving time period.Following this sorting, the top 10 stocks with the highest returns and the top 20 stocks with the highest returns are chosen to constitute the top 10 and top 20 portfolios across all moving time periods, as depicted in Figure 4.For each model, we use the scikit-learn library in Python to develop models.And we list the hyperparameters of each model in Sections 3.1-3.5,including RF, FNN, GRU, and FinGAT.

Random Forest Hyperparameters
We use Pytorch to develop the FNN models.Hyperparameters of random forest are tuned with the validation set for preventing overfitting where the number of estimators is 1000 and the optimization criterion used squared_error.
The test result shows that the random forest model for generating top-10 as a portfolio with a 109.2%relative return of 109.2% to the TW50 index and top-20 as a portfolio with a 50.1% relative return of 50.1% to the TW50 index.The 97 composite index achieves only a 24.5% relative return of 24.5% to the TW50 index.
In Figure 5, the importance of the random forest characteristics shows that all 16 financial indices are similar in importance with no redundant features.For each model, we use the scikit-learn library in Python to develop models.And we list the hyperparameters of each model in Sections 3.1-3.5,including RF, FNN, GRU, and FinGAT.

Random Forest Hyperparameters
We use Pytorch to develop the FNN models.Hyperparameters of random forest are tuned with the validation set for preventing overfitting where the number of estimators is 1000 and the optimization criterion used squared_error.
The test result shows that the random forest model for generating top-10 as a portfolio with a 109.2%relative return of 109.2% to the TW50 index and top-20 as a portfolio with a 50.1% relative return of 50.1% to the TW50 index.The 97 composite index achieves only a 24.5% relative return of 24.5% to the TW50 index.
In Figure 5, the importance of the random forest characteristics shows that all 16 financial indices are similar in importance with no redundant features.

FNN Hyperparameters
We use Pytorch to develop FNN models.Hyperparameters of FNN are tuned using the validation set to prevent overfitting, as shown in Table 4.We use Pytorch to develop GRU models.Hyperparameters of GRU are tuned using the validation set to prevent overfitting, as shown in Table 5.We use Pytorch to develop FinGAT models.Hyperparameters of FinGAT are tuned using the validation set to prevent overfitting, as shown in Table 6.Table 6.Hyperparameters of FinGAT models.

Number of layers in GAT 1
Dimension of Hidden State of GRU and GAT 20 GRU time step (Ratios of four quarters are inputted to GRU) 3

Activation Function Sigmoid
Loss Function MSE

Optimizer Adam
Learning Rate Scheduler ReduceLROnPlateau with factor = 0.1 There are a total of 11 sectors of TW stocks, and the distribution for the 97 stocks in the pool is shown in Table 7.

Results
We plot the relative return of four models in Figure 6 by quarter.Each trained model is used to select the highest 10 and highest 20 stocks for the top-10 and top-20 relative returns in red and orange, respectively.The TW 97 used all stocks in the pool to investigate and calculate the relative return in the green line.Then, the TW50 index is the portfolio as the benchmark for stock selection in the blue line.

Results
We plot the relative return of four models in Figure 6 by quarter.Each trained model is used to select the highest 10 and highest 20 stocks for the top-10 and top-20 relative returns in red and orange, respectively.The TW 97 used all stocks in the pool to investigate and calculate the relative return in the green line.Then, the TW50 index is the portfolio as the benchmark for stock selection in the blue line.
The area under the relative return curve shows how the portfolio performs during that investigation period.While using the TW50 index as the benchmark, the larger area between each portfolio and the TW50 blue line shows that the portfolio obtains better returns.
Overall, the selected top 10 and top 20 portfolios by trained models perform better than the TW50 index portfolio.The area under the relative return curve shows how the portfolio performs during that investigation period.While using the TW50 index as the benchmark, the larger area between each portfolio and the TW50 blue line shows that the portfolio obtains better returns.
Overall, the selected top 10 and top 20 portfolios by trained models perform better than the TW50 index portfolio.
We calculated the indexes, including portfolio score, excess return, average return of a portfolio, top-k precision, and STD of portfolio for comparison of different portfolio models in Table 8.The results were discussed in the following subsections.

High Portfolio Scores
The portfolio score, as detailed in Section 3.3 and expressed in Equation ( 5), serves as a metric designed to strike an equilibrium between stock return profitability and investment risk.It is calculated by averaging the returns over quarters and dividing by the investment risk.Higher portfolio scores denote a stable and advantageous portfolio from a financial perspective.
The FinGAT model showcases the most impressive excess return among all portfolios.This outcome can be attributed to the amalgamation of temporal and spatial models within the FinGAT framework for predicting stock returns.Notably, the sector-specific information demonstrates that FinGAT's top 20 portfolios not only yield substantial excess returns but also reduce risk compared to RM of Top-20. 1 The benchmark for top 10 precision in the stock pool is 10.3% (calculated as 10/97). 2The benchmark for top 20 in the stock pool is 20.6% (calculated as 20/97).
The portfolio score in TW stock with aligned fiscal year data shows improvement in stock prediction compared with the portfolio score of RF in S&P stock as in Table 9 with RF and FNN models of 0.166 and 0.328 [2], respectively.This proves our hypothesis that not only modeling will affect the stock price prediction but also fiscal year alignment, which is a key factor in stock price prediction.The excess return for the top 10, top 20, and TW97 portfolios, as well as the TW50 index during the period from 2019Q3 to 2022Q1, spanning a total of 11 quarters, is presented in Figure 7a.Notably, all portfolio types, including the top-10, top-20, TW97, and the TW50 index, exhibit excess returns exceeding 135%.

Low-Risk Investment and High Return Rate
In Table 3, the columns representing the average return on investment (investment profit) and the standard deviation of a portfolio (investment risk) serve as critical indicators of the model's proficiency in managing investment risks.To provide a clearer insight into the relationship between risk and return, we created a scatter plot in Figure 8.The xaxis represents risk, while the y-axis depicts return, encompassing all portfolios and the When we consider the relative excess return compared to the TW50 index, as displayed in Figure 7b, the RF and FinGAT models achieve 109.2% and 114% for op-10 portfolios, respectively.It is worth noting that the top-10 portfolio consistently outperforms the top-20 portfolio.Among the four models, RF and FinGAT stand out due to their pronounced nonlinearity in capturing stock trends, making them noteworthy choices for stock trend learning.

Low-Risk Investment and High Return Rate
In Table 3, the columns representing the average return on investment (investment profit) and the standard deviation of a portfolio (investment risk) serve as critical indicators of the model's proficiency in managing investment risks.To provide a clearer insight into the relationship between risk and return, we created a scatter plot in Figure 8.The x-axis represents risk, while the y-axis depicts return, encompassing all portfolios and the TW50 index.

Low-Risk Investment and High Return Rate
In Table 3, the columns representing the average return on investment (investment profit) and the standard deviation of a portfolio (investment risk) serve as critical indicators of the model's proficiency in managing investment risks.To provide a clearer insight into the relationship between risk and return, we created a scatter plot in Figure 8.The xaxis represents risk, while the y-axis depicts return, encompassing all portfolios and the TW50 index.As evident in Figure 8, the principle that a higher number of stocks in a portfolio corresponds to increased risk and augmented return holds true, a phenomenon corroborated by the data.
Furthermore, a black regression line is plotted, intersecting with the TW50 index, which serves as our benchmark.The upper right side of this line signifies high risk with As evident in Figure 8, the principle that a higher number of stocks in a portfolio corresponds to increased risk and augmented return holds true, a phenomenon corroborated by the data.
Furthermore, a black regression line is plotted, intersecting with the TW50 index, which serves as our benchmark.The upper right side of this line signifies high risk with substantial portfolio investment, while the lower left side denotes lower risk with more conservative portfolio investment.
Exploring the implications of varying the value of k for portfolios ranging from the top 5 to the top 40 will be a future research endeavor.This study will delve into how the hyperparameter k influences both profit and investment risk within the TW stock market context, offering valuable insights into portfolio optimization.

Top-k Precision
The top-k precision metric is instrumental in gauging the concordance between the list of chosen top-k stocks, those with the highest predicted returns, and the actual outcomes during that specific quarter.As elaborated in Section 5.2, a higher top-k precision underscores the model's capacity for accurate return predictions.
For the four models, namely RF, FNN, GRU, and FinGAT, the top-10 portfolio model selections exhibited overlaps with the ground truth (GT) at percentages of 16.4%, 19.1%, 18.2%, and 21.8%, respectively.In contrast, the baseline precision of a random shuffle comprising 10 stocks from the pool of 97 stocks amounted to 10.3%.In summation, our modeling endeavors showcased their potential by enhancing precision, elevating it by approximately 6.4% to 11.8% for top 10 portfolios.
The precision of the top 20 portfolios in the RF, FNN, GRU, and FinGAT models was recorded at 26.8%, 27.7%, 29.5%, and 27.3%, respectively.In contrast, the random shuffle baseline for selecting 20 stocks from the pool of 97 stocks yielded a precision of 20.6%.In conclusion, the utilization of modeling for the selection of 20 stocks in a top 20 portfolio boosted precision by approximately 6.2% to 9.3%.
It is noteworthy that top 20 portfolios exhibit higher precision compared to top 10 portfolios, thereby entailing lower investment risk.However, this comes at the trade-off of relatively lower returns.Investors are encouraged to choose their model based on their income and risk tolerance, ensuring they opt for the most suitable option that aligns with their risk acceptance and financial objectives.

Conclusions
The successful utilization of RF, FNN, GRU, and FinGAT models holds significant managerial implications for enhancing portfolio management strategies:

•
Improved Stock Selection: The superior performance of our models, particularly in comparison to the TW50 benchmark, positions them as valuable tools for stock selection.This enhances the decision-making process for portfolio managers, providing more effective alternatives for discerning investors.

•
Consideration of Fiscal Year Alignment: Managers should be aware of the limitations regarding aligned fiscal years.In markets with misaligned fiscal years, there may be potential performance loss due to quarterly financial report publishing misalignment.This suggests a need for adaptation or additional considerations when applying these models in diverse fiscal environments.

•
Optimal Risk-Return Balance: The demonstrated balance between return and risk, as showcased in the risk vs. return plot, highlights the efficiency of our risk and return management approach.This implies that managers can achieve higher returns without significantly increasing portfolio risk, offering a valuable strategy for optimizing riskadjusted returns.

•
Methodological Prowess: The consistently superior performance of our methodology, as evidenced by portfolio scores outperforming the TW50 index, underscores its prowess.This emphasizes the reliability and effectiveness of our approach, reinforcing the commitment to sound risk and return management practices.

•
Precision Improvement: Although precision in top 10 and top 20 outcomes may not be significant, the approach significantly outperforms random stock selection.This suggests that managers can enhance accountability by relying on our models, achieving more predictable outcomes in the range of 6.4% to 11.8% for top 10 portfolios and 6.2% to 9.3% for top 20 portfolios.

•
Expanded Investment Options: The diversity of choices beyond TW50 index portfolios or haphazard stock selection offers investors a more tailored approach.Managers can guide investors to opt for top 10 portfolios for high excess returns with acceptable risk or top 20 portfolios for lower risk, maintaining commendable excess returns relative to the TW50 index.
In conclusion, these managerial implications emphasize the strategic advantages and adaptability of our models, providing valuable insights for optimizing portfolio performance in dynamic market conditions.

Future Work
In conclusion, the Random Forest model stands out as the second-highest performer within the top 10 portfolios.To further enhance its risk-return profile, we may explore the incorporation of additional financial ratios into the Random Forest modeling in the future, aiming to maintain robust returns while mitigating risk.
Moving forward, we plan to refine the value of k as a hyperparameter, which will provide investors with more flexibility.Currently, we adhere to k values of 10 and 20, but fine-tuning this parameter could offer greater options for portfolio customization.Furthermore, our current approach employs equal weights for stocks within a portfolio.A prospective avenue for improvement involves training weights for individual stocks within the same portfolio.This adjustment aligns more closely with stock market dynamics, in which certain stocks may outperform due to societal or politically relevant topics.
Additionally, we are intrigued by the prospect of applying our methodology to stock markets that share the same fiscal year alignment as the TW stock market, facilitating performance comparisons across different financial markets.This endeavor promises to yield valuable insights into stock selection strategies and investment opportunities.

Figure 1 .
Figure 1.In the S&P stock market, some companies, such as Company A, start their fiscal year in September, and others, such as Company B, start their fiscal year in April.The misaligned starting point of the fiscal year makes the publishing of financial reports time misaligned due to different market businesses.

Figure 2 .
Figure 2.In the TW stock market, the fiscal year is aligned to start in January as Q1 for all companies.And the yearly financial report will be public before March the next year.

Figure 2 .
Figure 2.In the TW stock market, the fiscal year is aligned to start in January as Q1 for all companies.And the yearly financial report will be public before March the next year.

Figure 4 .
Figure 4. Model training architecture for RF, FNN, GRU, and FinGAT, with FNN as an example in the figure.

Figure 5 .
Figure 5. Importance of features of random forest models.

Figure 4 .
Figure 4. Model training architecture for RF, FNN, GRU, and FinGAT, with FNN as an example in the figure.

Figure 4 .
Figure 4. Model training architecture for RF, FNN, GRU, and FinGAT, with FNN as an example in the figure.

Figure 5 .
Figure 5. Importance of features of random forest models.

Figure 5 .
Figure 5. Importance of features of random forest models.

Figure 7 .
Figure 7.The relative return for 4 models with 4 portfolios from 2019Q3 to 2022Q1, a total of 11 quarters: (a) cumulative return of top 10, top 20, TW97, and TW50 sorted from low to high; (b) excess return of top-10, top-20, and TW97 relative to TW50 index to compare the selected stocks of top-10 and top-20 relative to TW50 index.

Figure 7 .
Figure 7.The relative return for 4 models with 4 portfolios from 2019Q3 to 2022Q1, a total of 11 quarters: (a) cumulative return of top 10, top 20, TW97, and TW50 sorted from low to high; (b) excess return of top-10, top-20, and TW97 relative to TW50 index to compare the selected stocks of top-10 and top-20 relative to TW50 index.

Figure 7 .
Figure 7.The relative return for 4 models with 4 portfolios from 2019Q3 to 2022Q1, a total of 11 quarters: (a) cumulative return of top 10, top 20, TW97, and TW50 sorted from low to high; (b) excess return of top-10, top-20, and TW97 relative to TW50 index to compare the selected stocks of top-10 and top-20 relative to TW50 index.

Table 2 .
Data split for RF and FNN training, including the moving time period.

Table 3 .
Data split for GRU and FinGAT training, including the moving time period.

Table 7 .
Sector distribution of 97 TW stocks in the pool.

Table 8 .
Portfolio score, excess return, average return of a portfolio, top-k precision, and STD of portfolio.These indexes are used to compare different portfolio models.

Table 9 .
Portfolio score of Top-20 with RF and FNN models in US S&P stock market and TW stock market.High Excess Return in Top-10 and Top-20 in Test Data for Four Models for Investment Gain