# A Trend-Based Segmentation Method and the Support Vector Regression for Financial Time Series Forecasting

Authors: Jheng-Long Wu; Pei-Chann  Chang
Journal: Mathematical Problems in Engineering
 (2012)

---

## Abstract

This paper presents a novel trend-based segmentation method (TBSM) and the support vector regression (SVR) for financial time series forecasting. The model is named as TBSM-SVR. Over the last decade, SVR has been a popular forecasting model for nonlinear time series problem. The general segmentation method, that is, the piecewise linear representation (PLR), has been applied to locate a set of trading points within a financial time series data. However, owing to the dynamics in stock trading, PLR cannot reflect the trend changes within a specific time period. Therefore, a trend based segmentation method is developed in this research to overcome this issue. The model is tested using various stocks from America stock market with different trend tendencies. The experimental results show that the proposed model can generate more profits than other models. The model is very practical for real-world application, and it can be implemented in a real-time environment.


---

## Body

## 1. Introduction

Support vector machines (SVMs) have outperformed other forecasting models of machine learning or soft computing (SC) tools such as decision tree, neural network (NN), bayes classifier, fuzzy systems (FSs), evolutionary computation (EC), and chaos theory by many researchers from historical nonlinear time series data applications in the last decade [1–5]. In these techniques, many researchers presented different forecasting models in dealing with characteristics such as imprecision, uncertainty, partial truth, and approximation to achieve practicability, robustness, and low solution cost in real applications [6–8]. However, the most important issue in resolving the nonlinear time series problem is error revision. ANNs use the empirical risk minimization principle to minimize the generalization errors but SVRs use the structural risk minimization principle because SVR is able to analyze with small samples and to overcome the local optimal solution problem, which surpasses to ANNs [9–11]. Therefore, the SVRs forecasting model is applied to accomplish the forecasting task in this research. Presently, support vector regression (SVR), which was evolved from support vector machine (SVM) based on the statistical learning theory, is a powerful forecasting and machine learning approach for numerical prediction [12–15]. Also, SVR has high toleration error rate and high accuracy for learning solution knowledge in complex problems [16]. Although SVR can be applied well in time series data, the input vector is a key successful factor. Despite the volatile nature of the stock markets, researchers still can find certain correlations between these factors and stock prices. An investor’s primary goal is to make profits. In order to help investors achieve their financial objectives, researchers have studied the relationship between financial markets and price variations over time from [17–20].In the last few years, several representations of time series data have been proposed; the most often used representation is piecewise linear representation (PLR) [21–23]. It can decompose a time series data into a series of bottom and peak points [24, 25] in financial market. But the traditional PLR does not consider the multiple trending characteristics in time series. Moreover, the price movements of stocks are affected by many factors such as government policies, economic environments, interest rates, and inflation rates. The share prices of most listed companies also move up and down with other changing factors like market capitalization, earnings per share (EPS), price- to -earnings ratio, demand and supply, and market news. Moreover, there are more fractal properties of financial data, such as self-similarity, heavy-tailed distributions, long memory, as well as power laws [26–29]. One of fractal properties is long memory which is a common characteristic in financial data or other fields [30–32]. The daily stock trading is a short-term return so in this paper these fractal properties were not considered in our framework, just focusing on the real stock price’s trends.Therefore, there is a need to develop a new segmentation method which takes the price moving trends into consideration. As a result, this research will consider the multiple trends of stock price’s movements in TBSM segmentation approach to capture the embedded knowledge of nonlinear time series. This research intends to improve the SVR forecasting performance using a trend based decomposition method. The TBSM approach has captured the tendency of stock price’s movement which can be inputted into SVR in learning the historical knowledge of the time series data. Moreover, a more accurate forecasting result can be achieved when applied in real-time stock trading decision.The rest of this paper is organized as follows. In Section2, we describe TBSM segmentation principle. Forecasting model is discussed in Section 3. Section 4 explains modeling for trading decisions including using historical data to make trading decisions by the TBSM approach, selecting highly correlated technical indices by stepwise regression analysis (SRA), forecasting trading signals by SVR, and evaluating trading strategies. Section 5 explains how the TBSM with SVR for stock trading decisions and compares the profits obtained from various forecasting approaches. Finally, conclusions and directions for further research are discussed in Section 6.


## 2. A Trend Based Segmentation Method (TBSM)

In the time series database there are many approaches such as Fourier transform, wavelets, and piecewise linear representation which can be applied to find the turning point on time series data. According to the characteristics of sequential data, a piecewise linear representation of the data is more appropriate. A variety of algorithms to obtain a proper linear representation of segment data have been presented. As reported in [33–36], PLR is used to support more tasks and provides an efficient and effective solution. In this paper we intend to enhance the segmentation accuracy based on different trends in stock price’s movements. The basic idea of TBSM is to modify the PLR segmentation using the trend tendency in a specific time period. Three different trends such as uptrend, downtrend, and hold trend will be considered when making the segmentation. Detailed procedures of TBSM include the following. (1) PLR is applied to locate the turning points from the time series including up or downtrends. (2) The points around each turning point will be double-checked if the variations of the points are within the threshold. If yes, these points will have the same buy/sell trading in this period. (3) These points are set to be in the same trend. The pseudocode of the TBSM is shown in Algorithm 1.Algorithm 1:A pseudocode for TBSM in time series data.
Define:Threshold // cutting thresholdX_Thld // horizontal areaY_Thld // vertical areaX // a time seriesY // stock price1: Procedure TBSM(T)2: LetT be represented as X[1,2,…,n], Y[1,2,…,n]3:n= 04: Draw a line between(X1,Y1) and (Xn,Yn)5: Maxd = maximum distance of (Xi,Yi) to the line6:If(Max d > Threshold)7:  Let(Xi,Yi) be the point with maximum distance8:  Forj = X1:Xn9:   If (|Xj-Xi| < X_Thld) and (|Yj-Yi| < Y_Thld)10:    Then Point[n]=[Xj,Yj], n = n + 111:   End If12:  End For13:  Select from Point[n]:Xt1=Min(X0),Xt2=Max(Xn)14:  Return:S1 = T[X1,Xt1]15:      S2 =T[Xt2,Xn]16: End IfFor example, a time seriesT={t1,t2,…,t191} with 191 data is given to explain the basic idea of the TBSM procedure. As shown in Figure 1(a), several trading points are represented as buy (four red points) or sell (six green points) in this case. According to the TBSM procedure, we can draw a line S1form the first point to the last point as shown in Figure 1(b) and find the max distance to line S1which is point t26. Then line S1 is decomposed into two segments including line S2 from t1 to t26 and line S3 from t26 to t191. Based on point t26, we can locate point t16 to t56 which are varied within the threshold. These points are set as hold trend and with the same state of point t26. Therefore line S2 and line S3 will be changed to three different lines including line S4 from point t1 to point t16, line S5 from point t16 to point t56, and line S6 is from point t56 to point t191 as shown in Figure 1(c). Next step is repeating the same process for the rest of segments as t56 to t191. The final results are shown in Figure 1(d) including two hold trend segments (dotted line), one uptrend segment, and two downtrend segments (solid line) in this time series.Figure 1
An example for TBSM in time series data.


