## 3 Method
### Distance Calculation Functions
Many distance measures have been proposed to compute the distances between two temporal sequences ([31; 32; 33; 34]). Among these dozens of offerings, DTW has been proven to be an effective algorithm to compute the distance between two temporal data sequences, and it outperforms other alternatives in most domains [17; 35]. Given two temporal sequences \(P\) and \(Q\), both of which contain a sequence of real-valued data points, DTW aligns \(P\) and \(Q\) using the shortest _warping path_ in a distance matrix, where a warping path \(W\) is a sequence of adjacent matrix indices that defines a match between \(P\) and \(Q\). Given two temporal sequences, there is a large number of warping paths for them, and the optimal path is the one with lowest global warping cost [36]. To compute the global warping cost for two temporal sequences, one has to use some distance function \(d(X,Y)\) to measure the local distance between every pair of data points from the two sequences \(X\) and \(Y\) in consideration. The choice of local distance function depends on the data type used in the sequence. A simple but effective method for computing local distance is _Euclidean distance_ (_ED_). It is illustrated as below, given two data points \(X\in\mathbb{R}^{d}\) and \(Y\in\mathbb{R}^{d}\). The Euclidean distance between \(X\) and \(Y\) is defined as follows:  
\[d_{ED}(X,Y)=\sqrt{\sum_{i}^{d}(x_{i}-y_{i})^{2}}.\]  
Although using Euclidean distance is an effective approach for computing the distance of two data points on a hyperplane, it is not an ideal way to compute the distance of two data points that contain non-real value elements. Notice that in our problem setting, the data points of a temporal stock data are composed by heterogeneous data items where each includes both a numeric element and a textual element. A desirable local distance function would be one that combines different local distance functions for each of the two data types. This motivates us to demonstrate DTTW in this paper. Dynamic Time-Text Warping. DTTW uses the same idea as DTW. The only difference is the choice of local distance function for two data points. In our problem setting, the stock temporal sequence in consideration contains a sequence of data points of complex types. Specifically, in our setting, a temporal sequence of some stock \(X\) is a sequence of observations: \(X=\{X_{1},\dots,X_{m}\}\), where \(X_{i}=(X_{i}^{n},X_{i}^{t})\) is a binary tuple where \(X_{i}^{n}\) represents the stock price of \(X\) at time \(i\), and \(X_{i}^{t}\) represents the textual information (i.e., corresponding financial news) observed at time \(i\). A building block for computing the global distance for two stock temporal sequences with DTTW is to design a local distance function \(d_{\text{local}}\) for a pair of data points of the aforementioned form. In this paper, the authors use the following local distance function in DTTW:\[d_{\text{local}}(X_{i},Y_{i})=\underbrace{w_{n}\cdot d_{\text{numeric}}(X_{i}^{n},Y_{i}^{n})}_{\text{numeric observation part}}+\overbrace{w_{t}\cdot d_{\text{text}}(X_{i}^{t},Y_{i}^{t})}^{\text{text{text}}}\enspace, \tag{3}\]  
where \(w_{n}\) and \(w_{t}\) are two real-valued weight factors, \(d_{\text{numeric}}(\cdot)\) is the distance function for numeric elements (e.g., Euclidean distance), and \(d_{\text{text}}(\cdot)\) is some distance function measuring the distance between two textual data (e.g., distance based on cosine similarity for two bag-of-words feature vectors). It is not hard to see that \(d_{\text{local}}\) is a linear combination of two quantities: \(d_{\text{numeric}}\) and \(d_{\text{text}}\). Two important questions remain to be answered. Firstly, what are the two distance functions \(d_{\text{numeric}}\) and \(d_{\text{text}}\)? Secondly, what are the values for the two corresponding weight factors \(w_{n}\) and \(w_{t}\)? It turns out the first question is easier and less important than the second one because there has been extensive study on how to design distance functions for different data types.