Effective Application of Improved Profit-Mining Algorithm for the Interday Trading Model

Many real world applications of association rule mining from large databases help users make better decisions. However, they do not work well in financial markets at this time. In addition to a high profit, an investor also looks for a low risk trading with a better rate of winning. The traditional approach of using minimum confidence and support thresholds needs to be changed. Based on an interday model of trading, we proposed effective profit-mining algorithms which provide investors with profit rules including information about profit, risk, and winning rate. Since profit-mining in the financial market is still in its infant stage, it is important to detail the inner working of mining algorithms and illustrate the best way to apply them. In this paper we go into details of our improved profit-mining algorithm and showcase effective applications with experiments using real world trading data. The results show that our approach is practical and effective with good performance for various datasets.


Introduction
Data mining of Association Rules (AR) comes from knowledge discovery in large databases [1]. Using the application of AR on the stock market as an example, one can benefit from the rule: when the price of one stock goes up, the price of another stock goes up with 70% confidence at the same day. However, this rule cannot depict the information of when to buy or when to sell a stock. This form of AR only presents a fact that the prices of both stocks go up together. The investors do not know when to buy or when to sell the stock. To solve this problem in the financial market, Lu et al. [2] proposed the intertransaction mining (ITM) of association rules.
The ITM is very popular for investors to find rules like "when the price of one stock goes up, then the price of another stock will go up the next day with 70% of confidence. " This rule indicates that one may win 7 out of 10 times. With ITM we still cannot be sure to have a profit as illustrated in the next example. Assume that an investor gets 1 dollar for each win and loses 3 dollars otherwise. Based on a simple calculation, we get a loss of 2 dollars from 10 trades, which is 7 × 1 − 3 × 3 = −2 dollars. This example amplifies the point that high confidence does not necessarily mean high profit.
In the investment market, although every trader wants to make a profit, taking a loss is almost inevitable and becomes a risk. In particular in the futures market, the main purpose is to allow those who wish to manage price risk to transfer that risk to those who are willing to take that risk in return for an opportunity to profit. In addition to the profit and risk, what are concerned by investors the most? For example, if two trading results have the same profit and risk with two different winning chances of 1% and 99%, then the investor would prefer the latter over the former. Most investors have low psychological endurance to bad performance of their stocks and prefer the trading with a higher winning chance. Here the winning chance is called WinRate. Therefore, the combination of high profit, low risk, and high WinRate becomes the choice of the most investors.
Profit-mining (PM) [3] is such an alternative solution to ITM that better meets the requirements of investors in financial market. PM considers more of investor's expectation on mined results which include profit, risk, and WinRate. 2 The Scientific World Journal The resultant profit rule has the form "Buy stock when an event (or a signal) occurs and sell stock when an event (or a signal) occurs; then you have profit = , risk = , and WinRate = %. " The concept of PM is similar to utility mining from [4]. However, Chan et al. use a sales manager's perspective to mine profitable result that is important to the customer. Traditional statistical correlations may not measure how useful an itemset is in accordance with customer preferences. Although utility mining solves the problem from a sales manager's perspective, the concerns from customers in financial market have not been addressed. PM can be used to solve the problem. The utility mining uses a fixed weight to compute the profit while PM uses a dynamic approach depending on two trading orders. PM can find trading rules and trading results based on the trading model and investor's expectations. To find the profitable rules more efficiently, we improve our PRMiner algorithm [5] and illustrate its usage with real world applications in this paper.
The rest of the paper is organized as follows. Section 2 presents the related work and Section 3 introduces problem definitions and reviews our research approach. The improved PRMiner algorithm, profit rule mining examples, and real world applications are described in Section 4 while Section 5 discusses experimental results. Section 6 concludes the paper and describes our future study.

