Stock Price Prediction Incorporating Market Style Clustering

Abstract

Market style analysis is critical when designing a stock price prediction framework. Under different market styles, stocks may show quite different behaviors; thus, predictions will vary. Consequently, incorporating market styles into stock price predictions should help improve the prediction performance. In this paper, we investigate how to characterize market styles to improve stock prediction performance under varying market styles. First, stock time series data are divided into windows of different lengths. The windows are summarized and represented by technical indicators and news sentiment features. Second, hierarchical clustering is employed to cluster the windows and categorize their market styles; the window lengths and number of market styles are carefully tuned to achieve the best clustering results. Third, a distance measurement is proposed to distinguish among rotating patterns within the market styles to verify the usability of the market styles. Finally, a stock price prediction framework is constructed to predict future stock price trends based on data belonging to the same market styles. The experiments are conducted with five years of real Hong Kong Stock Exchange data that includes both stock prices and corresponding news. Two famous sentiment dictionaries (i.e., SenticNet 5 and the Loughran-McDonald financial sentiment dictionary 2018) are employed to analyze the news sentiments. Predictive models are compared both with and without incorporating market styles. The results demonstrate that the approach incorporating market styles outperforms the baseline, which does not incorporate market styles. There is a maximum 9 percent improvement in terms of accuracy and F1-score. Moreover, backtesting results show that incorporating market styles into trading signals earns trading strategies more profits on most stocks.

Introduction

Due to the stock market dynamics, it is believed that stocks within the market manifest with different market styles in different periods. Market styles can be defined in many ways and characterized by different factors. For example, Indro et al. [17] reported that institutional funds used value/growth as well as small/large capitalization for market style characterization. Lucas et al. [25] used firm-specific characteristics (i.e., size and book-to-price) to represent market styles. From a market structure point of view, market styles refer to patterns that may exist across the entire market, an individual sector, or even a single stock. From a market frequency point of view, market styles can change yearly, monthly, daily, or even in response to various market events. Because market style behaviors, such as rotation and trend, can affect the performances of stock price prediction models, people have become increasingly interested in market style analysis and in applying it to their investment strategies to obtain higher profits and fewer losses. Therefore, how to characterize the concept of market style more accurately and incorporate market style analysis into a stock price prediction framework has become an interesting research problem.

Many research works have studied market styles and used them for portfolio management and stock price predictions. Lucas et al. [25] gained significant return improvements by formulating alternative style rotating investment strategies. Levis and Liodakis [18] investigated the profitability of style rotation strategies in the UK and suggested that such strategies can be highly rewarding. Sun et al. [29] mined trading signals from temporal investment styles defined by technical indicators. However, there are two main issues in previous studies:

  1. 1.

    The first issue is the characteristics they constructed. Lucas et al. [25] characterized market styles mainly using firms’ fundamental factors, while Sun et al. [29] defined temporal investment styles using technical indicators. Although these factors are well defined and easy for people to understand, both rely on factors extracted from traditional stock numerical data. In contrast, newer types of data, such as text-based news articles, have rarely been employed in market style characterizations. Market news articles report different events related to stocks and express sentiments that traditional factors do not possess. For example, while market style size may indicate that a portfolio focused on large companies would be more profitable, negative sentiment regarding company size expressed in news articles is not included in the information set, which may cause the portfolio to act incorrectly. Thus, how to incorporate different kinds of data, fuse the information properly, and use the result to represent market styles is the first research question addressed by this paper.

  2. 2.

    The second issue involves how to incorporate market styles into prediction models. Levis and Liodakis [18] activated portfolio management by considering each market style as an attribute; then, the portfolio was built by calculating the risk exposure on different market attributes. In addition, Domino et al. [13] indicated that the Hurst exponent and other market style clustering properties were not well analyzed, and that various trending or periodic market style behaviors could lead to quite different market style predictions; consequently, they varied the usage of market styles in a stock price prediction framework. Therefore, how to analyze the properties of market styles and incorporate them to improve stock price predictions is the second research question in this paper.

To address these issues, we propose a stock price prediction approach that incorporates market styles in this paper. Our approach includes the following steps. 1) Stock time series data are divided into time windows of different lengths. The market style features for each window include both technical indicators and news sentiments. The news sentiments are obtained from one of two sentiment dictionaries (i.e., SenticNet 5 and the Loughran-McDonald financial sentiment dictionary 2018); 2) A hierarchical clustering method is employed to cluster the windows and identify their market styles. During this process, the number of market styles and the window lengths are carefully tuned to achieve the best clustering results; 3) A quantitative distance measurement is defined to distinguish rotating patterns in the market styles to verify the usability of the market styles; 4) A stock price prediction framework is constructed to predict stock future price trends based on data within the same market style. Stock price predictions both with and without market styles are investigated using experiments based on five years of real data from the Hong Kong Stock Exchange. The experimental results show that incorporating market styles improves the prediction performance for most stocks. The contributions of this paper can be summarized as follows:

  • A new method that characterizes market styles by technical indicators and news sentiments is proposed.

  • A clustering approach that categorizes market styles is proposed, and a distance measurement that distinguishes rotating patterns within market styles is proposed and analyzed.

  • Market styles are incorporated into a stock price prediction framework, and the prediction performances are improved.

The remainder of this paper is organized as follows. Section 2 describes the related research works on market style analysis and stock price prediction. Section 3 proposes an approach that characterizes and analyzes the market styles based on representations we defined and a distance measurement that distinguishes the rotating patterns within the market styles. In Section 4, we describe the experimental setup, report the experimental results, and compare the proposed approach with baselines. Finally, Section 5 provides conclusions.

Related Works

Many previous research works have studied market styles and stock price predictions. In this section, representative papers from these two research areas are broadly reviewed.

Market Style Analysis

