{'fraction_non_alphanumeric': 0.03164369349340448, 'fraction_numerical': 0.01506842547304975, 'mean_word_length': 4.482529794149513, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Stock Movement Prediction with Financial News using Contextualized Embedding from BERT

News events can greatly influence equity markets. In this paper, we are interested in predicting the short-term movement of stock prices after financial news events using only the headlines of the news. To achieve this goal, we introduce a new text mining method called Fine-Tuned Contextualized-Embedding Recurrent Neural Network (FT-CE-RNN). Compared with previous approaches which use static vector representations of the news (static embedding), our model uses contextualized vector representations of the headlines (contextualized embeddings) generated from Bidirectional Encoder Representations from Transformers (BERT). Our model obtains the state-of-the-art result on this stock movement prediction task. It shows significant improvement compared with other baseline models, in both accuracy and trading simulations. Through various trading simulations based on millions of headlines from Bloomberg News, we demonstrate the ability of this model in real scenarios.


Introduction
Stock movement prediction has attracted a considerable amount of attention since the beginning of the financial market, although the stock prices are highly volatile and non-stationary. Fama (1965) showed that the movement of stock prices can be explained jointly by all known information.
With the development of Internet, there is a rapid increase in the amount of financial news data (Figure 1), and more studies have been done to use computational methods to predict stock price changes based on financial news (Oliveira et al. 2013, Si et al. 2013, Xie et al. 2013, Nguyen and Shirai 2015, Luss and d'Aspremont 2015, Rekabsaz et al. 2017, Ke et al. 2019, Li et al. 2020, Coqueret 2020. Following previous works, we explore an accurate method to transform textual information into stock movement prediction signal. Schumaker and Chen (2009) use a classical feature engineering method to predict the market behavior. More recently, deep learning methods are more frequently applied on this task. Ding et al. (2014Ding et al. ( , 2015 employ structured representations to normalize a news then apply a Convolutional Neural Network (CNN) on this formulation. Hu et al. (2018) apply an improved Transformer model (Vaswani et al. 2017) to handle all the words in the raw text simultaneously to predict the forward return. Luss and d'Aspremont (2015) propose a statistical learning method to combine text data and the historical returns. Xu and Cohen (2018) improve the idea from Luss and d'Aspremont (2015) by designing a deep neural network. Ke et al. (2019) adopts a simple but effective classification method combining both regression and Term-Frequency Inversed Document Frequency (TF-IDF) model (Jones 1972). Del Corro and Hoffart (2020) further introduce an unsupervised method to extract market moving events from text data, which overcomes the problem of lacking reliable labels in financial data.
Before applying computational models mentioned above, the first step usually involves converting words into fixed-length vectors (these fixed-length vectors are called embeddings in natural language processing, details are presented in Section 2.2). Mikolov et al. (2013) propose Word2Vec model to embed words based on words co-occurrence prediction and Pennington et al. (2014) propose a similar GloVe model based on words co-occurrence frequencies. However, both methods can only generate static non-contextualized embeddings. It means that a word is converted to the same vector no matter its meaning or its context. This approach ignores the fact that the meaning of a word can change significantly in different contexts, which impacts the performance of the model. As most of the previous researches rely heavily on static non-contextualized embedding such as Word2Vec or GloVe, there can be accuracy loss. Cer et al. (2018) and Peters et al. (2018) propose methods to generate contextualized embeddings by jointly considering all the words together. They published their models trained on large English corpus. Although effective, the model is fixed and does not contain domain-specific knowledge in finance. Devlin et al. (2018) introduce a general-use language model called Bidirectional Encoder Representations from Transformers (BERT). It is one of the most promising models in natural language processing and it showed significant improvement on multiple benchmarks ). The BERT model is pre-trained on a very large scale of textual data to leverage all the features in natural languages, and it also provides the ability to fine-tune this pre-trained model with domain-specific data without needing to start from the scratch. As we have a large amount of financial texts, we can use them to add financial knowledge to the BERT model and generate contextualized embeddings with domain-specific knowledge in finance from BERT.
In addition, previous researches evaluate the performance of the models based on the accuracy calculated on all the news (Ding et al. 2015, Xu and Cohen 2018, Hu et al. 2018. However, this evaluation metric does not reflect the real capability of the model since investors only care about the news which can move the market significantly. The news identified as neutral have little impact on investors' decisions, as investors will simply ignore the news if they are classified as neutral.
In this paper, aiming to solve the problems mentioned above, we want our research to have the following characteristics: • It adopts the contextualized embeddings instead of the static embeddings.
• The contextualized embeddings contain financial domain-specific knowledge.
• Our model has a better prediction on the news which can move the market significantly.
Hence, based on previous work (Sec. 2), we propose Fine-Tuned Contextualized-Embedding Recurrent Neural Network (FT-CE-RNN) to predict the stock price movement based on the headlines (Sec. 3). Using Bloomberg News dataset (Sec. 4), this model generates contextualized embeddings with domain-specific knowledge using all the hidden vectors from the BERT model fine-tuned on financial news. Then FT-CE-RNN uses a recurrent neural network (RNN) to make use of the generated embeddings. (Sec. 5) We also introduce a new evaluation metric which calculates the accuracy on various percentiles of the prediction scores on the test set instead of the whole test set to better incorporate investors' interests. Our experiments show that our FT-CE-RNN achieves a state-ofthe-art performance compared with other baseline models. We also evaluate our model by running trading simulations with different trading strategies. (Sec. 6)

Stock Movement Prediction
Stock movement prediction is a widely discussed topic in both finance and computer science communities. Researchers predict the stock market using all available information, including historical stock price, company fundamentals, third-party news sentiment score, financial news, social media texts and even satellite images.
The most classical method is to use the historical stock prices to predict the future prices. Kraft and Kraft (1977), Sonsino and Shavit (2014), Ariyo et al. (2014), Kroujiline et al. (2016), Jiang et al. (2018) use time series analysis techniques to extract the patterns of historical returns, and predict the future stock movement based on these patterns. More recently, researchers start to use neural networks to analyze this pattern (Kohara et al. 1997, Adebiyi et al. 2012, Tashiro et al. 2019, Chen and Ge 2019, Mäkinen et al. 2019, Bai and Pukthuanthong 2020.
Financial analysts usually use companies' fundamental indicators from their financial reports to predict the stocks' prices in the future (Zhang and Yan 2018). This includes the use of earnings per share (EPS) (Patell 1976), debt-to-equity (D/E) ratio (Bhandari 1988), cash flow (Liu et al. 2007), etc. Nonejad (2021 builds a conditional model to jointly consider historical prices and financial indicators. With the rapid development of the natural language processing and deep learning, researchers start to focus on predicting stock movement based on textual data, such as financial news and social media texts, which were viewed as difficult to process systematically. Financial news data vendors such as Bloomberg, ThomsonReuters and RavenPack all include their proprietary sentiment analysis on the news. Coqueret (2020) thoroughly analyzes the sentiment classification given by Bloomberg and finds disappointing results on its predicting power. Ke et al. (2019) include the RavenPack's proprietary score as a benchmark and find it less performing than other models.
Hence, more researchers propose their own natural language processing models to improve the predictability based on financial news. Luss and d'Aspremont (2015) propose an improved Kernel learning method to extract the features in the texts. Ke et al. (2019) use statistical learning methods to determine the sentiment of the words in the news. More recently, computer scientists begin using state-of-the-art deep learning techniques to solve this problem. Ding et al. (2015), Hu et al. (2018), Xu and Cohen (2018), Li et al. (2020) propose different deep learning models to extract information from both financial news and social media texts.
There are also other researches which use uncommon data to predict future stock prices. The data includes key people compensation (Cooper et al. 2016), satellite images (Donaldson and Storeygard 2016) and the pictures included in the news (Obaid and Pukthuanthong 2021).

Contextualized Embedding
In the natural language processing, the first step usually involves transforming words or sentences into fixed-length vectors to allow numerical computations. These fixed-length vectors are known as the embeddings of the words or the sentences.
Historically, researchers use one-hot embeddings (Stevens et al. 1946) to encode words. However, the dimension of the one-hot embedding is large since each unique word takes one dimension. Hence, researchers start to develop methods to make the word embeddings denser.
The most widely used methods for word embedding are Word2Vec (Mikolov et al. 2013) and GloVe (Pennington et al. 2014), both of which are based on word co-occurrences. Such models take in a large number of texts and output a fixed vector for each word in the texts. The more frequently the two words co-occur, the more correlated two embeddings are. Once the model is trained, the embeddings of the words no long change, therefore we call these embeddings static embeddings. Such model generates the same embedding for one word no matter its context, although the meanings of the words can depend on the context in which this word occurs.
Researchers propose contextualized embeddings to solve this issue. Instead of taking only one words as input, the contextualized embedding model accepts the whole sentence as its input. The model then generates the embeddings for each word in the sentence by jointly considering the word and all the other words in the sentence. Cer et al. (2018) proposes Universal Sentence Encoder (USE) to encode the whole sentence contextually. However, USE only gives the embedding of the sentence as a vector without specifying the embedding of each word. Peters et al. (2018) proposed Embeddings from Language Models (ELMo) to embed words based on their linguistic contexts, but ELMo is trained on general English language, making the generated embeddings lack of financial domain-specific knowledge. However, Yang et al. (2020) showed domain-specific model outperforms general models in most of the tasks.
Recent researches on general-use language model such as BERT (Devlin et al. 2018) and XLNet (Yang et al. 2019) reported impressive result on all natural language processing tasks. More interestingly, these models propose a way to fine-tune its pre-trained model on general English with domain-specific data.
Hence, we propose FT-CE-RNN to complement existing researches. FT-CE-RNN generates contextualized embeddings with domain-specific knowledge from the BERT model, it then makes the stock movement prediction based on this more advanced embedding.

Problem Formulation
Suppose that we have a stock s with a headline h s,t recorded at time t, and the headline has N words, we denote them by w 1 , ..., w N . We first need to transform them into fixed-length embeddings. Suppose that the length of the embedding is l e , this process can be written as: where Emb i ∈ R le is the embedding of the word w i and f s denotes the static embedding encoder. In this case, each word has a fixed embedding independent of its context. A contextualized embedding encoder has the same function of converting a word into a vector, unless it considers all the words in a sentence together. We use f c to denote this contextualized embedding encoder, it can be written as: We concatenate the embeddings of all words to get the embedding of the headline h s,t . We define the embedding of this headline as: where Emb hs,t ∈ R le×N . Following the work of Luss and d'Aspremont (2015), Ding et al. (2015), Xu and Cohen (2018), Ke et al. (2019), we formulate the stock movement prediction as a binary classification task 1 . It means that we predict if a news has a positive impact or a negative impact on the related stock.
We define its market-adjusted return r s,t as where P s,t denotes the price of stock s at time t and P m,t denotes the value of the equity index at time t. We notice that it is necessary to use market-adjusted return instead of the simple return, as the information contained in the price change is partially due to the information related to this stock (such as news), and also partially due to the information related to other macroeconomic information (such as interest rate, fiscal policies, etc.). As the macroeconomic effect impacts all stocks, it can be explained by a weighted sum of all stocks, such as market index. We can simply remove this impact by subtracting the index return from the stock return, and this adjusted return can better explain the impact of the news.
Most researches in the stock movement prediction based on news simply suppose that all the news induce the market change in the same way (Luss and d'Aspremont 2015, Xu and Cohen 2018, Hu et al. 2018, Ke et al. 2019, and therefore use the same ∆t to calculate the forward returns of all news. However, Fedyk (2018) suggests that the news during the trading hours and the news outside the trading hours have different market impact.
Hence, for different news, we choose different ∆t. For example, for the news published during the trading hours, the price can change in several minutes after the arrival of the news. In this case, we can choose a smaller ∆t of several minutes or several hours. However, for the news published out of the trading hours, as the market is already closed, we cannot observe the effect of the news until the next market open. Therefore, we need to choose a ∆t of several days.
We define the stock price movement as: The goal is to predict Y s,t from the embeddings of the headlines Emb hs,t . It can be written as: where g represents the prediction model.

Data Description
The dataset that we use is Bloomberg News 1 . In this dataset, each entry contains a timestamp showing when this news is published, a ticker which tells the stock related to this news and the headline of this news. In addition to the necessary information above, there are two fields given by Bloomberg's proprietary classification algorithm. The score is among -1, 0 and +1, which indicates if the news is either negative, neutral or positive. Confidence is a value between 0 and 100 related to score. A higher confidence value means that Bloomberg's model is more sure about its score. Bloomberg's classification will serve as one of the benchmarks for our prediction model. We present a sample dataset in Table 1. We need to address that in our dataset, we only have the headlines of the news instead of the whole article.
In our experiment, we use the news data on all the stocks from the STOXX Europe 600 index 2 which represents the 600 largest stocks of the European market. In order not to overfit, we select a short period (from 01/01/2016 to 30/06/2018) as our training set and another short period (from 01/07/2018 to 31/12/2018) as our development set. We tune the parameters of the models only based on this subset of the data, we then test on the whole period (from 01/01/2011 to 31/12/2019) on a 3-year rolling basis. It means that we generate the classification result of the year y using model trained between y −3 and y −1, without varying the parameters initially obtained. Detailed statistics of the dataset are in Table 2. We can also find the number of news in each year from Figure 1. In addition to the Bloomberg news dataset, we also use the cooperate action adjusted share prices at market close and intraday minute bar share prices for all the stocks. The share prices are used to label our data and simulate our trading strategies.

Data Labelling
For this supervised learning task, we need to provide our model with the ground-truth as its target. However, our data is simply the headlines of the financial news, it does not tell us if a news is positive or negative. Hence, we need to give each news in the training set a label (positive or negative) before training our model.
The intuition behind our labelling method is simply that if a news is positive, the investors will start to overbuy the related stocks, the stock should therefore outperform the market and vice versa. We use Equation 4 to calculate the market adjusted return for each news. As discussed in Section 3, we consider the different effects of the news which occur during the trading hour 1 and those outside the trading hour. We use different ∆t (Eq. 4) for the news during the trading hours and outside the trading hours. For the news inside trading hours, we choose ∆t i and for the news outside the trading hours, we use ∆t e . 2 We show an example of the distribution of the returns for all the news in Figure  2.  We label the data based on the market-adjusted return mentioned above. As our task is to identify 1 9:00 to 17:30 CET for most European markets 2 For ∆t i , we test 5,30,60,120 minutes; for ∆te, we test 1,2,3,5 days.
market-moving news which investors focus on, we need to remove news which do not have significant impact on the price. As we found that the return distribution is quite balanced for the training set ( Figure 2), we simply label the 15% news with most positive return as 1 and the 15% news with most negative return as 0. This can be written as: where Y s,t,train is the label for the news e s,t for stock s recorded at time t in the training set.
However, for development and test sets, we label all news with positive return as 1 and all news with negative return as 0. This can be written as: This difference in labelling is simply to avoid the information leakage. In real-life scenario we cannot know the forward return of a news when it is published. Therefore, we cannot know if the news is in the top 15-percentile or the bottom 15-percentile. We are supposed to give each news a score when it is published regardless its forward return. However, we can choose to exclude a news according to its score when calculating the metrics, as this information is available immediately after we receive the news. We use this idea to construct different test sets to evaluate of model. We present the details in Section 6.2.

Prediction Model
There are two main components in our model: a contextualized embedding encoder from BERT model and a Recurrent Neural Network (RNN) which takes the contextualized embedding as input and outputs the classification probability for both classes.

Contextualized Embedding Encoder from BERT
The Bidirectional Encoder Representations from Transformers (BERT) proposed by Devlin et al. (2018) is a widely used language model in the natural language processing applications. It is first pre-trained on very large scale data (WikiBooks 1 and Wikipedia 2 ) to learn the basic characteristics of a language. After this pre-training phase, we can obtain a pre-trained base BERT model for all other downstream tasks (such as text classification). This pre-training process is computationally intensive, we simply use the pre-trained BERT model published by Google 3 . Figure 3 shows the structure of BERT model. It has L layers and each layer has N nodes, each node is a Transformer (Vaswani et al. 2017). The first layer takes a tokenized headline as input and the BERT model generates N × L hidden vectors, denoted by T i,j . The first token at the first layer is a special [CLS] token reserved for fine-tuning. For a specific downstream task, we can fine-tune the base BERT model suitable for this specific task. It means that we do not initialize the parameters of BERT model randomly, we use the pretrained BERT model as our initial state instead. We update the parameters in the base model with our domain-specific data. This approach adds domain knowledge to the large scale language model . BERT model with input headline "company lost about 80 percent of its market value after interim data" and the maximum length of model is set to 10 (N = 10). The last two words interim and data are therefore trimmed. There are L layers in this BERT model. T oki denotes the i-th token of the tokenized news and N denotes the maximum length of a headline. Ti,j represents the hidden vector for the j-th transformer at layer i. The first [CLS] label is simply a special string we choose to signify the class of this headline. This label is only used when fine-tuning the model, we leave it blank when we generate the embeddings. The original method to use BERT as classification model is to use directly [CLS] vector to represent the whole sentence, while we choose to use all hidden vectors at one layer to represent the sentence. The embedding generated with the model is shown in Equation 11. (Yang et al. 2020), it can help the BERT model better understand the texts in specific situations. In our case, we can fine-tune the base BERT model with our labelled financial news data mentioned in Section 4.2 to make it specialize in financial texts.
The fine-tuning process is straightforward. We input the class label (0 or 1) together with the tokenized headline into the first layer of a pre-trained BERT model. We set the target to the class label and loss function to cross-entropy, defined as: where Y i is the label for the news i and P + i denotes the probability that the news i is positive given by the model. We use back-propagation (Hecht-Nielsen 1992) to update the parameters in the model. We repeat such operation for several epochs until the loss converges.
In order to generate the contextualized embedding, we can either directly use the base BERT model or use the fine-tuned model. We first tokenize our headlines using SentencePiece tokenizer (Kudo and Richardson 2018). If the number of tokens is smaller than N , we simply pad it to N tokens by adding null tokens at the end. If there are more than N tokens, we remove the last tokens to make this sentence have exactly N tokens. We input these tokens into pre-trained BERT model as shown in Figure 3 with the first token which stands for [CLS] label left blank. Suppose that our BERT model has L layers, we can then generate L different embeddings, denoted by Emb base,l . We have, where Emb base,l is a size(T l,i ) × (N − 1) matrix representing this headline and l denotes the layer from which we generate the embedding. We have 1 ≤ l ≤ L. Similarly, we can generate another L embeddings from the fine-tuned BERT model, denoted by Emb tuned,l . We have, where T l,i denotes the hidden vector for the i-th token at the l-th layer for the fine-tuned model.

RNN Prediction Model
The structure of our prediction model is simple and straightforward, it is shown in Figure 4. There are several layers of cells which can either be Vanilla RNN (Cleeremans et al. 1989), Long-Short Term Memory (LSTM) (Hochreiter and Schmidhuber 1997) or Gated Recurrent Unit (GRU) (Cho et al. 2014). The size of output at each layer shrinks in order to reduce the dimension of our features gradually and to make the remaining features more meaningful. Two neighbor layers are connected by a dropout to overcome the overfitting problem in the network. At the end of the last layer, a softmax is added to calculate the probability for each class based on the last vector on the last layer.
Suppose that we choose to use Emb base,l to represent a sentence. We first initialize the parameters in the RNN model randomly and input the embeddings of tokens (T l,i ) sequentially into the cells (Cell 1,i ) in the first layer of the recurrent neural network. At the same time, we set the target to the corresponding label of the headline. We use the same cross-entropy loss mentioned in Equation 10 as our loss function. We use the same back propagation procedure in Section 5.1 to update the parameters in the model until we have a stable loss.

Experiments
In this section, we introduce our experiment setup and results in detail. We also include the results of some baseline models to prove the effectiveness of our model. In addition to the final result, we add some ablation experiment results to show the effect of some factors in our model.

Training Setup
We use the pre-trained 12-layer, 768-dimension, 12-heads BERT model 1 to generate E base,l , then we fine-tune this base model using our labelled dataset with the method mentioned in section 4.2. 2 We choose the best-performing fine-tuned model to generate E tuned,l . Empirically, the layer of BERT used as embedding should not be too close to the first layer, otherwise the contextualized embedding will be too similar to the static embedding. Hence, we only test embeddings with l = L, L−1 or L−2. This choice will be discussed in detail in Section 6.6.
The maximum length of a sentence is set to 32 tokens, as there are at most 29 tokens for all headlines in our dataset. If there are fewer tokens, we pad it to 32 with null tokens. For our RNN model, the cells are set to be LSTM. We use a four-layer single-directional RNN 3 with a dropout rate of 50%.

Evaluation Metrics
Because of the huge volume of news that we receive daily, it is not realistic for either human investors or systematic trading algorithms to react on all news. Otherwise, we lose a considerable amount of transaction fees on the news which do not significantly move the market. It is more logical that an investor first reads the news, then buys or sells the stock if he thinks that the news can have substantial impact on the stock price. If he thinks that the news is neutral, he will simply ignore the news. In this type of neutral-insensitive scenario, evaluating our model on all news is less meaningful. Instead, we evaluate our model only on certain "extreme" news chosen based on their sentiment classification results.
We define the score of a news, denoted by S news : where P + (news) denotes the probability that this news belongs to the positive class given by the prediction model. S news is therefore a value between -1 and 1. We use P n to denote the n th percentile of all scores on the training set. We can then choose the set on which we want to evaluate our model. We define this set E 2n by: We assume that the distributions of scores on the training set and the test set are the same. It should contain about n% highest-score news and n% lowest-score news from the test set. We evaluate our model on these subsets of news instead of all news in the test set.

Standard Metrics
Given a confusion matrix tp f n f p tn which contains the number of samples classified as true positive (tp), false positive (f p), true negative (tn) and false negative (f n). We use both the accuracy and the Matthews Correlation Coefficient (MCC) (Matthews 1975) to evaluate our models. These two values are defined by: Accuracy:

Trading Strategies
However, those two metrics introduced above do not perfectly reflect the reality, as the profits are quite different when the price goes up significantly or mildly, although they are both counted as true positive. Hence, it is necessary to simulate these trades on real markets. We use two simple trading strategies for simulations.

Strategy 1 (S1).
We simply follow the strategy used by Ke et al. (2019). Before each market close, we search for all the news belonging to E n with a maximum age of A days. We group the selected news by stock and we calculate the average score for each stock. We choose the 20 stocks with the highest scores, our target position for these stocks is $T. We also choose the 20 stocks with the lowest scores, our target position for these stocks is -$T.

Strategy 2 (S2).
The advantage of S1 is that it perfectly balances the long leg and the short leg. 1 As such, we have no exposure to the market, and it reduces the risk of the market movement. However, the fallback of S1 is that it only focuses on the highest scores instead of considering all the stocks. In this case, we will not be able to fully use our predictions. Hence, we design the following strategy to solve this problem: 1. We first calculate the average score for each stock using the same method as described in S1.
2. We choose all the stocks with positive scores, s + i denotes the score for the stock i. 3. The target position for the stock i is $20T × s + i / j s + j . 2 4. We invest in the stocks with negative scores in the same way. For a negatively scored stock i, This strategy not only uses all the available classification results, but also has no exposure to the market as S1, since the long position and the short position are both 20T .
To evaluate the performance of these strategies, we use the following two commonly used indicators in finance.

Annualized return: defined by
where D is the number of trading days in one year 1 , and r t denotes the daily return of the portfolio for the day t, defined by the ratio of the profit on day t to the total position on day t.

Annualized Sharpe Ratio: defined by
r denotes the mean of all the r i and σ(r) represents the standard deviation all the r i .

Baselines and Proposed Models
We use the following models as baselines.
• NBC (Maron 1961): Naive Bayes Classifier One of the most traditional language classification models based on word frequency. • SSESTM (Ke et al. 2019

): Supervised Sentiment Extraction via Screening and Topic Modeling.
A regression model based on word frequency and stock returns.

• Bloomberg (Proprietary): Bloomberg Sentiment Score
The sentiment score from Bloomberg's proprietary model, which comes along with the Bloomberg News dataset. An example of this sentiment score is shown in Table 1.

): Bidirectional Encoder Representations from Transformers
A general and powerful language model for a wide range of NLP tasks. We directly use the [CLS] label as the final prediction, as proposed by the author.

): Financial Sentiment Analysis with BERT
The same structure as the BERT model but pre-trained with financial domain-specific data.
To make a detailed analysis of the improvement brought by our proposed models, in addition to the final version of our model (FT-CE-RNN), we add two other intermediate variants of our RNN model.

• RNN: Recurrent Neural Network
The recurrent neural network introduced in Section 5.2. Instead of using contextualized embeddings, we use the static Word2Vec embedding as its first layer.

• CE-RNN: Contextualized Embedding -Recurrent Neural Network.
The network structure is the same as RNN, but we use contextualized embedding generated from base BERT model instead of Word2Vec.

Results
The detailed results for standard metrics are shown in Table 3 and Figure 5. We also list the results from trading simulations in Table 4.  We find that in terms of accuracy, our FT-CE-RNN outperforms all the other baselines models. Especially, comparing the accuracy of RNN and FT-CE-RNN, there is an improvement of 4.1% when we test on the 1% most extreme news (E 1 ). This result shows the power of contextualized embedding against static embedding. We also notice that there is an improvement of 0.9% compared with BERT result. This result explains that using all hidden vectors instead of only one [CLS] vector helps improve the result. However, if we directly use the embedding from the base BERT (CE-RNN) instead of the fined-tuned BERT (FT-CE-RNN), there is a clear disadvantage. This result shows the necessity of including the domain knowledge in the embeddings.
In addition, we observe that all our models have a significant margin compared with the Bloomberg and SSESTM sentiment score, which is completely independent of our data labelling and modelling process, this result can prove the efficiency of our models compared with other widely used models in the industry. In our trading simulations, we use a look-back window of 5 days (A = 5 days). We find that the result of our FT-CE-RNN outperforms all other models in most of the cases. The most significant improvement is on Sharpe Ratio. When trading on the 1% most extreme news using strategy S2, there is an improvement of 0.69 (49%) in Sharpe ratio and an improvement of 6.62 (51%) in return if we compare BERT and FT-CE-RNN. It means that our model using contextualized embedding is not only more profitable but also more stable.
We can also find that S2 performs better than S1, since S2 uses all the signals while S1 only uses the signals on the top/bottom stocks. This proves that our classification is valid for most of the stocks, making it a robust method.
An example of trading simulation is shown in Figure 6. It shows how our profit evolves with time. We observe that FT-CE-RNN is not only better on profitability and stability but also on the absolute profit in dollars. Our trading simulations ignore transaction costs thus far, since the primary goal of this research Figure 6. Trading simulation result in absolute profit. This trading simulation is run on 1% most extreme news (E1) using strategy S2. We also include the market return, represented by Europe STOXX 600 Index. We can see our models largely exceed the market return and the Bloomberg sentiment score.

Transaction costs
is to prove the effectiveness of our sentiment model with contextualized embedding. The transaction costs have no impact on the result because all the models are in the same no-cost environment. That said, applying this model in real-life trading is another separate but interesting question. To understand the real gain of our FT-CE-RNN model for the asset management, we rerun our trading simulations with transaction costs.
In our simulations, we assume a transaction cost of 4bps 1 proportional to the daily turnover 2 . The simulation results with transaction costs are shown in Table 5.
Although the transaction costs cut our profits significantly, we can still have a profitable margin when using our FT-CE-RNN model.

Effect of Embedding Layer
In this section, we discuss our choice of BERT hidden layer to be used as embedding.
Empirically, the final layer of BERT model should be used to generate our contextualized embedding as the final layer is more "mature" and contains more information compared with other layers which are closer to the first layer. However, our result listed in Table 6 shows the opposite.
We find that the best result for CE-RNN is acquired when we use layer L while the best result for FT-CE-RNN is obtained when using layer L − 1. The reason for this phenomenon is that the last layer of the fine-tuned BERT is biased towards the classification result, since the goal for the fine-tuning process is to make the first token of the last layer close to the classification target. If we use the last layer of the fine-tuned BERT as the input for RNN, we are simply replicating the classification process of the BERT, instead of improving the result. Using one deeper layer (L − 1) helps reduce this bias (Xiao 2018). However, the base BERT does not have this bias on the last layer since it has no previous knowledge on the training set. This explains why CE-RNN has a better performance when using the embedding from the last layer (L). If we use an even lower layer to generate contextualized embedding, such as L−2, the performance declines as it is too close to the embedding layer and lacks contextualized characteristics.

Effect of Classification Classes
During our initial researches, we also explored the possibility of using a 3-class classification instead of a 2-class classification. It means that we do not classify a news into a positive or a negative news, we classify if a news is either positive, negative or neutral. This is the method adopted in the Bloomberg's proprietary model. b For 3-class classification, we choose the n/2% largest scores for the positive class and the n/2% largest scores for the negative class as our En. The guarantees the same number of the news considered in both cases.
The result of using a 3-class classification model is shown in Table 7. We find a significant worse performance if we add another possibility to our model. This is because a 3-class model supposes a clear difference between the market-moving news and the neutral news, however, this is not always the case. It is not obvious to find a threshold, above which the news is positive and below which the news is neutral. In this scenario, we are not able to construct a clear training set for our model to learn the difference between a neutral news and a market-moving news.
Hence, in our final model, we decide to classify the news into two classes instead of three.

Qualitative Analysis of the Classification Result
We analyze the news in E 1 to see if there is any pattern, for example, some frequent words in them. We include the 50 most frequent words appeared in E + 0.5 and 50 most frequent words in E − 0.5 in Appendix A, along with their frequencies. We exclude all the stopwords in English, such as to, for, a, etc.
We can find that for the news identified as the most positive, some common words include buy, upgrade, raise, etc. For the news identified as the most negative, downgrade, cut and miss are among common words. These are also logical keywords for the humans, making the result from the neural network intuitive.
We can also find in this collection that there are also some less natural words, such as fly, say neutral, etc. However, as these words appear in both categories, the effect of such words is neutralized if we empirically assume the effect of a word is its positive impact minus its negative impact.
This result is similar to the result we get from the word frequency-based method, such as NBC and SSESTM. However, we demonstrate that our FT-CE-RNN model is significantly more powerful than these two baseline models (Section 6.4). This phenomenon implies that our model is capable of capturing complex information in the news on top of the word frequency.

Conclusion
We build the whole pipeline for the stock movement prediction task with headlines from financial news, including labeling the news, generating contextualized embedding, training a neural network model, validating the model with various metrics and building trading strategies based on the model output.
We design a FT-CE-RNN model which uses fine-tuned contextualized embeddings from BERT instead of the traditional static embeddings. We also introduce our new evaluation metrics focusing on market-moving news, which are more suitable for asset manager's needs.
Through various experiments on the Bloomberg News dataset, we demonstrate the effectiveness of our FT-CE-RNN model. We find a better performance, in both accuracy and trading simulations, than other widely used baseline models. We also include other ablation studies to discuss the choice of some important parameters and to demonstrate the intuitiveness of the result.
In the future, we will continue our research on the stock movement prediction using natural language processing methods based on longer texts (such as earning call transcripts, financial reports, etc.) instead of the headlines. By using more information, we aim to build a model which helps achieve better stock movement prediction result.