Related Work
Agrawal et al. [1] proposed the association rule mining for finding the rule of related itemsets with high frequency and confidence from transactional databases. Lu et al. [2] presented the intertransaction association rules mining to predict if some stock prices will go up or down based on the previous performance of other stocks. Chan et al. [4] developed an objective-directed utility mining to find the top-K high utility closed patterns supporting a given business objective. Su and Huang [6] used model free estimators to predict the price of stock. Magdon-Ismail and Atiya [7] presented their research on risk management in financial market, which is critical for investors. Zhang and Zhou [8] revealed the fact that "data mining in finance is involved with the features of data, target applications, and domain models leading to a conceptual framework consisting of these three dimensions. " Boetticher et al. [9] performed several studies to mine the financial data in which the result is presented with profit but lacks risk information. Hsieh et al. [10] used the ITM to mine stock data and to study upstream and downstream causal relationship in stock market. In real world applications, Trade Station [11] can be used to build program models that can perform trading simulation. Based on the simulation, Trade Station generates reports to show the expected profit, risk, and other trading results. Recently, Bodas-Sagi et al. [12] proposed an evolutionary approach to optimize the parameters of two important technical indicators (RSI and MACD) by considering the objectives of maximal profit and minimal risk. However, Hsieh and Yang [3] had already applied a profit-mining model to solve the problem using all three factors of profit, risk, and winning rate (i.e., WinRate). In this paper we make further improvements on the profitmining algorithm PRMiner and its implementation [5]. Practical applications and experiments are used to show how well our improved algorithm can work on real world trading data.

Problem Definitions and Our Research Approach
In this section we describe the interday trading model [5], transactional database (TDB), trading rules, trading results, and profit rules. Using trading rules we can simulate trading in the interday model for the target TDB and generate trading results with profit, risk, and WinRate. The rules meeting users' expectation are profit rules.

Interday Trading Model.
We define TC as a set of trading commands consisting of Buy and Sell. Let TO = {tc, qty, price} denote the form of a Trading Order where ∈ , ∈ + , and ∈ + . With no loss of generality, we set the value of qty to 1. We say that a TO is either a Buy-Order (BO) if tc = "Buy" or a Sell-Order (SO) if tc = "Sell." Let MP be a set of market positions containing None, Long, and Short. We use {mp, hqty, hprice} to denote the form of a position POS where ∈ , ℎ ∈ {0, 1}, and ℎprice ∈ + . We say that a POS is in a close position if mp = "None, " hqty = 0, and hprice = 0. Otherwise, a POS is either in a long position if mp = "Long" or in a short position if mp = "Short." In addition, let HPOS denote a hold position representing a position of an investor in hold before or after trading. Here HPOS is also a kind of POS. Therefore, the HPOS 0 at time = 0 is in a close position {None, 0, 0}. A close position means that an investor does not hold any stock. Therefore, it does not matter whether stock prices will go up or down. A long position means that an investor expects future stock prices to go up for a chance to make profit. On the other hand, a short position means that an investor expects to make profit in the future if the stock price goes down.
We use a state machine in Figure 1 to explain the interday trading model [5] with three hold positions: close, long, and short. In Figure 1, a Buy-Order (BO) is generated when a Buy-Pattern (BP) appears in the transaction database (TDB) and a Sell-Order (SO) is generated when a Sell-Pattern (SP) occurs. The BP and SP are patterns to be mined. A Buy-Order or Sell-Order is used to change the status of a hold position (HPOS) at the beginning to other positions in Figure 1. At time t, a BO t or SO t is generated to change a hold position from HPOS −1 to HPOS . The action "change" is also called an offset. We define an operator "−" to indicate the operation of an offset. Thus, the operator "−" uses TO to offset a hold position from HPOS −1 to HPOS . The definition of the operator "−" among HPOS −1 , TO , and HPOS is as follows: (1) At time t, if there exists a trading order TO that changes HPOS −1 to HPOS , then we call its previous trading order TO −1 a complete trading order (CTO). For example, the investor holds a close position HPOS 0 = {None, 0, 0} as shown in top of Figure 1. When a BP occurs in the TDB at time t = 1 and a BO 1 = {Buy, 1, bprice 1 } is generated, it changes HPOS 0 to HPOS 1 by following the arrowhead line from "Close Position" to "Long Position. " HPOS 1 = BO 1 −HPOS 0 = {Buy, 1, bprice 1 } − {None, 0, 0} = {Long, 1, bprice 1 }. Then the state does not change until a SP occurs in the TDB. DoNothing[BP] in Figure 1 means that no action will take place when a BP appears.
Assume that a Sell-Pattern SP occurs at time t = 2 and a Sell-Order SO 2 = {Sell, 1, sprice 2 } is generated to offset HPOS 1 to become HPOS 2 by following the arrowhead line from "Long Position" to "Short Position. " HPOS 2 = SO 2 − HPOS 1 = {Sell, 1, sprice 2 } − {Long, 1, bprice 1 } = {Short, 1, sprice 2 }. Then, BO 1 is a complete trading order (CTO) because SO 2 changes the state from HPOS 1 to HPOS 2 . The remaining two offset cases from "Close Position" to "Short Position" and from "Short Position" to "Long Position" can be derived in a similar manner.