Based on statistical analyses, many studies have confirmed that stock sequence volatility has long-term dependencies. These studies mainly analyzed the Hurst exponent. For example, Wang et al. [32] analyzed variations in the Hurst exponent and the multifractal degree of volatility series in the Shenzhen stock market. Their results showed that the volatility series still retains strong long-term dependencies and a multifractal nature. Eom et al. [15] explored the relationship between the Hurst exponent and stock predictability in 60 market indices from various countries. Based on the nearest-neighbor prediction method, they showed that a market index with a higher Hurst exponent tends to have higher predictability. Zhuang et al. [37] drew a similar conclusion from the Chinese stock market: stock prices time series have long-term dependencies. These works demonstrate that a pattern is implicated in the stock price volatility.

Some works have proposed using the concept of market styles and incorporated it into portfolio management. Levis and Liodakis [18] used value/growth and small/large-cap segments as market styles and investigated the profitability of style rotation strategies in the UK. They suggested that style rotation strategies can be highly rewarding. Lucas et al. [25] concluded that the impact of firm-specific characteristics on excess stock returns varied considerably over time. By formulating alternative modeling strategies, they found significant and robust excess returns attributable to style rotating investment strategies and that business-cycle oriented approaches exhibited the best overall performance. Sun et al. [29] defined temporal investment styles composed of technical indicators via biclustering. They transformed these investment styles into trading actions through the k-nearest-neighbor algorithm. The experimental results showed that temporal investment styles can provide effective trading indicators for the market.

Stock Price Predictions

Stock markets generate large amounts of transactional data. Such historical data provides a plethora of training data for training prediction models. One classic approach is to predict future stock trends based on these historical price data, and many recent works have shown that this approach is still efficient. Zhang and Tan [36] used historical price data to predict stocks’ future return rankings via a novel stock selection model. Chen et al. [10] used a deep neural network trained on historical price data to predict the daily volatility of stocks in the Chinese A-share market. Li et al. [19] built a system that exploited deep learning architecture to improve feature representations and adopted an extreme learning machine to predict market impacts. They concluded that deeply learned feature representations together with extreme learning machines yield the highest market-impact prediction accuracy.

Recently, financial news has become a new type of data source for stock predictions. Advancements in the field of natural language-based financial forecasting have led many researchers to begin to analyze textual information using deep neural networks; such models can capitalize on news texts to predict stock prices [33]. Engelberg et al. [14] showed that the anomaly return occurrences were higher on corporate news days and earnings announcement days. Ding et al. [12] proposed using a neural tensor network to learn event embeddings of news headlines for stock trend prediction. Hu et al. [16] predicted the daily volatility of stocks based on both news vectors and price data. Shi et al. [28] bridged text-based deep neural networks and users to make stock price predictions. Some studies have combined multiple information sources and predicted stock prices based on both prices and new textual data. Akita et al. [1] predicted the closing prices of 50 stocks on the Tokyo Stock Exchange using paragraph vectors and price data. Li et al. [20] quantitatively integrated information from both market news and stock prices. Their results showed that integrating such information can improve the prediction accuracy on stock future price returns in an intraday trading context. Another study [23] investigated whether news article summaries are more effective at improving prediction than full-length articles; their experiments verified that using article summaries can enhance the prediction performance.

Sentiment analysis has introduced an additional information source for artificial intelligence (AI) frameworks and has been exploited in many research and industrial fields, including public opinion mining and automated upkeep of reviews [4]. The NLP sentiment analysis process not only detects textual polarity but also represents texts as a large “suitcase” with three layers [7]: a syntactic layer, a semantic layer, and a pragmatic layer. Cambria et al. [9] showed that public opinions can be mined using sentiment analysis. They proposed an hourglass model [6] to analyze sentiments at the concept level; this model was further refined in their most recent work [30]. In addition, they introduced deep learning into the construction of sentiment dictionaries, integrating logical reasoning within deep learning architectures to improve the accuracy of their sentiment dictionary [5]. Because sentiment dictionaries provide a new way to extract sentiments from texts, many studies have begun to predict stock future trends based on sentiments mined from news articles. Tetlock [31] investigated the role of media in stock markets and suggested that sentiments are related to markets. Xiong et al. [35] used Google domestic trends as indicators of public mood to predict daily S&P 500 index volatility. Bollen et al. [2] adopted Opinion Finder and Google-Profile of Mood States dictionaries to analyze investor sentiments on Twitter and predicted Dow Jones Industrial Average prices based on sentiments. Deng et al. [11] analyzed news sentiments using SentiWordNet to predict stock prices based on both price series and news sentiments. Li et al. [22] applied the Harvard psychological dictionary and the Loughran-McDonald financial sentiment dictionary to construct a sentiment space for stock predictions. Picasso et al. [27] incorporated sentiment and technical indicators to predict stock price trends using classification methods; their results verified that incorporating both sentimental and technical indicators improved the prediction accuracy beyond that achievable using data from only a single source.

As deep learning technology matures, especially recurrent neural network (RNN) models, many works have focused on performing temporal stock trend predictions using RNNs. Xing et al. [34] incorporated market sentiments to predict stock return fluctuations; their approach included incorporating ground knowledge into an LSTM. Li et al. [21] captured price trend patterns with an LSTM using technical indicators and news sentiments. They compared the use of four sentiment dictionaries (i.e., SenticNet 5, Vader, SentiWordNet 3.0, and the Loughran-McDonald financial dictionary) in their experiments and found that the finance-domain-specific sentiment dictionary obtained the best performance. All these works suggest that using sentiment dictionaries provides an additional boost to stock price prediction accuracy.