## 3. Support Vector Regressions (SVRs)

Support vector regression is a modification of machine-learning-theory-based classification called support vector machine. Machine learning techniques have been applied for assigning trading signal. Many studies used support vector machine for determining whether a case contains particular class [37, 38]. But the shortcoming only deal with discrete class labels, whereas trading signal continuum data type because a weight of signal can take a buy or sell power. Grounded in statistical learning theory [1, 2], support vector regression is capable to predict the continuous trading signal while still benefiting from the robustness of SVM. SVM has been successfully employed to solve forecasting problems in many fields, such as financial time series forecasting [39] and emotion computation [40]. For explaining the concept of SVR, we have considered a standard regression problem. Let S={Xi,Yi}i=1…n be the set of data where Xi is input vector (selected technical index in this research), Yi (trading signal ts) is an output vector, and n is the number of data points. In regression analysis, we find a function f(Xi) such that Yi=f(Xi). This function can be used to find the output value Y of any X. The standard regression function is as follows:
(3.1)qi=f(xi)+δ,
where δ denotes the random error and qi denotes the estimated output. There are two types of regression problems, namely, linear and nonlinear. SVR is developed to tackle the nonlinear regression problems because the nonlinear regression problems have high complexity as well as stock market trade. In SVR, at first the input vectors are nonlinearly mapped into a high-dimensional feature space (F), where they are linearly correlated with the respective output values.SVR uses the following linear estimation function:(3.2)f(x)=(ω⋅ϕ(x))+b,
where ω denotes the weight vector, b denotes a constant, ϕ(x)denotes the mapping function in the feature space, and (ω·ϕ(x))denotes the dot product in the feature space F.SVR transfers the nonlinear regression problem of the lower dimension input space (x) into a linear regression problem of a high-dimension feature space. In other words, the optimization problem involving a nonlinear regression is converted into finding the flattest function in the feature space instead of input space.Various cost functions like Laplacian, Huber’s Gaussian, andε-insensitive can be used in the formulation of SVR. The cost function should be suitable for the problem and should not be very complicated because a complicated cost function could lead to difficult optimization problems. Thus, we have used robust ε-sensitive cost function which is shown below:
(3.3)Lε(f(x),q)={|f(x)-q|-ε,if|f(x)-q|≥00,otherwise,
where ε denotes a precision parameter which represents the radius of the tube located around the regression functionf(x).The{+ε,-ε}region is called ε-insensitive zone. ε is determined by the user. If the actual output value lies in this region, the forecasting error is considered to be zero.The weight vector,ω, and constant, b, in (3.2) are calculated by minimizing regularized risk function which is shown in (3.4):
(3.4)R(C)=Cn∑i=1nLε(f(xi),qi)+12|ω|2,
where Lε(f(xi),qi) denotes the ε-insensitive loss function, |ω|2/2 denotes the regularization term, and C denotes the regularization constant. ω decides the complexity and approximate accuracy of the regression model. Value of C is selected by the user to ensure appropriate value of w and low empirical risk.The two positive slack variablesξiand ξi* are used to replace the ε-insensitive loss function of (3.3). ξi is defined as the distance between the qi and higher boundary of the ε-insensitive zone, and ξi* is defined as the distance between the qi and lower boundary of the ε-insensitive zone. Equation (3.4) is transformed into (3.5) by using the slack variables:
(3.5)Minimize:Rreg(f)=12|ω|2+C∑i=1n(ξi+ξi*)(3.6)Subjectto{qi-(ω⋅ϕ(xi))-b≤ε+ξi(ω⋅ϕ(xi))+b-qi≤ε+ξi*ξi,ξi*≥0,fori=1,…,n.
Lagrange function method is used to find the solution which minimizes the regression risk of (3.4) with the cost function in (3.3) which results in the following quadratic programming problem (QP):
(3.7)Minimize:12∑i=1N∑j=1N(αi-αi*)(αj-αj*)(ϕ(xi)⋅ϕ(xj))+∑i=1N(εiup-yi)αi+∑i=1N(εidown-yi)αi*,(3.8)Subjectto:∑i=1N(αi-αi*)=0,whereαi,αi*∈[0,C],
where αi and αi* denote Lagrange multipliers. εiup and εidown represent the ith up- and downmargin, respectively. The value of εiup and εidown is equal to ε. The QP problem of (3.7) is solved under the constraints of (3.8). After solving the QP problem, we obtained Lagrange multiplier from (3.9), and (3.2) is transformed into the following equation (3.10):
(3.9)ω=∑i=1N(αi-αi*)⋅ϕ(xi),(3.10)f(x)=(αi-αi*)(ϕ(xi)⋅ϕ(x))+b.
The Karush-Kuhn-Tucker (KKT) conditions are used to find the value of b. KKT conditions state that at the optimal solution, the product between the Lagrange multipliers and the constraints is equal to zero. The value of b can be calculated as follows:
(3.11)b={yi-(ω⋅ϕ(xi))-εiup,yi-(ω⋅ϕ(xi))+εidown,forαi∈(0,C),forαi*∈(0,C).
Using the trick of the kernel function, (3.10) can be written as (3.12):
(3.12)f(x)=∑i=1n(αi-αi*)K(x,xi)+b,
where K(x,xi)=(ϕ(x)·ϕ(xi)) denotes the kernel function which is symmetric and satisfies the Mercer’s condition. SVR was able to predict the nonlinear relationship between technical indices and trading signal ts better than other soft computing (SC) techniques.


## 4. Application in Financial Time Series Data

This paper proposes a forecasting framework using a TBSM combined with SVR model which is called TBSM-SVR trading model for stock trading. The framework of TBSM-SVR trading model has five stages: the first is generating nonlinear trading segments by TBSM approach from historical stock price; the second is trading signal transformation from trading segments; the third is feature selection from technical indices by SRA approach; the fourth is learning the trading forecasting model by SVRs approach. The framework of TBSM-SVR model is shown in Figure2. The five stages of TBSM-SVR model are explained as follows.Figure 2
The framework of TBSM-SVR model for stock trading.


### 4.1. Find Turning Points Based on Multiple Trend by TBSM

According to TBSM procedure to find turning point based on trend of stock price, we selected a time series of historical stock price in a period to segment into several segments based on three trends including uptrend, downtrend, and hold trend. For example, a time series is given to segment trend segments from the date 2008/1/2 to 2008/12/30. Figure3 shows the segmentation result by our proposed TBSM approach. The blue line is original historical stock price. The dashed lines are up/down trends which if the segment trend goes up is belonging to uptrend and if the segment trend goes down is belonging to downtrend. The dot line is belonging to hold trend. In our experiment, each stock price can split to multiple trend segments for trading signal transformation.Figure 3
An example of segmentation result by TBSM.


### 4.2. Trading Signal Transformation

In this stage, the aim is calculating the trading signal for a nonlinear time series of segmentation result which are a lot of segments based on trends. We suppose a segmentSk is uptrend; then we assume the real value into the vector Sk′ like to Sk=[0,0.1,…,1]; if Sk is hold trend but locates in buy point, then the vector like to Sk′=[0.5,0,0.5]; if Sk is hold trend but locates in sell point; then the vector like to Sk′ = [0.5, 1, 0.5]; if Sk is downtrend, then the vector Sk′ like to [1,0.9,…,0]. Finally we combine these Sk′to a full time series of trading signal ts. If the segment belongs to uptrend or downtrend, then the formula equation (4.1) is used to calculate trading signal value:
(4.1)Sk,i′={iLifSkisuptrendsegment,(L-i)LifSkisdowntrendsegment,
where L denotes the length of segment Sk, whereas segment belonging to hold trend is using (4.2) to calculation: (4.2)Sk,i′={1ifithishigherpointintimeseries,0ifithislowerpointintimeseries,0.5otherwise.
For example, the S1, and S3 are hold trend; the S1 is down-trend; the S4 is up-trend. The result of trading signal ts is shown in Figure 4. The red dotted line is the hold trend which is a special signal for increasing reflects on the original turning points, so the hold trend is not a horizontal line. The purple dotted line is downtrend signal, and the orange dotted line is uptrend signal. For example, in the time series T the T1 to T5 and T10 to T14 are hold trend signal representation, T6 to T9 is downtrend signal representation, and finally T15 to T18 is uptrend signal representation. Finally the trading signal ts which is like tots = {S1, S2, S3, S4} = {〈0.5,0.5,1,0.5,0.5〉, 〈1,0.66,0.333,0〉, 〈0.5,0.5,0,0.5,0.5〉, 〈0,0.33,0.66,1〉}. For the detail process see the pseudocode in Algorithm 2.Algorithm 2:A pseudocode for trend segments by TBSM in time series.
Input:length, oldTs // input data length and vector.Output:newTs // a new time series vector of trading signal.Method:1: Start = oldTs[1]2: End = oldTs[length]3: IfStart = = −1 and End = = 14:    newTs[1] = 05:    Fori = 1:length−16:     newTs[i+1] = 1/(lenghth−1)*i7:   End For8: Else If Start = = 1 and End = = −19:   newTs[length] = 010:   Fori = 1  : length−111:     newTs[i+1] = 1/(lenghth−1)*(length−i)12:   End For13: Else14:  For  i= 2  : length−115:   newTs[i] = 0.516:   End For17:  End IfFigure 4
A sample of trading signal.


### 4.3. Feature Selection for Technical Indices by SRA

In this paper, we have considered 28 variables (technical indices) as listed in Table1. These variables are correlated with variations in stock prices to some degree. The quantity of correlation varies for different variables. Rather than using all the 28 variables, we select the variables with a greater correlation than a user-defined threshold. The variable selection is done by stepwise regression analysis. We apply the SRA approach to determine which technical indices affecting the stock price. This is accomplished by selecting the variables repeatedly.Table 1
Technical indices used as input variables.
TechnicalTechnical indexExplanationMoving average (Ma)5 MA, 6 MA, 10 MA, 20 MAMoving averages are used to emphasize the direction of a trend and smooth out price and volume fluctuations that can confuse interpretation.Bias (BIAS)5 BIAS, 10 BIASThe difference between the closing value and moving average line, which uses the stock price nature of returning back to average price to analyze the stock market.Relative strength index (RSI)6 RSI, 12 RSIRSI compares the magnitude of recent gains to recent losses in an attempt to determine overbought and oversold conditions of an asset.Nine days stochastic line (K, D)9 K, 9 DThe stochastic line K and line D are used to determine the signals of overpurchasing, overselling, or deviation.Moving average convergence and divergence (MACD)9 MACDMACD shows the difference between a fast and slow exponential moving average (EMA) of closing prices. Fast means a short-period average, and slow means a long period one.Williams %R (pronounced “percent R")12 W%RWilliams %R is usually plotted using negative values. For the purpose of analysis and discussion, simply ignore the negative symbols. It is best to wait for the security’s price to change direction before placing your trades.Moving average convergence and divergence (MACD)9 MACDMACD shows the difference between a fast and slow exponential moving average (EMA) of closing prices. Fast means a short-period average, and slow means a long period one.Williams %R (pronounced “percent R")12 W%RWilliams %R is usually plotted using negative values. For the purpose of analysis and discussion, simply ignore the negative symbols. It is best to wait for the security’s price to change direction before placing your trades.Transaction volume (TV)5 TV, 10 TV, 15 TVTransaction volume is a basic yet very important element of market timing strategy. Volume provides clues as to the intensity of a given price move.Differences of technical index (Δ)Δ5 MA, Δ6 MA, Δ10 MA, Δ5 BIAS, Δ10 BIAS, Δ6 RSI, Δ12 RSI, Δ12 W%R, Δ9 K, Δ9 D, Δ9 MACDDifferences of technical index between the day and next day.In the feature selection part input factors will be further selected using stepwise regression analysis (SRA). The SRA has been applied to determine the set of independent variables which is most closely affecting the dependent variable. The SRA is step by step to select factor into regression model which if factor has the significance level, then it is selected. We can follow (4.4) to calculate the F value of SRA: (4.3)SSR=∑(Ŷ-Y̅)2,SSE=∑(Yî-Yi)2,(4.4)Fj*=MSR(xj∣xi)MSE(xj∣xi)=SSR(xj∣xi)SSE/(n-2)(xj∣xi)i∈I,
where SSR denotes a regression sum of square. SSE denotes residual sum of squares. x is the value of technical index. y is the value of stock price. n is the total number of training data. Ŷis the forecasting value of regression. Y̅is the average stock price of training data. After the feature selection by SRA, we can provide a set of features to form an input vector for the next step to learning the forecasting model.The steps of the SRA approach are described as follows.Step 1.
Find the correlation coefficientrfor each technical index v1,v2,…,vn with the stock price y in a stock. These correlation coefficients are stored in a matrix called correlation matrix.Step 2.
The technical index with largestR2 value is selected from the correlation matrix. Let the technical index be vi. Derive a regression model between the stock price and technical index, that is, ŷ=f(vi).Step 3.
Calculate the partialF value of other technical indices. Compare the R2 value of the remaining technical indices and select the technical index with the highest correlation coefficient. Let the technical index be vj. Derive another regression model, that is, ŷ=f(vi,vj).Step 4.
Calculate the partialF value of the original data for the technical index vj. If the F-value is smaller than the user-defined threshold, vj is removed from the regression model since it does not affect the stock price significantly.Step 5.
Repeat Step3 to Step 4. If the F-value of variable is more than the user-defined threshold, the variable should be added to the model, otherwise it should be removed.In addition, the range of the input variables of SVR model should be between 0 and 1. Hence, the selected technical indices are normalized as follows:(4.5)Normal(xij)=xij-Min⁡(xi)Max⁡(xi)-Min⁡(xi)i=1,…,n;j=1,…,m;n,m∈R,
where Normal(xij) denotes the normalized value of jth data point of ith technical index. Max(xi) denotes the maximum value of ith technical index. Min(xi) denotes the minimum value of ith technical index. xij denotes original value of jth data point of ith technical index. n and m denote the total number of technical indices and data points, respectively.


### 4.4. Learning the Trading Forecasting Model by SVR

Support vector regression will be applied as a machine learning model to extract the hidden knowledge in the historic stock database. The single output is the trading signalts from TSBM process, and the multiple input features are technical indices from SRA selection. SVR learning model transforms multiple features into high multidimensional feature space, and the transformed feature space can be mapped into a hyperplane space to determine correct signals based on those support vector points. On the kernel function selection, we try to use linear, RBF, polynomial, and sigmoid functions to generate better performance for the SVR model because the stock market is a very complicated nonlinear environment. Since the SVR approach possesses high learning capability and accuracy in predicting continuous signals for building hidden knowledge among trading signals and technical indices, it is a widely used tool for predicting the trading signals.


### 4.5. Trading Points Decision from Forecasted Trading Signal

In the daily forecasting, if the forecasted trading signals by SVR satisfied buy threshold, then this means it is needed to buy stock quickly because it is very close to turning point; otherwise if the state satisfied a sell threshold, then there is need to sell stock. These satisfied points are recommended to transaction in stock market. Before determining the trading point, we will calculate the buy/sell threshold values for two trading types. The trading thresholds of two types are as follows:(4.6)Buythreshold=μ+σ,Sellthreshold=1-μ+σ,μ=1N∑i=1Nxi′,σ=1N∑i=1N(xi′-μ),
where μdenotes the average of trading signal in training data. σ denotes the standard deviation of trading signal in training data. Buy_threshold denotes the buy trading threshold. Sell_threshold denotes the sell trading threshold. If forecasted trading signals form SVR model in testing data are more than buy_threshold, then this suggests trading point for buy stocks else if forecasting signal in testing data is smaller than sell_threshold, then this suggests trading for sell stock.In the trading decision step, the TBSM-SVR model is employed to calculate daily trading signals. The detailed principles for making trading decisions include the following.(1)
If the time series prediction of trading signals by TBSM-SVR model is going up and intersects with buy trading threshold Buy_threshold, then it is a “buy” trading decision.(2)
If the time series prediction of trading signals by TBSM-SVR model is going down and intersects with sell trading threshold sell_threshold, then it is a “sell” trading decision.(3)
A “hold” trading decision is made (or do not make any trading decision) when the forecasting trading signal does not intersect with buy and sell thresholds.For example, Figure5 shows trading points decision for Apple stock. How to suggest the buy/sell points for stock in a time series in which the red square points are buy points and green triangle points are the sell points? Both are satisfied two thresholds in which the orange dotted line is sell threshold and the purple dotted line is buy threshold, so we can forecast the trading points daily by an automatically trading system.Figure 5
An example of result for detecting trading points of Apple.


## 4.1. Find Turning Points Based on Multiple Trend by TBSM

According to TBSM procedure to find turning point based on trend of stock price, we selected a time series of historical stock price in a period to segment into several segments based on three trends including uptrend, downtrend, and hold trend. For example, a time series is given to segment trend segments from the date 2008/1/2 to 2008/12/30. Figure3 shows the segmentation result by our proposed TBSM approach. The blue line is original historical stock price. The dashed lines are up/down trends which if the segment trend goes up is belonging to uptrend and if the segment trend goes down is belonging to downtrend. The dot line is belonging to hold trend. In our experiment, each stock price can split to multiple trend segments for trading signal transformation.Figure 3
An example of segmentation result by TBSM.


## 4.2. Trading Signal Transformation

In this stage, the aim is calculating the trading signal for a nonlinear time series of segmentation result which are a lot of segments based on trends. We suppose a segmentSk is uptrend; then we assume the real value into the vector Sk′ like to Sk=[0,0.1,…,1]; if Sk is hold trend but locates in buy point, then the vector like to Sk′=[0.5,0,0.5]; if Sk is hold trend but locates in sell point; then the vector like to Sk′ = [0.5, 1, 0.5]; if Sk is downtrend, then the vector Sk′ like to [1,0.9,…,0]. Finally we combine these Sk′to a full time series of trading signal ts. If the segment belongs to uptrend or downtrend, then the formula equation (4.1) is used to calculate trading signal value:
(4.1)Sk,i′={iLifSkisuptrendsegment,(L-i)LifSkisdowntrendsegment,
where L denotes the length of segment Sk, whereas segment belonging to hold trend is using (4.2) to calculation: (4.2)Sk,i′={1ifithishigherpointintimeseries,0ifithislowerpointintimeseries,0.5otherwise.
For example, the S1, and S3 are hold trend; the S1 is down-trend; the S4 is up-trend. The result of trading signal ts is shown in Figure 4. The red dotted line is the hold trend which is a special signal for increasing reflects on the original turning points, so the hold trend is not a horizontal line. The purple dotted line is downtrend signal, and the orange dotted line is uptrend signal. For example, in the time series T the T1 to T5 and T10 to T14 are hold trend signal representation, T6 to T9 is downtrend signal representation, and finally T15 to T18 is uptrend signal representation. Finally the trading signal ts which is like tots = {S1, S2, S3, S4} = {〈0.5,0.5,1,0.5,0.5〉, 〈1,0.66,0.333,0〉, 〈0.5,0.5,0,0.5,0.5〉, 〈0,0.33,0.66,1〉}. For the detail process see the pseudocode in Algorithm 2.Algorithm 2:A pseudocode for trend segments by TBSM in time series.
Input:length, oldTs // input data length and vector.Output:newTs // a new time series vector of trading signal.Method:1: Start = oldTs[1]2: End = oldTs[length]3: IfStart = = −1 and End = = 14:    newTs[1] = 05:    Fori = 1:length−16:     newTs[i+1] = 1/(lenghth−1)*i7:   End For8: Else If Start = = 1 and End = = −19:   newTs[length] = 010:   Fori = 1  : length−111:     newTs[i+1] = 1/(lenghth−1)*(length−i)12:   End For13: Else14:  For  i= 2  : length−115:   newTs[i] = 0.516:   End For17:  End IfFigure 4
A sample of trading signal.


## 4.3. Feature Selection for Technical Indices by SRA

In this paper, we have considered 28 variables (technical indices) as listed in Table1. These variables are correlated with variations in stock prices to some degree. The quantity of correlation varies for different variables. Rather than using all the 28 variables, we select the variables with a greater correlation than a user-defined threshold. The variable selection is done by stepwise regression analysis. We apply the SRA approach to determine which technical indices affecting the stock price. This is accomplished by selecting the variables repeatedly.Table 1
Technical indices used as input variables.
TechnicalTechnical indexExplanationMoving average (Ma)5 MA, 6 MA, 10 MA, 20 MAMoving averages are used to emphasize the direction of a trend and smooth out price and volume fluctuations that can confuse interpretation.Bias (BIAS)5 BIAS, 10 BIASThe difference between the closing value and moving average line, which uses the stock price nature of returning back to average price to analyze the stock market.Relative strength index (RSI)6 RSI, 12 RSIRSI compares the magnitude of recent gains to recent losses in an attempt to determine overbought and oversold conditions of an asset.Nine days stochastic line (K, D)9 K, 9 DThe stochastic line K and line D are used to determine the signals of overpurchasing, overselling, or deviation.Moving average convergence and divergence (MACD)9 MACDMACD shows the difference between a fast and slow exponential moving average (EMA) of closing prices. Fast means a short-period average, and slow means a long period one.Williams %R (pronounced “percent R")12 W%RWilliams %R is usually plotted using negative values. For the purpose of analysis and discussion, simply ignore the negative symbols. It is best to wait for the security’s price to change direction before placing your trades.Moving average convergence and divergence (MACD)9 MACDMACD shows the difference between a fast and slow exponential moving average (EMA) of closing prices. Fast means a short-period average, and slow means a long period one.Williams %R (pronounced “percent R")12 W%RWilliams %R is usually plotted using negative values. For the purpose of analysis and discussion, simply ignore the negative symbols. It is best to wait for the security’s price to change direction before placing your trades.Transaction volume (TV)5 TV, 10 TV, 15 TVTransaction volume is a basic yet very important element of market timing strategy. Volume provides clues as to the intensity of a given price move.Differences of technical index (Δ)Δ5 MA, Δ6 MA, Δ10 MA, Δ5 BIAS, Δ10 BIAS, Δ6 RSI, Δ12 RSI, Δ12 W%R, Δ9 K, Δ9 D, Δ9 MACDDifferences of technical index between the day and next day.In the feature selection part input factors will be further selected using stepwise regression analysis (SRA). The SRA has been applied to determine the set of independent variables which is most closely affecting the dependent variable. The SRA is step by step to select factor into regression model which if factor has the significance level, then it is selected. We can follow (4.4) to calculate the F value of SRA: (4.3)SSR=∑(Ŷ-Y̅)2,SSE=∑(Yî-Yi)2,(4.4)Fj*=MSR(xj∣xi)MSE(xj∣xi)=SSR(xj∣xi)SSE/(n-2)(xj∣xi)i∈I,
where SSR denotes a regression sum of square. SSE denotes residual sum of squares. x is the value of technical index. y is the value of stock price. n is the total number of training data. Ŷis the forecasting value of regression. Y̅is the average stock price of training data. After the feature selection by SRA, we can provide a set of features to form an input vector for the next step to learning the forecasting model.The steps of the SRA approach are described as follows.Step 1.
Find the correlation coefficientrfor each technical index v1,v2,…,vn with the stock price y in a stock. These correlation coefficients are stored in a matrix called correlation matrix.Step 2.
The technical index with largestR2 value is selected from the correlation matrix. Let the technical index be vi. Derive a regression model between the stock price and technical index, that is, ŷ=f(vi).Step 3.
Calculate the partialF value of other technical indices. Compare the R2 value of the remaining technical indices and select the technical index with the highest correlation coefficient. Let the technical index be vj. Derive another regression model, that is, ŷ=f(vi,vj).Step 4.
Calculate the partialF value of the original data for the technical index vj. If the F-value is smaller than the user-defined threshold, vj is removed from the regression model since it does not affect the stock price significantly.Step 5.
Repeat Step3 to Step 4. If the F-value of variable is more than the user-defined threshold, the variable should be added to the model, otherwise it should be removed.In addition, the range of the input variables of SVR model should be between 0 and 1. Hence, the selected technical indices are normalized as follows:(4.5)Normal(xij)=xij-Min⁡(xi)Max⁡(xi)-Min⁡(xi)i=1,…,n;j=1,…,m;n,m∈R,
where Normal(xij) denotes the normalized value of jth data point of ith technical index. Max(xi) denotes the maximum value of ith technical index. Min(xi) denotes the minimum value of ith technical index. xij denotes original value of jth data point of ith technical index. n and m denote the total number of technical indices and data points, respectively.


## 4.4. Learning the Trading Forecasting Model by SVR

Support vector regression will be applied as a machine learning model to extract the hidden knowledge in the historic stock database. The single output is the trading signalts from TSBM process, and the multiple input features are technical indices from SRA selection. SVR learning model transforms multiple features into high multidimensional feature space, and the transformed feature space can be mapped into a hyperplane space to determine correct signals based on those support vector points. On the kernel function selection, we try to use linear, RBF, polynomial, and sigmoid functions to generate better performance for the SVR model because the stock market is a very complicated nonlinear environment. Since the SVR approach possesses high learning capability and accuracy in predicting continuous signals for building hidden knowledge among trading signals and technical indices, it is a widely used tool for predicting the trading signals.


## 4.5. Trading Points Decision from Forecasted Trading Signal

In the daily forecasting, if the forecasted trading signals by SVR satisfied buy threshold, then this means it is needed to buy stock quickly because it is very close to turning point; otherwise if the state satisfied a sell threshold, then there is need to sell stock. These satisfied points are recommended to transaction in stock market. Before determining the trading point, we will calculate the buy/sell threshold values for two trading types. The trading thresholds of two types are as follows:(4.6)Buythreshold=μ+σ,Sellthreshold=1-μ+σ,μ=1N∑i=1Nxi′,σ=1N∑i=1N(xi′-μ),
where μdenotes the average of trading signal in training data. σ denotes the standard deviation of trading signal in training data. Buy_threshold denotes the buy trading threshold. Sell_threshold denotes the sell trading threshold. If forecasted trading signals form SVR model in testing data are more than buy_threshold, then this suggests trading point for buy stocks else if forecasting signal in testing data is smaller than sell_threshold, then this suggests trading for sell stock.In the trading decision step, the TBSM-SVR model is employed to calculate daily trading signals. The detailed principles for making trading decisions include the following.(1)
If the time series prediction of trading signals by TBSM-SVR model is going up and intersects with buy trading threshold Buy_threshold, then it is a “buy” trading decision.(2)
If the time series prediction of trading signals by TBSM-SVR model is going down and intersects with sell trading threshold sell_threshold, then it is a “sell” trading decision.(3)
A “hold” trading decision is made (or do not make any trading decision) when the forecasting trading signal does not intersect with buy and sell thresholds.For example, Figure5 shows trading points decision for Apple stock. How to suggest the buy/sell points for stock in a time series in which the red square points are buy points and green triangle points are the sell points? Both are satisfied two thresholds in which the orange dotted line is sell threshold and the purple dotted line is buy threshold, so we can forecast the trading points daily by an automatically trading system.Figure 5
An example of result for detecting trading points of Apple.


## 5.  Experimental Results

### 5.1. Profit Evaluation and Parameters Setting

In this research, the trading point (buy and sell timing) is decided by the TBSM-SVR model based on the forecasting trading signal of SVR and TBSM segmentation. In the experimental section, we also use various forecasting models to the generated profiting trading points and compare their performances. The profits in each different forecasting model are calculated as follows:(5.1)profits=C∏i=1k{(1-a-b)×pSi-(1+a)×pBi(1+a)×pBi},
where C is the total amount of money to be invested at the beginning as well as the capital of money, a refers to the tax rate of ith transaction, b refers to the handling charge of ith transaction, k is the total number of transaction, pSi is the selling price of the ith transaction and pBi is the buying price of ith transaction.This study uses minimal root mean square error (RMSE) to measure the model performance in SVR train stage. In the model selection strategy that the dataset uses the last one trading period of training data contains (buy/sell and sell/buy states). The RMSE of an estimatortŝ with respect to the estimated parameter ts is defined as the square root of the mean square error:
(5.2)RMSE=∑i=1ntsi-tsîN.ts denotes the trading signal by trading signal transformation from TBSM segmentation in Section 4.2. tŝdenotes the estimated trading signal by SVR forecasting model. N denotes total number in each training data (Table 2).Table 2
The parameter setup for TBSM and SVR by DOEs (design of experiments).
ApproachParameterValueExplanationTBSMThreshold0.1σ to 1σThe difference of price at uptrend or downtrendTBSMX_Thld0.1σ to 1σThe difference of days at hold trendTBSMY_Thld0.1σ to 1σThe difference of price at hold trendSVRC10-3 to 103CostSVRε10-4 to 10-1EpsilonSVRd2-9 to 2-1DegreeSVRg21 to 24GammaIn parameter section we use design of experiments (DOEs) approach to set each parameter for capture optimal parameter combination for trading system in financial data. The parameters of the TBSM are based on standard deviationσfrom stock price in each stock which is the range from 0.1σ to 1σ for testing in each parameters. In SVR model, the kernels chosen for testing are “radial basis function (RBF)” and “polynomial” function. The common combination includes cost C; epsilon εandγ are selected by the grid search with exponentially growing sequences. C ranges from 10-3 to 103. ε from 10-4 to 10-1 and γ is fixed as 0. In “polynomial” function, the degree d ranges from2-9 to 2-1. The gamma g ranges from 21 to 24 in RBF kernel.


### 5.2. Profit Comparison in the US Stock Market

In this research, we have selected 7 stocks from the US stock market to compare the profit achieved by various trading models, including Apple, BOENING CO. (BA), Caterpillar Inc. (CAT), Johnson and Johnson (JNJ), Exxon Mobil Corp. (XOM), Verizon Communication Inc. (VZ), and S&P 500. Among all the stocks, 253 data points were collected for the training period from 1/2/2008 (mm/dd/yy) to 12/31/2008 while 124 data points were used for the testing period from 1/2/2009 to 6/30/2009. In this research, we have compared our forecasting model of TBMS-SVR approach with two other identification models developed in the past. The PLR-BPN model proposed by Chang et al. [26] used neural networks in combination with PLR and exponential smoothing to determine the trading points. Kwon and Kish [41] used statistical model such as moving average, rate of change and trading volumes to determine the buy-sell points and generated profit.The technical indices selected result by SRA as shown in Table3. Apple, Ba, CAT, JNJ, S&P 500, and VZ used 5 features (technical indices) for training forecasting model; XOM used 3 features for training forecasting model. From this result we can know that a few features can capture more trading knowledge.Table 3
Feature selection result in each stock for technical indices by SRA.
StockTechnical indexApple5 MA, 6 MA, 9 K, 9 MACD, 12 W%RBA5 MA, 6 MA, 9 K, 10 TV, 12 W%RCAT5 MA, 6 MA, 9 K, 10 TV,Δ5 MAJNJ5 MA, 6 MA, 6 RSI, 9 MACD,Δ5 MAS&P 5005 MA, 5 BIAS, 10 TV, 26 BR, TAPIVZ5 MA, 6 MA,Δ5 MA, 10 TV, 26 VRXOM5 MA,6 MA,Δ5 MAFrom model selection results the RBF kernel has better low error in each stock by RMSE. Moreover, the gamma, degree, cost, epsilon, support vectors, and RMSE as shown in Table4 are necessary parameters and measures. The models of TBSM-SVR in each stock are selecting optimal parameter combination by RMSE consideration.Table 4
Model selection results from TSBM-SVR model for each stock.
StockKernelRadial basis function (RBF)PolynomialgCεSVsRMSEdCεSVsRMSEApple2−110310−42530.08192[0.001 : 1000][0.0001 : 0.1]710.266BA2−110310−11070.09552[0.001 : 1000][0.0001 : 0.1]760.269CAT2−110310−32540.08982[0.001 : 1000][0.0001 : 0.1]1560.233JNJ2−110210−11370.26171[0.001 : 1000][0.0001 : 0.1]1160.426S&P 5002−110310−42540.00041[0.001 : 1000][0.0001 : 0.1]1120.379VZ2−110310−32510.00311[0.001 : 1000][0.0001 : 0.1]1250.269XOM2−110310−42530.00012[0.001 : 1000][0.0001 : 0.1]1820.18Each forecasting model provides trading points for each stock, so the best profits of the 3 forecasting models are shown in Table5. The results turn out that our proposed TBSM with SVR model generates the greatest returns for the seven stocks, that is, number 1, 2, 3, 4, 5, 6, and 7 outperform other models. The average profit rate of these seven stocks is 40.42% using the TBSM-SVR model whereas the average profit rate generated by other models like PLR-SVR, PLR-BPN, and Statistical is 19.46%, 12.32%, and 9.65%, respectively. Therefore, our TBSM approach is better than PLR approach which is only considered linear representation.Table 5
Comparison of profit obtained by various forecasting models.
Stock no.Stock nameTBSN-SVR model (RBF)PLR-SVR model (RBF)PLR-BPN modelStatistical model1Apple92.35%35.84%12.97%20.50%2BA59.49%35.69%17.50%20.03%3CAT43.39%36.09%9.36%24.83%4JNJ13.95%9.47%16.88%0%5S&P 50022.78%4.19%3.77%9.81%6VZ28.60%2.60%27.72%0%7XOM22.40%12.34%−1.99%−7.65%Average40.42%19.46%12.32%9.65%The buy and sell points obtained from the TBSM forecasting model in each stock are shown in Figures6, 7, 8, 9, 10, 11, and 12. The red square represents the buy point, and the black triangle represents the sell point using a trading strategy to determine turning points. Furthermore, our proposed approach TBSM is better than PLR segmentation which denotes that TBSM approach captures better trading knowledge for SVR forecasting model. Due to PLR only the linear representation is considering, so it loses important trend. Therefore, TBSM is an effective segmentation method for nonlinear time series data in stock market.Figure 6
The forecasted trading points of Apple (an uptrend stock).Figure 7
The forecasted trading points of BA (a steady-trend stock).Figure 8
The forecasted trading points of CAT (a downtrend stock).Figure 9
The forecasted trading points of JNJ (a steady-trend stock).Figure 10
The forecasted trading points of S&P 500 (a steady-trend stock).Figure 11
The forecasted trading points of VZ (a downtrend stock).Figure 12
The forecasted trading points of XOM (a downtrend stock).


## 5.1. Profit Evaluation and Parameters Setting

In this research, the trading point (buy and sell timing) is decided by the TBSM-SVR model based on the forecasting trading signal of SVR and TBSM segmentation. In the experimental section, we also use various forecasting models to the generated profiting trading points and compare their performances. The profits in each different forecasting model are calculated as follows:(5.1)profits=C∏i=1k{(1-a-b)×pSi-(1+a)×pBi(1+a)×pBi},
where C is the total amount of money to be invested at the beginning as well as the capital of money, a refers to the tax rate of ith transaction, b refers to the handling charge of ith transaction, k is the total number of transaction, pSi is the selling price of the ith transaction and pBi is the buying price of ith transaction.This study uses minimal root mean square error (RMSE) to measure the model performance in SVR train stage. In the model selection strategy that the dataset uses the last one trading period of training data contains (buy/sell and sell/buy states). The RMSE of an estimatortŝ with respect to the estimated parameter ts is defined as the square root of the mean square error:
(5.2)RMSE=∑i=1ntsi-tsîN.ts denotes the trading signal by trading signal transformation from TBSM segmentation in Section 4.2. tŝdenotes the estimated trading signal by SVR forecasting model. N denotes total number in each training data (Table 2).Table 2
The parameter setup for TBSM and SVR by DOEs (design of experiments).
ApproachParameterValueExplanationTBSMThreshold0.1σ to 1σThe difference of price at uptrend or downtrendTBSMX_Thld0.1σ to 1σThe difference of days at hold trendTBSMY_Thld0.1σ to 1σThe difference of price at hold trendSVRC10-3 to 103CostSVRε10-4 to 10-1EpsilonSVRd2-9 to 2-1DegreeSVRg21 to 24GammaIn parameter section we use design of experiments (DOEs) approach to set each parameter for capture optimal parameter combination for trading system in financial data. The parameters of the TBSM are based on standard deviationσfrom stock price in each stock which is the range from 0.1σ to 1σ for testing in each parameters. In SVR model, the kernels chosen for testing are “radial basis function (RBF)” and “polynomial” function. The common combination includes cost C; epsilon εandγ are selected by the grid search with exponentially growing sequences. C ranges from 10-3 to 103. ε from 10-4 to 10-1 and γ is fixed as 0. In “polynomial” function, the degree d ranges from2-9 to 2-1. The gamma g ranges from 21 to 24 in RBF kernel.


## 5.2. Profit Comparison in the US Stock Market

In this research, we have selected 7 stocks from the US stock market to compare the profit achieved by various trading models, including Apple, BOENING CO. (BA), Caterpillar Inc. (CAT), Johnson and Johnson (JNJ), Exxon Mobil Corp. (XOM), Verizon Communication Inc. (VZ), and S&P 500. Among all the stocks, 253 data points were collected for the training period from 1/2/2008 (mm/dd/yy) to 12/31/2008 while 124 data points were used for the testing period from 1/2/2009 to 6/30/2009. In this research, we have compared our forecasting model of TBMS-SVR approach with two other identification models developed in the past. The PLR-BPN model proposed by Chang et al. [26] used neural networks in combination with PLR and exponential smoothing to determine the trading points. Kwon and Kish [41] used statistical model such as moving average, rate of change and trading volumes to determine the buy-sell points and generated profit.The technical indices selected result by SRA as shown in Table3. Apple, Ba, CAT, JNJ, S&P 500, and VZ used 5 features (technical indices) for training forecasting model; XOM used 3 features for training forecasting model. From this result we can know that a few features can capture more trading knowledge.Table 3
Feature selection result in each stock for technical indices by SRA.
StockTechnical indexApple5 MA, 6 MA, 9 K, 9 MACD, 12 W%RBA5 MA, 6 MA, 9 K, 10 TV, 12 W%RCAT5 MA, 6 MA, 9 K, 10 TV,Δ5 MAJNJ5 MA, 6 MA, 6 RSI, 9 MACD,Δ5 MAS&P 5005 MA, 5 BIAS, 10 TV, 26 BR, TAPIVZ5 MA, 6 MA,Δ5 MA, 10 TV, 26 VRXOM5 MA,6 MA,Δ5 MAFrom model selection results the RBF kernel has better low error in each stock by RMSE. Moreover, the gamma, degree, cost, epsilon, support vectors, and RMSE as shown in Table4 are necessary parameters and measures. The models of TBSM-SVR in each stock are selecting optimal parameter combination by RMSE consideration.Table 4
Model selection results from TSBM-SVR model for each stock.
StockKernelRadial basis function (RBF)PolynomialgCεSVsRMSEdCεSVsRMSEApple2−110310−42530.08192[0.001 : 1000][0.0001 : 0.1]710.266BA2−110310−11070.09552[0.001 : 1000][0.0001 : 0.1]760.269CAT2−110310−32540.08982[0.001 : 1000][0.0001 : 0.1]1560.233JNJ2−110210−11370.26171[0.001 : 1000][0.0001 : 0.1]1160.426S&P 5002−110310−42540.00041[0.001 : 1000][0.0001 : 0.1]1120.379VZ2−110310−32510.00311[0.001 : 1000][0.0001 : 0.1]1250.269XOM2−110310−42530.00012[0.001 : 1000][0.0001 : 0.1]1820.18Each forecasting model provides trading points for each stock, so the best profits of the 3 forecasting models are shown in Table5. The results turn out that our proposed TBSM with SVR model generates the greatest returns for the seven stocks, that is, number 1, 2, 3, 4, 5, 6, and 7 outperform other models. The average profit rate of these seven stocks is 40.42% using the TBSM-SVR model whereas the average profit rate generated by other models like PLR-SVR, PLR-BPN, and Statistical is 19.46%, 12.32%, and 9.65%, respectively. Therefore, our TBSM approach is better than PLR approach which is only considered linear representation.Table 5
Comparison of profit obtained by various forecasting models.
Stock no.Stock nameTBSN-SVR model (RBF)PLR-SVR model (RBF)PLR-BPN modelStatistical model1Apple92.35%35.84%12.97%20.50%2BA59.49%35.69%17.50%20.03%3CAT43.39%36.09%9.36%24.83%4JNJ13.95%9.47%16.88%0%5S&P 50022.78%4.19%3.77%9.81%6VZ28.60%2.60%27.72%0%7XOM22.40%12.34%−1.99%−7.65%Average40.42%19.46%12.32%9.65%The buy and sell points obtained from the TBSM forecasting model in each stock are shown in Figures6, 7, 8, 9, 10, 11, and 12. The red square represents the buy point, and the black triangle represents the sell point using a trading strategy to determine turning points. Furthermore, our proposed approach TBSM is better than PLR segmentation which denotes that TBSM approach captures better trading knowledge for SVR forecasting model. Due to PLR only the linear representation is considering, so it loses important trend. Therefore, TBSM is an effective segmentation method for nonlinear time series data in stock market.Figure 6
The forecasted trading points of Apple (an uptrend stock).Figure 7
The forecasted trading points of BA (a steady-trend stock).Figure 8
The forecasted trading points of CAT (a downtrend stock).Figure 9
The forecasted trading points of JNJ (a steady-trend stock).Figure 10
The forecasted trading points of S&P 500 (a steady-trend stock).Figure 11
The forecasted trading points of VZ (a downtrend stock).Figure 12
The forecasted trading points of XOM (a downtrend stock).


## 6. Conclusions

In this paper we proposed a trading system combining TBSM with SVR, and it is called TBSM-SVR-based stock trading system. This new trading system has been very effective in earning high profit while with the greatest ability. Experimental results showed that the TSBM can segment the stock price’s variation into different trading trends. The trading signal in each trading trend will be assumed to be the same. The nonlinear time series can be better represented using these trading trends. Additionally, SVR is applied to capture the trading knowledge using the trading signals derived from these trading trends. The captured knowledge is more effective using TBSM-SVR when compared to PLR segmentation method. As a result, the primary goal of the investor could be easily achieved by providing him with simple trading decisions. However, the limitation of the TBSM-SVR trading system is the machine learning tool; that is, SVR is still not that mature yet. There are still rooms for the improvement of a better machine learning mechanism to be developed. Therefore, the trading system may make a wrong trading and lose money. In the future works, we can extend the segmentation method by considering a more detailed trend by investigating different buy-hold strategy or better trading strategy. In addition, the trend based segmentation method can further consider the fractal properties such as long memory, which can be accommodated to improve the segmentation performances.



---

*Source: 615152-2012-05-29.xml*