Transactional Databases. Let
items. An item represents an event or a trading signal. Let TDB be a transactional database which contains a set of transactions {tr 1 , tr 2 , . . . , tr }. Let (TID j , ItemSet j , Price j ) denote the form of a transaction tr j where TID j is a consecutive number and TID j > 0, ItemSet j contains a set of items and ItemSet j ∈ E, and Price j ∈ R + . Table 1 shows an example of TDB with three attributes TID, ItemSet, and Price as in [5]. For simplification, we ignore mega-transactions without itemset in their base transaction. TID is a transaction ID possessing the time feature to establish the trading sequence and identify the set of items and  trading result in the fields of ItemSet and Price, respectively. The investors use various techniques and information to determine the best time to buy or sell stocks, leading to produce trading signals which are recorded in the database as itemsets. In Table 1, there are ten such transactions.
The definition of a pattern in PM is similar to that of ITM. Let a pattern be a set of items (or an itemset) in the form of an opposite direction from the moving direction of sliding windows.
For example, assuming that maxspan = 2 in Table 1, there are six megatransactions 1, 2, . . . , 6. The megatransaction M1 contains two transactions with TID = 1 and TID = 2, 2 contains two transactions with TID = 2 and TID = 3, and so forth. The megatransaction 2 has five patterns a (0) The third pattern a(0)c(−1) implies that a(0) and c(−1) are in the same megatransaction 2. The same pattern occurs in the megatransaction 5 as well. The number of −1 in the parenthesis of c(−1) indicates that item is in the first extended transaction of TID 2 above the base transaction of TID 3. Since the pattern a(0)c(−1) occurs at TID 3, the trading price 500 of pattern a(0)c(−1) is set at the base transaction of TID 3, not at TID 2.
3.3. Trading Rules. As described in our trading model of Figure 1, we use BP and SP patterns to determine the trading orders of Buy and Sell, respectively. If BP and SP occur at the same time causing a semantic ambiguity, an investor does not know what trading action (Buy or Sell) to take. A new attribute of trading -priority (TP) is required to solve the problem. Now we can define the format of a trading rule as { , , } where TP ∈ {BF, SF}, "BF" stands for Buy-First, and "SF" stands for Sell-First. When a semantic ambiguity situation occurs at a market position MP = "None, " if TP = BF, then the generated trading order is a Buy-Order (BO). If TP = SF, the generated trading order is a Sell-Order (SO). For example, given a trading rule {SF, a(0), b(0)} with stock , the trading priority SF tells the investor to sell the stock when = a(0) and = b(0) occur simultaneously at a close position (i.e., MP = "None"). Then the investor can buy the stock when = a(0) occurs again. If = a(0) and = b(0) do not occur simultaneously, buy the stock when = a(0) occurs and sell the stock when = (0) occurs.

Trading Results.
Trading results are generated by using trading rules in a trading simulation. Our trading result includes Profit, Risk, and WinRate. In real world practice, each trading in a trading simulation must pay some trading fee and tax. In our trading model one must specify the handling fee for each trading to cover the fee and tax as paid in real world.