In contrast to the previous works, we propose an approach that 1) employs both technical indicators from numerical historical prices and sentiment indicators from textual news to characterize market styles; 2) uses a hierarchical clustering algorithm to identify market styles and distinguishes the rotating patterns contained within market styles; and 3) incorporates market styles into a stock price prediction framework to improve the prediction performance.

Stock Price Predictions with Market Styles

Market styles can be exploited as one kind of domain knowledge that enhances the performances of stock prediction algorithms. In this section, we first describe our formulation of market styles based on technical indicators and news sentiments; then, we expound on our market style clustering approach; and finally, we describe the developed stock prediction framework that employs market styles.

Market Style Formulation

Market styles are used to represent distinct market behaviors in different periods. Market styles were originally characterized mainly by macroeconomic indicators, fundamental indicators, technical indicators, etc. However, the advent and rapid expansion of social media has enabled nearly instant stock market news, and the underlying sentiments contained in the texts express the preferences of investors and provide a new source of information for market style definition. Therefore, we define market styles z based on the following formula, which incorporates both stock technical indicators T and related news sentiments, S:

$$\begin{aligned} f: \{T, S\} \rightarrow z, \end{aligned}$$
(1)

where f is a model used to identify market styles.

Since both T and S are sets of features representing market styles, we denote them by X, i.e., \(X=\{T, S\}\). The details are described in the following subsections.

Technical Indicators

Technical indicators can reflect trends or fluctuations in the stock market from different aspects, and they provided signals that can be used in trading strategies. In this paper, several popular technical indicators calculated by Ta-LibFootnote 1 are introduced to define the market styles, as listed in Table 1. These indicators are calculated from different time period durations, and their parameters (when not specified in Table 1) are set to the default values in Ta-Lib.

Table 1 Technical indicators for stock prices

News Sentiments

News sentiments can represent both the sentiment polarities of the market and the preferences of investors. Positive sentiments express investors’ confidence in the stock market, while negative sentiments express concerns. One efficient way to analyze sentiments in textual news is to extract sentiment values using the bag-of-words approach, which first queries the sentiment values corresponding to each term in the text with the help of a sentiment dictionary and then forms a sentiment vector for each part of the news article. The news articles on social media mainly appear in the form of long texts. Tokenization is the first step in preprocessing these texts: each article is tokenized and converted into a word vector \(W = (w_1, \dots , w_n)\), where \(w_i\) is the i-th term in the article. Because some sentiment dictionaries also support query phrases, it requires an extra step during tokenization to check whether a token and its context can form a phrase that exists in the sentiment dictionary. In addition, because negation words can affect sentiment polarity, they should be revised by reversing the sentiments of tokens that appear after negation words (e.g., “not”, “no”, or “neither”). Finally, stop words are removed, and the remaining words are lemmatized to increase the accuracy of sentiment retrieval from the sentiment dictionary. After preprocessing, we query the sentiment values \(\varvec{s}\) for token w from a specific sentiment dictionary D.

The query process can be represented by a mapping,

$$\begin{aligned} Q_D: \mathcal {W} \rightarrow \mathcal {S}, \end{aligned}$$
(2)

where \(\mathcal {W}\) is the token space and \(\mathcal {S}\) is the sentiment space. Therefore, each word \(w_i\) can be represented by a sentiment vector:

$$\begin{aligned} \varvec{s_i} = Q_D(w_i). \end{aligned}$$
(3)

For example, SenticNet 5, proposed by Cambria et al. [8], contains 5 sentiment dimensions, i.e., sentiment polarity and 4-dimensional fine-grained sentiments (pleasantness, attention, sensitivity, and aptitude).

Suppose that the comprehensive sentiments of an article are linear superposition of each word’s sentiments; then, the sentiment vector \(\varvec{S_i}\) of news \(N_i\) is calculated by

$$\begin{aligned} \varvec{S_i} = \sum _{w_j \in \varvec{W_i}}Q_D(w_j). \end{aligned}$$
(4)

However, multiple daily news items are typically available; therefore, the daily news sentiments regarding a particular stock are derived by averaging the news sentiments that appear on the same day.

Market Style Clustering

It is natural that daily trading data that belong to the same market style should be similar in a feature space. Therefore, we use hierarchical clustering to automatically separate samples from different distributions; in other words, we use hierarchical clustering to obtain market styles based on daily technical indicators and news sentiments. Let \(n=|z|\) denote the number of market styles and \(\tau\) denote the length of the time series window. The clustering of the market style is formulated as follows:

$$\begin{aligned} z=f(X; n, \tau ). \end{aligned}$$
(5)

Specifically, featurewise normalization is used before clustering to eliminate magnitude differences. The Ward distance is used to evaluate the similarities between samples and is defined as

$$\begin{aligned} d(i,j)=\sqrt{\frac{|j|+|k|}{K} d(j,k)^2+\frac{|j|+|l|}{K} d(j,l)^2-\frac{|j|}{K} d(k,l)^2}, \end{aligned}$$
(6)

where i is the newly joined cluster consisting of clusters k and l, j is an unused cluster in the forest, \(K=|j|+|k|+|l|\), and \(|\cdot |\) is the cardinality operator. Since n and \(\tau\) are key parameters in market style clustering, we need to optimize their selections to obtain the most appropriate clustering by searching for the optimal values of n and \(\tau\) on a parameter grid. Moreover, the silhouette score \(M(\cdot )\) is used to evaluate the clustering performance for each parameter combination:

$$\begin{aligned} {\begin{matrix} \mathop {\arg \max }_{ n,\tau }\ \ &{} M(f(X, n, \tau ))\\ \text {s.t.}\ \ &{} n = 2,\ldots ,9,\\ &{} \tau = 1,\ldots ,7. \end{matrix}} \end{aligned}$$
(7)

We selected four representative stocks from four different sectors of the Hang Seng Index (HSI) and searched for the optimal clustering parameters, which are presented in Fig. 1. The results show that an increment in n is followed by decrement of the silhouette scores and that the silhouette scores with small (1-2 weeks) or large (6-7 weeks) \(\tau\) values are higher than those of others. Specifically, there are different preferences for optimal \(\tau\)s among sectors. Large \(\tau\) values are preferred in Properties (a) and Utilities (b), while both large and small \(\tau\) values are preferred in Finance (c) and Commerce (d).

Fig. 1
figure1

Grid search results of n and \(\tau\) evaluated by silhouette scores. (a) 0001.HK belongs to Properties, its optimal parameters are \(n^*=3,\tau ^*=4\); (b) 0002.HK belongs to Utilities, its optimal parameters are \(n^*=2,\tau ^*=7\); (c) 0005.HK belongs to Finance, its optimal parameters are \(n^*=2,\tau ^*=2\); (d) 0762.HK belongs to Commerce, its optimal parameters are \(n^*=2,\tau ^*=7\)

To further explore the implications of using market styles, we calculated each cluster’s center to analyze the market style patterns. The center of style \(z_i\) is calculated by

$$\begin{aligned} O_i = \frac{\sum _{f(X_j)=z_i} X_j}{|z_i|}, \end{aligned}$$
(8)

where \(X_j\) is a feature vector whose market style is \(z_i\), and \(|z_i|\) denotes the number of samples in \(z_i\). We perform hierarchical clustering with the best clustering parameters obtained from a grid search to obtain the centers of the market styles.

Fig. 2
figure2

Clustering centers of each market style of 4 stocks from different sectors, where each row denotes one kind of market style

Figure 2 displays the clustering centers of 4 stocks from different sectors; each row represents the center of one market style. The distinguishable and polarized color of each market style center in Fig. 2 indicates the differences and complementarities among each market style. Each market style of a stock corresponds to an interpretable market state or situation. Subfigure (a) shows that there are 3 types of market styles in 0001.HK: the first market style could occur when the stock is within a period in which its price is rising with slightly negative sentiments, and the second market style could occur when the stock is within a period in which its price is declining with strongly negative sentiments. The third style could occur when the stock price is low and slightly declining with few positive sentiments. Subfigure (b) shows that there are 2 types of market styles in 0002.HK: the first could occur when the stock price is high and rising with positive sentiments, while the second could occur when the stock price is low and declining with negative sentiments. Subfigure (c) shows that there are 2 types of market styles in 0005.HK: the first market style could occur when the stock price is low and rising with negative sentiments, and the second market style could occur when the stock price is high and declining with slightly positive sentiments. Subfigure (d) shows that there are 2 types of market styles in 0762.HK: the first market style could occur when the stock price is high and rising with negative sentiments, and the second market style could occur when the stock price is low and declining slightly with slightly negative sentiments.

Market Style Rotation

It is vitally important to investigate the rotating patterns of market styles over time; then, we can make full use of the patterns and tune stock prediction models to predict stock trends better.

To quantify the variation in market styles over time, we propose a distance measurement for market styles to illustrate the change in market styles,

  • Eliminate differences within the same market style and focus more on the evaluation of changes between different market styles;

  • Balance the style rotation amplitude according to the different radii of each cluster;

  • Make the amplitudes of the market style rotations easy to compare. An amplitude less than 1 means that the change in style is not obvious, and the distance between the current sample and the previous style’s center is below the maximum radius of the previous style. An amplitude greater than 1 indicates that the style has changed significantly, and the distance between the current sample and the center of the previous style exceeds the maximum radius of the previous style.

The market style distance measurement is formulated as follows:

$$\begin{aligned} d(t) = {\left\{ \begin{array}{ll} \frac{X(t) - O_{z_{t-1}}}{R_{z_{t-1}}}, &{} z_t \ne z_{t-1};\\ 0, &{} z_{t} = z_{t-1}; \end{array}\right. } \end{aligned}$$
(9)

where \(R_i\) is the clustering radius of market style \(z^{(i)}\), which is defined as

$$\begin{aligned} R_i = \max _{f(X)=z^{(i)}} \Vert X - O_i\Vert _2. \end{aligned}$$
(10)
Fig. 3
figure3

Amplitudes of market style rotations of different cluster number with best \(\tau\)

Based on the 4 stocks analyzed above, we first fix \(\tau\) to the optimal value and observe the market style rotations under different n values. Figure 3 shows the frequency and amplitude of market style rotations as n varies from 2 to 5 on each stock. These results reveal that,

  • Most of the amplitudes are not large (less than 0.5), except for some periods whose amplitudes are greater than 1 (when \(n=4, 5\));

  • As n increases, the number of red bars increases, which means that the market style changes more frequently with a large amplitude;

  • There is a rotation between stable and fluctuating periods. During a stable period, the market style lasts for a few periods, as illustrated by the continuous blanks, while during a fluctuating period, market styles alternate frequently, as illustrated by the continuous red bars.

Second, we fix n to the optimal value and observe the market style rotations under different \(\tau\) values. Figure 4 shows the frequency and amplitude of the market style rotations when \(\tau =1, 2, 3, 4\). These results reveal that,

  • All of the amplitudes are less than 1;

  • When \(\tau\) increases, the number of red bars decreases, and the market styles are more stable;

  • There is a rotation between the stable and fluctuating periods. During a stable period, the market styles last for a few periods, as represented by the continuous blanks, while during a fluctuating period, the market styles alternate frequently, as indicated by the continuous red bars.

Fig. 4
figure4

Amplitude of market style rotations on different sampling periods with best n

The preceding analysis verifies that 1) there are clear differences in market behaviors among different periods for each stock and 2) the market styles can last for several periods, which means that the market behaves similarly during that time. This scenario can be useful. Therefore, we incorporated the rotating patterns of the market styles into the stock price prediction framework whose workflow is illustrated in Fig. 5.