Profit. Let
Begin and End be two TIDs of the first and last transactions in a TDB, respectively. is a function to get the price at a specific TID, denoted as (TID). Equations (3) and (4) are used to compute the net profit (NP) of a trading rule. Consider the following: The net profit of a trading rule is to summarize all NPs. Consider the following: To better explain the net profit calculation, we use a stock price versus trading time curve in Figure 2 [5] based on the TDB in Table 1. The -axis is trading time and the -axis is stock price. We start from Begin , where HPOS 0 = close position. The first pattern in Figure 2 is a BP which appears at transaction T 1 and a Buy-Order BO 1 = {Buy, 1, ( 1 )} is generated to offset HPOS 0 to HPOS 1 . The calculation is At the 1 point, the investor holds a long position HPOS 1 = {Long, 1, ( 1 )} expecting a profit or a loss if the price of stock goes up or down in the future, respectively. The second pattern SP occurs at the 2 point and SO 2 = {Sell, 1, ( 2 )} is generated to offset HPOS 1 to HPOS 2 . The calculation is At the 2 point, the investor holds a short position = {Short, 1, ( 2 )} expecting a profit or a loss if the price of stock goes down or up in the future, respectively. The 3rd pattern BP occurs at the 3 point and BO 3 = {Buy, 1, ( 3 )} is generated to offset HPOS 2 to HPOS 3 = {Long, 1, ( 3 )}. We have the second net profit NP 2 = ( 2 ) − ( 3 ) − 2 × fee because the value of MP 2 is "Short. " Since the 3 point is next to the end, there is no trading pattern to expect. The profit of the trading rule is NP 1 + NP 2 .  where Loss 0 = 0,

Risk. We use the three variables Consecutive Loss
DD and RU are used to record the risk during the trading process when MP is "Long" and "Short," respectively. Let and be two TIDs where < . Let min ( , ) and max ( , ) be two functions for getting the minimal and maximal prices, respectively, from to , where < and , ∈ TID. We use Figure 3 to show the calculation of DD and RU. DD records the difference between the buying price and the lowest price where the difference must be less than 0; otherwise DD = 0. The location of the lowest price is between the buying point and the next selling point or between the buying point and End . Two examples are shown at L 1 and L 2 in Figure 3. The L 1 point is the lowest point between 1 (where a BP occurs) and 2 (where a SP occurs) while the 2 point is the lowest point between 3 (where a BP occurs) and End . The equation to compute DD is shown below: However, if the BP at is next to the End , there is no SP to expect and (7) is used to compute DD. Otherwise, the value of DD is 0. Consider the following: The definition of RU is similar to DD, but RU works at MP = "Short" and records the difference between the selling price and the highest price. The location of the highest price is between the selling point and the next buying point or between the selling point and End . One example is shown at the 1 point in Figure 3. The 1 point is the highest point between 2 (where a SP occurs) and 3 (where a BP occurs) such that the risk at 2 is ( 2 ) − ( 1 ) since MP 2 = "Short." The following two equations (8) and (9) corresponding to equations (6) and (7) are used for RU, respectively: Otherwise, the value of RU is 0 under other circumstances.
The current risk is the maximal value among the current absolute values of CLoss, DD, RU, and the previous risk. The equation of risk is as follows:

An Example of Trading
Result. An example of trading rule {BF, a(0)c(−1), b(0)} is used to explain the profit rule mining in a trading simulation. The process is illustrated in Table 2.