Fig. 5
figure5

Workflow of stock price prediction framework. It first uses technical indicators and news sentiments to represent and distinguish market styles by hierarchical clustering. Second, it selects past data within the same market style to train a prediction model (i.e. Market Style - Support Vector Machine, MS-SVM). Finally, it makes prediction of stock price trend for the next trading day

Experiments and Discussions

In this section, we introduce the data sets used to evaluate our proposed approach and present our model setup. The experimental results are then presented, discussed, and analyzed to illustrate the effectiveness of the proposed approach.

Data Set

Stock Price Data

We used daily stock price data from the Hong Kong Stock Exchange (HKEx) from January 2003 to March 2008 and corresponding news from FINETFootnote 2 to examine the effectiveness of our approach. Although the HKEx includes thousands of stocks, not all of them are traded actively in the market. The inactive stocks usually have less volume and are associated with fewer news reports. Our experiment mainly focuses on the constituents of HSI, which are the best-capitalized stocks in the market. We selected three representative stocks from each of the four HSI sectors (i.e., Properties, Commerce, Finance, and Utilities) for these experiments. These stocks attract more attention and elicit more news in their sectors. Statistics regarding these stocks’ news items are presented in Table 2, where the “Average” column denotes the average daily number of news items and the “Max” column denotes the maximum daily number of news items. The bold text in Table 2 represents that HSBC Holdings accrues the highest average number of daily news items, and China Unicom elicits the maximum number of daily news items. Properties and Commerce elicit more than 2 news items per day, but the number of news items related to utilities is smaller—often less than 1.

Table 2 Statistics on news articles of each stock

Sentiment Dictionaries

The sentiment dictionaries used in our experiments are SenticNet 5 [8] and the Loughran-McDonald Financial Dictionary 2018 [24], both of which provide fine-grained sentiment analysis. SenticNet 5 consists of sentiment polarity, pleasantness, attention, sensitivity, and aptitude, while the Loughran-McDonald Financial Dictionary 2018 (LMFinance 2018) is a domain-specific sentiment dictionary designed for financial news analysis. It contains 7 sentiment dimensions: positive, negative, uncertainty, litigious, weak modal, strong modal, and constraining. We conducted experiments using both these two dictionaries.

Training Setup

We divided the data set into two parts based on their dates. The data from March 2003 to November 2006 (approximately 80% of the total data) were used as the initial training set (on which the first model is trained), while the remaining data, from December 2006 to March 2008, were used as test set with a rolling window setup.

Labels

The purpose of our research is to use technical indicators and news sentiments to predict close-to-close stock price returns, which is defined as follows:

$$\begin{aligned} r_{t+1} = \frac{close(t+1) - close(t)}{close(t)}, \end{aligned}$$
(11)

where t is the current trading day. Then, the label of t day is set by the sign of \(r_{t+1}\), i.e.,

$$\begin{aligned} y_t= {\left\{ \begin{array}{ll} +1, &{} r_{t+1} > 0;\\ -1, &{} r_{t+1} \le 0. \end{array}\right. } \end{aligned}$$
(12)

Metrics

In the experiment, we evaluated the performances of each model using accuracy and micro F1-score as metrics. These are calculated as follows:

$$\begin{aligned} Acc = \sum _{i \in \mathcal {Y}}\dfrac{n_{ii}}{\sum _{j \in \mathcal {Y}} (n_{ij} + n_{ji})}, \end{aligned}$$
(13)
$$\begin{aligned} P =\sum _{i \in \mathcal {Y}}\dfrac{n_{ii}}{n_{ii}+\sum _{ j \ne i}n_{ji}}, \end{aligned}$$
(14)
$$\begin{aligned} R =\sum _{i \in \mathcal {Y}}\dfrac{n_{ii}}{n_{ii}+\sum _{ j \ne i}n_{ij}}, \end{aligned}$$
(15)
$$\begin{aligned} F1 = \frac{2\times P\times R}{P+R}, \end{aligned}$$
(16)

where P and R denote precision and recall, respectively, \(\mathcal {Y}=\{-1,1\}\) is the label space, and \(n_{ij}\) denotes the number of samples whose true label is i but that are mislabeled as j by the classifier.

Model Setup

Hierarchical clustering is first trained based on the samples in the training set. Then, a search of hierarchical clustering hyperparameters is conducted on a 2-D parameter grid to obtain the highest silhouette scores. Table 3 shows the clustering performances of SenticNet 5 and LMFinance 2018, where 0016.HK, 0006.HK, 0011.HK, and 0941.HK obtain higher silhouette scores (\(>0.4\)) for both SenticNet 5 and LMFinance 2018, meaning that the boundaries of the market style clusters are clearer. Finally, based on the hierarchical clustering results, the market style of each time window is identified, and the market styles of the samples within a time window are the same as that of the window. Following the analytic results in Section 3 that market styles tend to be continuous, we assume that the market style on day \(t+1\) is the same as that on day t, and the past m samples whose market style is the same as that of day t are employed to train the models.

Table 3 Optimal hyperparameters of hierarchical clustering

We adopt a radius basis function (RBF) kernel-based support vector machine (SVM) [3, 26] as a baseline to predict the return of the next trading day. We trained the SVM on the training set and optimized its hyperparameters to achieve the best performance. A 2-D parameter grid is built by \(C={10}^c, c\in \left\{ 0.0, 0.3, \ldots , 3.0 \right\}\), and \(\gamma ={10}^g, g\in \left\{ -2.0, -1.6, \ldots , 2.0\right\}\). We performed a fivefold cross-validation on the grid to search for the optimal hyperparameters, where the cross-validation scores were measured by the micro F1-score. For each trading day in the test set, the trained SVM is used to predict the return label of the next trading day. A rolling window is adopted in these experiments to simulate a real investment situation. For example, suppose the last day in the rolling window is t, the features and labels of the last m days (t, \(t-1\), \(\dots\), \(t-m+1\)) are selected from the training set to train the SVM, and then the return label of day \(t+1\) is predicted. Subsequently, the window rolls forward, and its front reaches day \(t+1\). Therefore, the sample of \(t+1\) day is added to the rolling window, and a new SVM is trained based on the new window to predict the label for the next day (i.e., day \(t+2\)).

Experimental Results

Let \(m=250\), which is approximately equal to the number of trading days in a calendar year. We select one year of data that contains the same market style to train a stock prediction model.

Validation Results

Fivefold cross-validations are performed on the sampled data and evaluated by the micro F1-score to select the best hyperparameters. To analyze the significance level of the differences between MS-SVM and the baseline, we adopt a double-sided t-test. The validation results based on SenticNet 5 and LMFinance 2018 are presented in Tables 4 and 5, respectively, where the values in bold font denote better F1-scores between the MS-SVM and the baseline (not significant); the values in blue bold font denote the better F1-scores between the MS-SVM and the baseline (significant); and the values in orange bold font denote the better F1-scores between the MS-SVM and the baseline (highly significant). The t-test statistics in Tables 4 and 5 marked by an asterisk (“\(^{*}\)”) denote that the differences between these two models are significant (significance level \(\alpha < 0.05\)), and the statistics marked by a double asterisk (“\(^{**}\)”) denote highly significant differences (\(\alpha < 0.001\)).

Table 4 SenticNet 5 based classification results on validation set

The results on SenticNet 5 show that MS-SVM performs better than does the baseline on all the finance and commerce sector stocks, and it performs worse for only one stock each in the Properties and Utilities sectors. Thus, the MS-SVM performs better than the baseline on 10 stocks, and the differences in the two models’ are highly significant on 6 stocks and significant on 4 stocks.

Table 5 LMFinance 2018 based classification results on validation set

The results based on LMFinance 2018 show that MS-SVM performs better than does the baseline for all the stocks in the Utilities sectors, but performs worse for one stock in Finance, while the baseline performs better than the MS-SVM on the stocks in Commerce. The MS-SVM performs better than the baseline on 9 stocks; the differences in the two models are highly significant on 9 stocks and significant on 1 stock.

Testing

The results of the SenticNet 5- and LMFinance 2018-based models on the test set are shown in Tables 6 and 7, respectively, where the values in bold orange font denote that the model (baseline or MS-SVM) performs better with regard to accuracy and the values in bold blue font denote that the model performs better with regard to micro F1-score.

Table 6 SenticNet 5 based classification results on test set

The MS-SVM based on SenticNet 5 performs better than the baseline on 11 stocks with regard to both accuracy and micro F1-score. Comparing the results sector-by-sector, the MS-SVM performs better than the baseline in all stocks in the Properties, Finance, and Commerce sectors, while the baseline performs better on 1 stock in the Utilities sector. The MS-SVM achieves the largest improvement on Henderson Land (0012.HK), where its accuracy and F1-score are 9% higher than the baseline. In the worst case, the accuracy of the MS-SVM is only 1% lower than that of the baseline (on CLP Holdings (0002.HK).

Table 7 LMFinance 2018 based classification results on test set

The MS-SVM based on LMFinance 2018 performs better than the baseline on 11 stocks both in accuracy and micro F1-score. Comparing the results sector-by-sector, the MS-SVM outperforms the baseline on all Utilities, Finance, and Commerce stocks, while the baseline performs better on 1 stock in Properties. The MS-SVM achieves its largest improvement on Hutchison Whampoa (0013.HK), where the accuracy and F1-score are 9% higher than the baseline. In the worst case, the accuracy of the MS-SVM is only 2% lower than that of the baseline on Henderson Land (0012.HK).

Fig. 6
figure6

Accuracy of SenticNet 5 based MS-SVM and LMFinance 2018 based MS-SVM on test set

Fig. 7
figure7

F1 scores of SenticNet 5 based MS-SVM and LMFinance 2018 based MS-SVM on test set

Figures 6 and 7 show the results comparing the two sentiment dictionaries on accuracy and micro F1-scores, respectively, on the test set. The figures reveal that LMFinance 2018 performs slightly better than does SenticNet 5 on 8 stocks with regard to accuracy and on 7 stocks with regard to micro F1. This result is consistent with our previous work [21] since LMFinance 2018 is a domain-specific sentiment dictionary.

We also designed a daily trading strategy that makes use of the signals generated by MS-SVM and the baseline. The initial inventory of this strategy is 1,000 HKD. The strategy goes long on one share of stock at the open price and sells one share at the closing price of day t if the predicted trend of day t is “\(+1\)”, while the strategy shorts one share of the stock at the open price and buys it back at the closing price if the predicted trend of day t is “\(-1\)”. The backtesting results of SenticNet 5- and LMFinance 2018-based MS-SVM and the baseline are shown in Figs. 8 and 9, respectively, where the x-axis represents time and the y-axis represents profit and loss.

Fig. 8
figure8

Backtesting, profit and loss of SenticNet 5 based MS-SVM and baseline

Fig. 9
figure9

Backtesting, profit and loss of LMFinance 2018 based MS-SVM and baseline

The backtesting results show that the SenticNet 5-based MS-SVM performs better than does the baseline on 7 stocks and obtains positive profits on 6 stocks, while the LMFinance 2018-based MS-SVM performs better than the baseline on 8 stocks and obtains positive profits on 7 stocks. These results reveal that a strategy based on MS-SVM provides more profits than one based on the baseline, which is consistent with the models’ evaluation results. Additionally, some stocks have performances that are similar on both the baseline and MS-SVM (e.g., 0005. HK, 0762. HK). This result occurs because the market styles often continue for long periods, as shown in Fig. 3 and Fig. 4, which means that most of the samples in the time windows have the same market style, i.e., the samples used to train the MS-SVM and the baseline are highly similar. More generically, no extra information regarding market styles exists that helps to improve MS-SVM in such situations.

Conclusions

In this paper, we address an important problem in financial forecasting: how to improve stock price predictions with the help of market styles. We first divide historical stock time series data into windows with different window lengths, and then calculate both technical indicators from stock prices and sentiments from news articles to characterize the market style of each window. Second, we use hierarchical clustering algorithms to cluster the windows into different market style categories. The number of categories and the length of windows in each category are carefully tuned to obtain the best clustering results. Third, based on the representations of the market styles, we design an algorithm to check that, whether the market style clustering has any pattern that could be used for market style predictions. Finally, the market style clustering results are employed as style tags for each trading day and are further incorporated into an SVM-based stock price prediction framework. The experiments were conducted based on five years of real HKEx data, including both stock prices and corresponding news. We compared prediction models both with and without market style predictions. The results are as follows.

  1. 1.

    The results show that market styles tend to persist across several time windows; this information can be used by the stock prediction framework.

  2. 2.

    Because the market styles tend to last for a period of days, we use the t day’s market style as a prediction of the \(t+1\) day’s market style. The results show that the accuracy and micro F1-scores of predictions incorporating the market styles outperform those of the baseline on most stocks. The improvement in both accuracy and F1-score can reach up to 9 percent.

  3. 3.

    The backtesting results show that incorporating market styles into trading signals can result in greater profits on most stocks.

In future works, we think that finding ways to more accurately characterize market styles using more data varieties is a worthy research problem, and based on different representations of the market styles, whether their clustering properties exist or not is another problem that worth investigation.

Notes

  1. 1.

    https://github.com/mrjbq7/ta-lib

  2. 2.

    https://finet.hk/

References

  1. 1.

    Akita R, Yoshihara A, Matsubara T, Uehara K. Deep learning for stock prediction using numerical and textual information. In: 2016 IEEE/ACIS 15th International Conference on Computer and Information Science (ICIS). IEEE; 2016. p. 1-6.

  2. 2.

    Bollen J, Mao H, Zeng X. Twitter mood predicts the stock market. J Comput Sci. 2011;2(1):1–8.

    Article  Google Scholar 

  3. 3.

    Buitinck L, Louppe, G, Blondel M, Pedregosa F, Mueller A, Grisel O, Niculae V, Prettenhofer P, Gramfort A, Grobler J, Layton R, Vander Plas J, Joly A, Holt B, Varoquaux G, et al. API design for machine learning software: experiences from the scikit-learn project. In: ECML PKDD Workshop: Languages for Data Mining and Machine Learning. 2013. p. 108–122.

  4. 4.

    Cambria E. Affective computing and sentiment analysis. IEEE intelligent systems. 2016;31(2):102–7.

    Article  Google Scholar 

  5. 5.

    Cambria, E., Li, Y., Xing, F.Z., Poria, S., Kwok, K.: Senticnet 6: Ensemble application of symbolic and subsymbolic ai for sentiment analysis. In: Proceedings of the 29th ACM International Conference on Information & Knowledge Management. 2020. p. 105–114.

  6. 6.

    Cambria E, Livingstone A, Hussain A. The hourglass of emotions. In: Cognitive behavioural systems. Springer; 2012. p. 144–157.

  7. 7.

    Cambria E, Poria S, Gelbukh A, Thelwall M. Sentiment analysis is a big suitcase. IEEE Intell Syst . 2017;32(6):74–80.

    Article  Google Scholar 

  8. 8.

    Cambria E, Poria S, Hazarika D, Kwok K. SenticNet 5: Discovering Conceptual Primitives for Sentiment Analysis by Means of Context Embeddings. In: AAAI Conference on Artificial Intelligence (AAAI-18). 2018. p. 1795–1802.

  9. 9.

    Cambria E, Schuller B, Xia Y, Havasi C. New Avenues in Opinion Mining and Sentiment Analysis. IEEE Intell Syst . 2013;28(2):15–21.

    Article  Google Scholar 

  10. 10.

    Chen K, Zhou Y, Dai F. A lstm-based method for stock returns prediction: A case study of china stock market. In: 2015 IEEE international conference on big data (big data). IEEE; 2015. p. 2823–2824.

  11. 11.

    Deng, S., Mitsubuchi, T., Shioda, K., Shimada, T., Sakurai, A.: Combining technical analysis with sentiment analysis for stock price prediction. In: 2011 IEEE Ninth International Conference on Dependable, Autonomic and Secure Computing. IEEE; 2011. p. 800–807.

  12. 12.

    Ding X, Zhang Y, Liu T, Duan J. Deep learning for event-driven stock prediction. In: Twenty-fourth international joint conference on artificial intelligence. 2015. p. 2327–2333.

  13. 13.

    Domino K. The use of the Hurst exponent to predict changes in trends on the Warsaw Stock Exchange. Physica A. 2011;390(1):98–109.

    Article  Google Scholar 

  14. 14.

    Engelberg J, Mclean RD, Pontiff J. Anomalies and News. J Finance. 2018;73(5):1971–2001.

    Article  Google Scholar 

  15. 15.

    Eom C, Choi S, Oh G, Jung WS. Hurst exponent and prediction based on weak-form efficient market hypothesis of stock markets. Physica A. 2008;387(18):4630–6.

    Article  Google Scholar 

  16. 16.

    Hu Z, Liu W, Bian J, Liu X, Liu TY. Listening to chaotic whispers: A deep learning framework for news-oriented stock trend prediction. In: Proceedings of the eleventh ACM international conference on web search and data mining. 2018. p. 261–269.

  17. 17.

    Indro D, Jiang C, Hu M, Lee W. Mutual fund performance: A question of style. J Invest. 1998;7:46–53.

    Article  Google Scholar 

  18. 18.

    Levis M, Liodakis M. The profitability of style rotation strategies in the United Kingdom: Depends on temporal volatility of underlying return spread between styles. J Portf Manag. 1999;26(1):73–86.

    Article  Google Scholar 

  19. 19.

    Li X, Cao J, Pan Z. Market impact analysis via deep learned architectures. Neural Comput Appl . 2018;31(10):5989–6000.

    Article  Google Scholar 

  20. 20.

    Li X, Huang X, Deng X, Zhu S. Enhancing quantitative intra-day stock return prediction by integrating both market news and stock prices information. Neurocomputing. 2014;142:228–38.

    Article  Google Scholar 

  21. 21.

    Li X, Wu P, Wang W. Incorporating stock prices and news sentiments for stock market prediction: A case of hong kong. Information Processing & Management. 2020. p. 102212.

  22. 22.

    Li X, Xie H, Chen L, Wang J, Deng X. News impact on stock price return via sentiment analysis. Knowl -Based Syst . 2014;69:14–23.

    Article  Google Scholar 

  23. 23.

    Li X, Xie H, Song Y, Zhu S, Li Q, Wang FL. Does summarization help stock prediction? a news impact analysis. IEEE intelligent systems. 2015;30(3):26–34.

    Article  Google Scholar 

  24. 24.

    Loughran T, McDonald B. When is a liability not a liability? Textual analysis, dictionaries, and 10-Ks. J Finance. 2011;66(1):35–65.

    Article  Google Scholar 

  25. 25.

    Lucas A, Van Dijk R, Kloek T. Stock selection, style rotation, and risk. J Empir Finance. 2002;9(1):1–34.

    Article  Google Scholar 

  26. 26.

    Pedregosa F, Varoquaux G, Gramfort A, Michel V, Thirion B, Grisel O, Blondel M, Prettenhofer P, Weiss R, Dubourg V, Vanderplas J, Passos A, Cournapeau D, Brucher M, Perrot M, Duchesnay E. Scikit-learn: Machine learning in Python. J Mach Learn Res. 2011;12:2825–30.

    MathSciNet  MATH  Google Scholar 

  27. 27.

    Picasso A, Merello S, Ma Y, Oneto L, Cambria E. Technical analysis and sentiment embeddings for market trend prediction. Expert Syst Appl . 2019;135:60–70.

    Article  Google Scholar 

  28. 28.

    Shi L, Member S, Teng Z, Wang L, Zhang Y, Binder A. DeepClue : Visual Interpretation of Text-Based Deep Stock Prediction. IEEE Trans Knowl Data Eng . 2019;31(6):1094–108.

    Article  Google Scholar 

  29. 29.

    Sun J, Huang Q, Li X. Determination of temporal stock investment styles via biclustering trading patterns. Cogn Comput. 2019;11(6):799–808.

    Article  Google Scholar 

  30. 30.

    Susanto Y, Livingstone A, Ng BC, Cambria E. The hourglass model revisited. IEEE Intell Syst . 2020;35(5):96–102.

    Article  Google Scholar 

  31. 31.

    Tetlock PC. Giving Content to Investor Sentiment : The Role of Media in the Stock Market. J Finance LXI. 2007;I(3):1139–68.

    Article  Google Scholar 

  32. 32.

    Wang Y, Liu L, Gu R. Analysis of efficiency for Shenzhen stock market based on multifractal detrended fluctuation analysis. Int Rev Financial Anal. 2009;18(5):271–6.

    Article  Google Scholar 

  33. 33.

    Xing FZ, Cambria E, Welsch RE. Natural language based financial forecasting: a survey. Artif Intell Rev . 2018;50(1):49–73.

    Article  Google Scholar 

  34. 34.

    Xing FZ, Cambria E, Zhang Y. Sentiment-aware volatility forecasting. Knowl -Based Syst . 2019;176:68–76.

    Article  Google Scholar 

  35. 35.

    Xiong R, Nichols EP, Shen Y. Deep Learning Stock Volatility with Google Domestic Trends. 2015, p. 0-5. arXiv preprinthttps://arxiv.org/abs/1512.04916v3.

  36. 36.

    Zhang X, Tan Y. Deep stock ranker: A LSTM neural network model for stock selection. Lecture Notes in Computer Science (including subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics) 10943 LNCS(181). 2018. p. 614–623.

  37. 37.

    Zhuang XT, Huang XY, Sha YL. Research on the fractal structure in the Chinese stock market. Physica A. 2004;333(1–4):293–305.

    MathSciNet  Article  Google Scholar 

Download references

Funding

This work was supported in part by the National Natural Science Foundation of China under Grant 61602149, and in part by the Fundamental Research Funds for the Central Universities under Grant B210202078.

Author information

Affiliations

Authors

Corresponding author

Correspondence to Xiaodong Li.

Ethics declarations

Conflicts of Interest

All authors declare that they have no conflict of interest.

Ethical Approval

This article does not contain any studies with human participants or animals performed by any of the authors.

Informed Consent

Informed consent was obtained from all individual participants included in the study.

Rights and permissions

Reprints and Permissions

About this article

Verify currency and authenticity via CrossMark

Cite this article

Li, X., Wu, P. Stock Price Prediction Incorporating Market Style Clustering. Cogn Comput (2021). https://doi.org/10.1007/s12559-021-09820-1

Download citation

Keywords

  • Stock price prediction
  • Technical analysis
  • Sentiment analysis
  • Market style clustering