6
The Scientific World Journal Without loss of generality, we set fee to 1. At the beginning, the investor holds a close position HPOS 0 = {None, 0, 0} in the entry no. 0 of Table 2. The patterns BP= a(0)c(−1) and SP= b(0) occur at TID = 3 simultaneously causing a trading ambiguity; thus trading priority = "BF" is applied to solve the problem and generate the first trading order TO 1 = {Buy, 1, 500} in the entry no. 1 of Table 2 Table 2.
The forth expected pattern is a SP at TID = 9 and TO 4 = {Sell, 1, 570} is generated at the entry no. 4 of Table 2.  Table 2.
The last expected pattern is a BP, but there is no buy pattern BP coming after TID 9. However, it is not risk free because there are transactions from TID 9 to End (i.e.,

Mining Profit Rules with Improved PRMiner
In this section, we review PRMiner and describe the improvements we made.
The number of items in a pattern is called the length of pattern. A pattern of length is called k-pattern. For example, pattern (0) (0) (−1) is a 3-pattern. Let and be two patterns. We define a function join(X, Y) for joining these two patterns into a new pattern . For the pattern Z = join(X, Y), we have = ∪ and TIDSet(Z) = TIDSet(X) ∩ TIDSet(Y). For example, the pattern a(0) appears in TIDSet(a(0)) = {3, 7} and the pattern b(0) can be found in TIDSet(b(0)) = {3, 5, 7, 9} in Table 1. Joining patterns a (0) and b(0), we have a new pattern a(0) We define an ITSet that consists of a pattern of itemsets and a TIDSet. The form of ITSet is 1 ( 1 ) 2 ( 2 ) ⋅ ⋅ ⋅ ( ){ 1 , 2 , . . . , }, where ∈ TID. Let Ftid(X) be a function for getting the first TID of a pattern . There exists an ambiguity if Ftid(X) = Ftid(Y) ̸ = , where is a pattern. Let simulation (R) be a function using a trading rule to do trading simulation and return the trading results RS R where the form of RS is [profit R , risk R , winrate R ]. Let = {Both, BF, SF} be a set of trading priorities for a trading rule. In PRMiner, we redefine the attribute trading priority tp ∈ in a trading rule. A trading rule with a trading priority "Both" means that one can extract two trading rules in which their trading priorities are "BF" and "SF", respectively.
Let and be two patterns. If X = Y, we can generate two trading rules with trading priority of BF and SF, respectively. If Ftid(X) ̸ = Ftid(Y), we can generate two trading rules with the same trading priority = "Both." If X ̸ = Y and Ftid(X) = Ftid(Y), we can generate four trading rules as shown in Table 3, where all the combinations of rules for patterns and are displayed.
Let RuleGenerator(X, Y) be a function for generating a set of trading rules by using patterns and in a TDB. We say that an Mtr(X) is a set of megatransactions which contain the pattern . The support sup(X) is defined as |Mtr(X)|. X is a frequent pattern if sup(X) ≥minsup, where minsup is a threshold value.  Table 3: The combination of trading rules using patterns and .

Conditions
The combination of trading rules

PRMiner and Its Improvements.
Before mining profit rules, a user specifies the thresholds minProfit, maxRisk, and minWinRate. PRMiner assumes minsup = 1 if minWinRate > 0%; otherwise minsup = 0. It means that at least one occurrence of a profit rule is required for a positive minWinRate.
PRMiner scans a TDB only once and stores all of the 1itemset into the oneItemList and the price is stored in the PList. The entry of the oneItemList contains an item and its TIDset(e). The price for a specific TID in PList is gotten by using the function ( ) defined in Section 3.4.1.
Instead of a single genPattern, two new depth-first-search strategies of genBP and genSP are used in the improved PRMiner to generate BP and SP patterns, respectively, by joining and shifting the 1-pattern from oneItemList into kpattern. Given the global parameters maxspan and minsup, Pseudocodes 1 and 2 show the pseudocode of genBP and genSP, respectively. To terminate the algorithm, the test of checking if the depth of search = 0 is replaced by examining the end of genBP and genSP in their respective procedures for the purpose of better performance.
The genBP and genSP procedures are based on the trading principles and the functions defined in the last section. First, the improved PRMiner calls genBP to generate a BP pattern. Then, genSP is invoked to produce all SP patterns using the BP as one of its input parameters. During the construction of SP patterns, the trading rules are generated by calling RuleGenerator as shown in Line 16 of Pseudocode 2 under the condition BP ≤ SP. After generating the second BP pattern, genSP is invoked again to produce corresponding SP patterns and trading rules as before. The process continues until the end of genBP is reached. Without rescanning the TDB, these trading rules are used to do trading simulation and produce trading results. Instead of providing an intricate description, (1) genBP (2) Parameters: (3) prefix : Pattern (4) index, interval : int (5) Begin (6) if interval > maxspan then (7) return (8) end if (9) if index < |oneItemList| then (10) for = index to |oneItemList| − 1 we use a simple example in the next section to illustrate the mining process of the improved PRMiner.

An Example of Using the Improved PRMiner.
We use the TDB of Table 1 and set the mining parameters fee = 1, maxspan = 2, minProfit = 20, maxRisk = 50, and minWin-Rate = 30%. At the beginning, the TDB is scanned to get the oneItemList as shown in Figure 4 where each entry contains an item and TIDSet(e). As described in Section 4.2, the minsup is set to 1 since minWinRate > 0%. The improved PRMiner uses the functions genBP and genSP to generate BP and SP patterns as shown in Tables 10 and 11, respectively. The first three BP patterns generated by the improved PRMiner in Table 10 are a (0){3,7}, a(0)b(0){3,7}, and a(0)b(0)c(0){}. Since the third BP has an empty TIDSet with a support value of zero, the pattern a(0)b(0)c(0) is removed and all of its extended patterns a (0)b(0)c(0)a(−1), a(0)b(0)c(0)a(−1)b(−1), 8 The Scientific World Journal (1) genSP (2) Parameters: (3) BP, prefix : Pattern (4) index, interval : int (5) Begin (6) if interval > maxspan then (7) return (8) end if (9) if index < |oneItemList| then (10) for = index to |oneItemList| − 1  After a new pattern BP is generated by genBP, genBP calls genSP to generate SP patterns and invokes RuleGenerator to produce trading rules using the pair of BP and SP patterns if the condition BP ≤ SP is satisfied. For example, RuleGenerator uses the first BP a(0) from the seq. 1 of Table 10 and SP a(0) from the seq. 1 of Table 11 to form two rules {BF, a(0), a(0)} and {SF, a(0), a(0)}. However, the first BP a(0) and the second SP a(0)b(0) cannot be used to generate trading rules because a (0) > a(0)b(0). Therefore, SP a(0)b(0) and its extended pattern SP a(0)b(0) c(0) are ignored. The patterns of seq. 3∼6 in Table 11 are all ignored because their support value is zero.
As for the first BP a(0) and the SP b(0) of seq. 7 in Table 11, four trading rules are generated. They are {BF, a(0), b(0)}, {SF,   a(0), b(0)}, {BF, b(0), a(0)}, and {SF, b(0), a(0)}. It is a simple combination of values for the components of a trading rule based on the rules in Table 3. After all the trading rules are generated by using BP a(0) and the rest of SPs, the next BP is changed to the second BP a(0)b(0) of seq. 2 in Table 10 and genBP calls genSP again to generate SPs and associated trading rules. The process continues until the end of genBP is reached.

Experiments
We use Java with JDK 1.6 to implement PRMiner and improved version. Our computer has a Intel Core-2 Duo P9600 CPU @ 2.66 GHz and 4 GB RAM. The operating system is Windows XP. All discovered profit rules are counted to compute the statistics and are not stored into the disk.
Two types of experiments were performed to evaluate the performance of the improved PRMiner. In the first type, we used a real dataset to mine profit rules and compared the result with that of the famous Buy and Hold Strategy (BHS) [13] to show the effectiveness of our algorithm. Section 5.1 describes the preprocessing for the real world dataset. A simple and effective measurement, Return of Investment (ROI) [14], is employed as the criteria for effectiveness evaluation in Section 5.2. Next, synthetic datasets were generated by using the IBM Data Generator [15] to measure the run time efficiency of our improved PRMiner using various minProfit, maxRisk, and minWinRate values in Section 5.3.

Data Preprocessing.
The real dataset comes from the Taiwan Economic Journal [16]. We select the data of the futures market in Taiwan from 2005/1/3 to 2010/6/30. Our approach is applicable to stock markets too. The source dataset contains 35,602,531 transactions of tick data including the date, time, price, and volume information. The processed tick data are stored in a TDB with the format of Table 1. The following three preprocessing steps are required to make the final conversion.
(1) Convert the tick data into candlestick chart (a style of bar chart) [17]. First, the tick data are converted into candlestick chart as shown in Table 4. Each transaction has three attributes of date, time, and prices representing the trading at that time. After conversion each bar in the candlestick includes six attributes of date, time, open price, highest price, lowest price, and close price. Each of the bars merges the price of tick data according to a specific time period ( > 0). A -minute (or -min.) candlestick chart consists of the bars within a -minute time period. For example, the transactions of one day in the tick data are partitioned into periods of -minute and a bar is generated in the candlestick chart for each period of the tick data. The prices of the first and last transactions in a period correspond to the open and close prices of a bar, respectively. The highest and lowest prices in a period also correspond to the highest and lowest prices in a bar, respectively.
Second, technical indicators are used on the candlestick chart for technical analysis of financial market data. TA-Lib [18] provides libraries for generating useful indicators. One of the simple and widely used indicators is a simple moving average (SMA). We chose the function of SMA(b) to generate the average value of close prices among bars and return a numerical value for each bar, where is an integral value. For example, function SMA(3) calculates the average value of three close prices starting from the current bar and return a numerical value. For example, the SMA(3) at time = "905" (the third entry of Table 4) is (6177 + 6177 + 6182)/3 = 6179 and SMA(3) at time = "915" (the fourth entry of Table 4)  Third, the candlestick chart along with indicators is converted into the form that can be stored as a transaction in our TDB. Each bar corresponds sequentially to one transaction in the TDB. The TID value in the TDB is a series number starting from 1. The close price in a bar is the price of a transaction. To generate items for each transaction, we define two functions cross-over and cross-under to work on the indicators. Figure 5 shows the functions of cross-over and crossunder. The horizontal axis is time and the vertical axis is close price. Two curves and are shown with two cross-points in the Figure 5. At the cross-points, the prices of and are the same. After passing the left cross-point on curve , the price of curve is greater than the price of curve and it is called a cross-over event. After passing the right cross-point on curve , the price of curve is smaller than the price of curve and it is called a cross-under event. Three indicators SMA(3), SMA(5), and SMA(8) are used with the cross-over and cross-under functions to generate six events which are represented by items to as shown in Table 5.

Effectiveness of Profit
Rules. An important benchmark, called Buy and Hold Strategy (BHS), is used to evaluate the effectiveness of our profit rules. BHS means that an investor buys a stock at the first transaction and does not sell the stock until the last transaction. The profit of BHS is the price at the last transaction minus the price at the first transaction while  the risk of BHS is the price at the first transaction minus the lowest price in the TDB. The return of investment (ROI) [18] is a simple and effective measurement for profitability and the definition of ROI is as follows: Here "profit" is the profit of a trading rule. The cost of investment is the summation of risk and initial margin, where the initial margin in the futures market is the amount of cash an investor must put up to open an account for trading. The investor must have enough capital to cover the risk during the investment period. The higher value of ROI indicates the better profitability of a trading rule.
In the first type of evaluation we use the real world dataset to perform two sets of experiments to measure the effectiveness of our improved PRMiner. The first set of experiments is to compare our results with that of BHS. The second set further evaluates the effectiveness of the mining algorithm by adjusting the values of minProfit, maxRisk, and minWinRate parameters.
We set fee = 4, minProfit = 982, maxRisk = 2290, and minWinRate = 30%, maxspan = 2, and the initial margin of Taiwan trading market = 320. The results of the first set of experiments are shown in Table 6 where the second column displays the ROI for BHS and the last three columns are for our improved PRMiner with the maximal, average, and minimal ROIs. Five different -minute time periods of candlestick data were used in the experiments where = 10, 15, 20, 30, and 60. It is obvious to see that all the ROI values of the improved PRMiner are much better than those of BHS. In particular, the second best Min. ROI of the improved PRMiner is greater than the best ROI of BHS (i.e., 0.39 > 0.38) in the last row of Table 6. Here, the best result of the improved PRMiner comes from the 30-minute candlestick data with the Max. ROI = 16.71, Avg. ROI = 2.56, and Min. ROI = 0.38. All of them are better than BHS's ROI = 0.36.
In the second set of experiments we use 10-Min. candlestick data to work with different settings of minProfit, minWinRate, and MaxRisk. We set fee = 4 and maxspan = 2. Users can set their expected value of minProfit. Here we assume minProfit = 4000.
To find the suitable settings of minWinRate for better ROIs, we first specify the minWinRate values without using the maxRisk (i.e., maxRisk is set to a very large value like 999999) in the first experiment. The results are shown in Table 7. As the minWinRate increases from 60% to 100%, the Min. ROI becomes larger in a linear fashion as expected. The Avg. ROI has a similar trend except when the minWinRate goes up to 90% and 100% since there are fewer profit rules to work with as shown in the last two columns of Table 7. Regarding the Max. ROI, the largest one is 16.01 when the minWinRate is below 90%. After that the Max. ROI becomes 9.88 since the previous rules may not satisfy the new requirement.
Second, we set the range of maxRisk from 3000 down to 1000 without specifying the minWinRate (i.e., minWinRate = 0%). Table 8 shows the results where the Avg. ROI and Min. ROI increase in response to lower risks. In the third experiment we specify both of minWinRate and maxRisk. To illustrate how to find better ROIs, we select the maxRisk that produces the best ROI (i.e., maxRisk = 1000) and set the range of minWinRate from 60% to 100%. As a result, except that the Max. ROIs remain the same (i.e., 16.01 and 9.88), all the other values of the Avg. ROIs and Min. ROIs in Table 9 are better than those in Table 7. From these experiments we can observe that the profit rules in our real world example are a small subset and can be extracted effectively by using profit-mining algorithms to get good ROIs. As expected, the more parameters of minProfit, minWinRate, and maxRisk are specified the better ROIs one can get. In particular, the increase rates of Min. ROIs from Table 7 to Table 8 and from  Table 8 to Table 9 are twofold.

Performance Evaluation.
We designed two sets of experiments to evaluate the execution performance of the improved PRMiner. By varying three user specified parameters of minProfit, maxRisk, and minWinRate in the first set of experiment, we can observe the changes of performance in executing the improved PRMiner. Stable performance is a very important feature for a financial tool. In the second set of  experiments, we increase the number of transactions to test if the improved PRMiner is a scalable algorithm. The results are plotted on the diagrams using the average value of ten tests.
We used the IBM data generator to build test datasets For example, the first dataset is T3I2D20KN4, where = 3 is the average size of transactions, = 2 is the average size of maximal potentially large itemsets, = 20 K is the total number of transactions, and = 4 is the number of unique items. In addition, a price generator was created to randomly produce the price information for each transaction in order to have the same format of Table 1. Given a seed of 1000 as the base price, we set that the range of the maximal and minimal prices between two consecutive transactions is within 2%, that is, between 1020 and 980. There are also ceilings for the highest and lowest prices in the TDB.
As before, we set fee = 1 and maxspan = 2. In the first set of experiments, we fix two of the three threshold parameters and change the values of the third one in a specific range.
First, we set maxRisk = 800 and minWinRate = 50%. Figure 6 shows the changes of running time for the values of minProfit ranging from 1000 to 1800.
From the above three experiments, we can see the range of running time is between 59.5 and 62 seconds. These results demonstrated that the improved PRMiner performs better than the PRMiner and both are stable and scalable.    In the next set of experiments, we focus on the performance of the improved PRMiner for five databases of different sizes. The thresholds are maxspan = 2, fee = 1, minProfit = 1000, maxRisk = 800, and minWinRate = 50%. Figure 9 shows that the performance of the improved PRMiner scales up almost linearly with respect to the increase of the number of transactions from 12 K to 20 K in the TDB. Although  the overall performance of the improved PRMiner is better than that of the original PRMiner, there are cases where the improvements (e.g., at 14 K and 18 K) are slightly less than the others.
To find the cause of degradation, we set the size of TDB = 14 K and repeat the last experiment five times with different distributions of prices generated randomly from the price generator. From Figure 10, we can see the large variation on the number of generated profit rules where the numbers of profit rules are close to zero in three out of five times. Therefore, it explains why the improvement is not as much as the others since there are less number of rules. Additionally, Figure 11 shows that the variation of price distributions and   the number of generated profit rules do not affect the best ROI. The results reinforce that the improved PRMiner is scalable and stable.  Best ROI Experiment-1 to experiment-5 Figure 11: The best ROIs from five different price distributions.

Conclusion and Future Work
In this paper, we improved the PRMiner algorithm and its implementation for effective mining of profit rules. Many examples are used to show how to mine profit rules and obtain good trading results. Experimental results show the effectiveness of our approach and its quality features on scalability and stable performance. As a preliminary study on financial data mining, we only used a simple trading approach of interday model for trading simulation. Using different trading models, we can derive many different trading rules The Scientific World Journal 13 under specific transaction databases. In data mining research, one expects to mine any knowledge that users might be interested in. These useful results of knowledge can be discovered and presented in terms of rules, patterns, or any other forms to meet users' expectation. Similarly, in profitmining, we think more types of profit rules can be defined and discovered in trading data from any kind of financial sectors. Since investors have their own measuring criteria for mining the preferred trading rules, we will investigate more useful models of financial data mining in the future. There is also room to improve the performance of our profit-mining algorithms.