Order Imbalance Based Strategy in High Frequency Trading
Shen Candidat Candidate eDarryl Number: Num ber: 275571
Linacre College University of Oxford
A thesis submitted in partial fulfillment of the MSc in Mathematical and Computational Finance
May 27, 2015
Acknowledgements
I would ould lik like to thank thank my supervi supervisor sor,, Dr. Zhaodo Zhaodong ng Wang, ang, for for his his assistanc sistancee on this thesis and provid providing ing guidanc guidancee througho throughout. ut. Discuss Discussion ionss about this project, high frequency trading, hedge funds, and the industry as a whole have been interesting and insightful. From the MSc Mathematical and Computational Finance class, I would like to thank Ivan Lam and Xuan Liu for their ideas and perspectives on high frequency trading, trading strategies, and statistical analysis. I would also like to thank a good friend in the industry, and all around genius, Jethro Ma. Finally Finally, my sincerest gratitude gratitude to my fianc´ee ee Emily and my parents parents for their unending support.
Abstract
This thesis aims to investigate the performance of an order imbalance based based trading trading strategy strategy in a high high frequenc frequency y setting setting.. We first first analyze analyze the statistical properties of order imbalance and investigate its capabilities as a trading strategy strategy motiv motivated by ideas ideas introduced introduced in [4,7, [4, 7, 11]. 11]. We try to understand how the strategy performs on different futures contracts and its relationship with trading volume. Finally, we attempt to improve the trading strategy by including including other imbalance-based imbalance-based signals, adjusting for bid-ask spread, and optimizing the model and trading parameters.
Contents 1 Introduction 1.1 High Frequency Trading . . . . . . . . 1.2 Limit Order Books and Microstructure 1.3 Stationarity . . . . . . . . . . . . . . . 1.4 Order Imbalance . . . . . . . . . . . .
. . . .
1 1 1 3 4
. . . . .
5 5 8 9 12 16
. . . . . . . . . .
17 17 17 18 21 22 22 23 24 27 32
4 Conclusions 4.1 Further Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
34 34
Bibliography
35
2 Order Imbalance Strategy 2.1 Volume Order Imbalance . . . 2.2 Assumptions and Setup . . . . 2.3 Statistical Analysis . . . . . . 2.4 Results and Performance . . . 2.5 Summary and Considerations
. . . . .
. . . . .
. . . . .
. . . . .
. . . . .
. . . .
. . . . .
. . . .
. . . . .
. . . .
. . . . .
. . . .
. . . . .
. . . .
. . . . .
. . . .
. . . . .
. . . .
. . . . .
3 Improved Strategy 3.1 Additional Factors and Analysis . . . . . . . . . . . 3.1.1 Order Imbalance Ratio . . . . . . . . . . . . 3.1.2 Mean Reversion of Mid-Price . . . . . . . . 3.1.3 Bid-Ask Spread . . . . . . . . . . . . . . . . 3.2 Parameter Selection and Results . . . . . . . . . . . 3.2.1 Parametrized Linear Model . . . . . . . . . 3.2.2 Comparison with Order Imbalance Strategy 3.2.3 Parameter Analysis . . . . . . . . . . . . . . 3.2.4 Parameter Selection Results . . . . . . . . . 3.3 Summary and Final Considerations . . . . . . . . .
i
. . . .
. . . . .
. . . . . . . . . .
. . . .
. . . . .
. . . . . . . . . .
. . . .
. . . . .
. . . . . . . . . .
. . . .
. . . . .
. . . . . . . . . .
. . . .
. . . . .
. . . . . . . . . .
. . . .
. . . . .
. . . . . . . . . .
. . . .
. . . . .
. . . . . . . . . .
. . . .
. . . . .
. . . . . . . . . .
. . . .
. . . . .
. . . . . . . . . .
A Daily Strategy P&L A.1 Volume Order Imbalance Strategy P&L: Main Contract . . . . . . . . A.2 Volume Order Imbalance Strategy P&L: Secondary Contract . . . . . A.3 Final Improved Strategy P&L: Main Contract . . . . . . . . . . . . .
38 38 43 48
B Daily P&L Heatmaps for B.1 Lag 2 P&L Heatmap . B.2 Lag 3 P&L Heatmap . B.3 Lag 4 P&L Heatmap .
54 55 56 57
Various Lags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
C Trading Simulation R Code
58
ii
Chapter 1 Introduction 1.1
High Frequency Trading
Traditionally, financial markets operated on a quote-driven process where a few market makers provided the sole liquidity and prices for financial assets [6]. Recently, major developments have been made to electronify the financial markets which has led to many trading firms using computer algorithms to trade financial assets as reported by Wang [14] and Aldridge [1]. High frequency trading (HFT), in particular, has been a major topic due to the features that distinguishes it from electronic and manual trading. This includes the extremely high speed of execution (microseconds), multiple executions per session, and very short holding periods (usually less than a day). Many algorithmic trading strategies have been developed on the advent of high frequency trading coming to the markets. According to Wang [14] and Aldridge [1], the advantages to having computers execute strategies include: higher accuracy, no emotion, lower costs, and technological innovation as the speed of trading becomes greater. Furthermore, by using the available market data, high frequency traders are able to come up with strategies which identify and trade away temporary market inefficiencies and price discrepancies. In this paper, we will be adapting and testing an existing strategy for HFT and verifying its stability and profitability.
1.2
Limit Order Books and Microstructure
Limit Order Books (LOB) allow any trader to become a market maker in the financial markets (Gould et al. [6]). It is a mechanism which allows traders to submit limit buy (sell) orders for the asset and the prices they wish to pay (receive). The limit order book is a complex system and understanding it can give insight into traders’ 1
intentions and a way to develop trading strategies using the rich and granular data it stores. We will define a few technical terms relating to LOBs that will be used throughout the paper including fields specific to the dataset we will be examining. The LOB is essentially a matching engine for buyers and sellers in the market [6]. Within a LOB, the best bid (ask ) price is the highest (lowest) price a market maker is willing to buy (sell) the asset at to market takers. The maximum number of contracts that the market makers are willing to buy (sell) at the bid (ask) price is called the best bid (ask) volume . Any market taker who wishes to buy (sell) at the counterparty price can submit a market order to trade at the best ask (bid) price up to the ask (bid) volume available. If the market order to buy (sell) is larger than the ask (sell) volume, then they will walk the book; the market taker will continue buying (selling) at the next-best ask (bid) price until their entire market order is filled. In this project, the data we will use is the China Financial Futures Exchange (CFFEX) CSI 300 Index Futures (IF). It comprises of snapshots taken every 500 milliseconds. From this point on, every time step is in intervals of 500 ms. That is, time t + 1 is 500 ms after time t. The tick size of the IF contracts is 0.2 and the tick value is 300 Chinese Yuan (CNY). The trading hours of the contracts on CFFEX is from 9:15 to 11:30 for the morning session, and 13:00 to 15:15 for the afternoon session. A sample of the data for January 16th, 2014 is shown in Table 1.1 below. Instrument Update Volume Turnover ID time IF1401 9:27:06.0 14589 9.69e9 IF1402 9:27:06.0 6337 4.22e9 IF1401 9:27:06.5 14593 9.69e9 IF1402 9:27:06.5 6351 4.23e9 IF1401 9:27:07.0 14595 9.70e9 IF1402 9:27:07.0 6351 4.23e9 Note: certain fields omitted to save space
Open interest 60011 28960 60010 28974 60010 28974
Bid price 2213.4 2218.8 2213.4 2218.8 2213.4 2218.8
Bid volume 23 4 21 4 22 6
Ask price 2213.8 2219 2213.8 2219 2213.8 2219
Ask volume 70 53 70 39 70 39
Second of day 34026 34026 34026 34026 34027 34027
Table 1.1: Sample data set for IF1401 and IF1402 on Jan 16th, 2014. The data provided is in comma separated values (CSV) format and each file presents a single trading day. However, on the CFFEX, two different futures contracts are traded: the CSI 300 Stock Index Futures (IF) and the Treasury Bond Futures (TF). We will only be focusing on the IF contracts for this paper. IF contract maturity is on the third Friday of every month. Instrument ID: the unique identifier of the futures contract being traded. It begins with IF or TF and followed by a 4-digit integer. The first two digits 2
represents the year and the last two represents the month of contract maturity. For example IF1401 is the IF contract maturing in January 2014. Update time: the exact time the LOB snapshot was taken, up to 500 millisecond precision. Volume: the transaction volume of contracts traded since market open (9:15) Turnover: the CNY-denominated volume traded since market open (9:15). This quantity is calculated by number of contracts × price × tick value. Open Interest: the number of contracts traded that create an open position (not trade to close) Bid/Ask price: the highest/lowest price a market maker is willing to buy/sell the futures contract at. Equivalently, it is the best price that a market taker can sell/buy the contract at. Bid/Ask volume: the number of contracts available at the current best bid/ask price. Second of day: number of seconds (rounded down) since midnight of the trading day. Another measure we will be using throughout the paper is the mid-price, denoted M t , which is the arithmetic average of the bid and ask prices at time t. More details regarding the structure and intricacies of the CFFEX can be found in Wang [14].
1.3
Stationarity
As mentioned in Wang [14], high frequency trading and applications of their strategies are closely related to the ergodic theory of stationary processes. We first explain the two types of stationarity for a time series X t as defined by Tsay [12] and Wang [14]. A time-series X t is strongly stationary if (X t , X t ,...,X t ) has the same distribution as (X t +a , X t +a ,...,X t +a ) for all a and any arbitrary integer n > 0. A less strict definition of stationarity for the time-series X t is called weakly stationary if the first two moments do not change over time. That is, E X t ] = E X t+a ] = µ and Cov (X t , X t+a ) = γ a for all time t and arbitrary a. The covariance for any interval a should only depend on a for the process to be weakly stationary. 1
1
2
2
n
n
3
Strong stationarity is difficult to verify empirically and therefore any hypothesis tests we conduct in this paper will be to verify weak stationarity, including both the Augmented Dickey-Fuller test and the KPSS test. It is sufficient for the data to be weak stationary for traders to build an algorithmic trading strategy which generates positive expected profits to be applied repeatedly and steadily accumulate positive returns [14]. Further theory regarding stationary processes, the strong ergodic theorem, and its applicability in high frequency trading can be found in [10,14].
1.4
Order Imbalance
Many studies have been conducted to describe the relationship between trade activity (volume) and price change and volatility (see Karpoff [8] for example). As traders submit limit orders to buy (sell), they impact the bid (ask) volumes of the limit order book and thereby gives us a view of the traders’ intentions. Categorizing trade volume as either taking the bid (ask) would allow us to gain insight into the direction of the upcoming price changes. To quantify this intent to trade, we look at the difference between the bid and ask volume, called order imbalance. Chordia and Subrahmanyam [4] have found the positive relationship between order imbalance and daily returns on a sample of stocks from the New York Stock Exchange. Order imbalance is an important descriptor that allows us to understand the general sentiment and direction the market is headed. If informed traders have information that has not been incorporated into the asset price yet, they can take a long (or short) position given the positive (or negative) news and subsequently increasing the imbalance on the asset [7]. Other market participants, who are merely observing this phenomenon in the LOB, would be able to use this information and develop a strategy to generate positive returns. The next chapter will carefully analyze the relationship between order imbalance and mid-price changes and determine whether it can be used to predict future price changes at the high frequency level. We will also investigate the statistical properties of order imbalance and how they can be applied to a trading strategy to generate statistically significant positive returns on a daily basis. Given that the previous studies by Chordia [3,4] and Huang [7] were done on much longer time-scales (daily and 5-15 minute intervals respectively), we will verify if the order imbalance theory they presented are still applicable to high frequency data.
4
Chapter 2 Order Imbalance Strategy We will be implementing and testing a similar imbalance-based strategy as outlined by Chordia and Subrahmanyam [4], Huang et al . [7], and Ravi et al. [11] where we enter into a long position when order imbalance is positive and a short position when order imbalance is negative.
2.1
Volume Order Imbalance
The order imbalance in [4, 7, 11] is defined using Lee and Ready’s algorithm [9] to classify trades as either buyer-initiated or seller initiated. This is done by checking if the trade price was closer to the bid (sell) or ask (buy) of the quoted price. Rather, our definition is more similar to the Order Flow Imbalance used by Cont et al. [5] which we will call Volume Order Imbalance (VOI): OI t = δV tB − δV tA
(2.1)
where δV tB
0, = V V
B t B t ,
−
V tB , −1
P tB P tB P tB
< P tB−1 = P tB−1 > P tB−1
δV tA
,
V = V 0,
A t , A t
−
P tA < P tA 1 −
V tA , −1
P tA P tA
= P tA−1 > P tA−1
(2.2)
where V tB and V tA are the bid and ask volumes at time t respectively and P tB and P tA are the best bid and ask prices at time t respectively. If the current bid price is lower than the previous bid price, that implies that either the trader cancelled his buy limit order or an order was filled at P tB 1 . As we do not have a more granular order or message book, we cannot be certain of the trader intent, hence we conservatively set δV tB = 0. If the current bid price is the same as the previous price, we take the difference of the bid volume to represent incremental buying pressure from the −
5
last period. Lastly, if the current bid price is greater than the previous price, we can interpret this as upward price momentum due to the trader’s intent to buy at a higher price. Downward price momentum and sell pressure can be interpreted analogously from the current and previous ask prices. Order imbalance has positive autocorrelation as presented in Figure 2.1. For most days, the order imbalance autocorrelation is significant up to lag 15. Its first difference has a significant lag-1 negative autocorrelation and is consistent with the results by Chordia [3]. This indicates that positive (negative) imbalances are often followed by periods of persistent positive (negative) imbalances due to traders splitting their orders across multiple periods as explained by Chordia [4].
Figure 2.1: Autocorrelation functions for VOI and ∆VOI We also find that the VOI is positively correlated with contemporaneous price changes. That is, the correlation between OI t and ∆M t = M t − M t 1 is 0.3935 which is consistent with the result in Chordia [3], though the relationship is not as strong. Figure 2.2 below illustrates this positive relationship. −
6
Figure 2.2: Scatterplot of VOI against contemporaneous price change on August 13, 2014. Blue line represents line of best fit. Furthermore, fitting a contemporaneous linear model ∆M t = α + βOI t + εt gives an average daily R2 of 0.155, which is a much weaker R2 of 0.69 presented by Cont in [5]. Even if we change the definition of VOI to match the definition of order flow imbalance, it only improves the average R2 to 0.294. Since both studies are done in the high frequency space, the difference in R2 it is likely due to the different time scales used in the analysis. By matching the 10 second time interval that Cont uses, we are able to get a daily average R2 of 0.6537, which is consistent with his results.
Figure 2.3: Scatterplot of VOI against price change over 10 second intervals on August 13, 2014. Blue line represents line of best fit. Figure 2.3 above presents the same relationship between VOI and price change at the 10 second interval that is highlighted in [5]. 7
Given that we have found a strong association between VOI and contemporaneous price changes, the following sections will analyze its strength in predicting future price changes and investigate its performance as a trading strategy.
2.2
Assumptions and Setup
We make several assumptions about the trading mechanisms and the simulation of the trading algorithms: (a) There are no market competitors which means we can always trade at the counterparty price (sell at bid and buy at ask). (b) There is no latency from the time we receive the new market data to the time we execute the trade, given a favourable signal. (c) The maximum position allowed is ±1 contract at any time and we can only buy and sell whole contracts. (d) The trading cost (commission) is 0.0025% of execution price. To construct our linear model each day, we select a main contract to be traded by examining the trade volume at market open (9:15) by choosing the futures contract with the largest volume. To remove some of the volatility and noise from the data that generally occurs at market open and close [5], we will also be restricting the trading hours from 9:16 to 11:28 and only be allowed to close positions after 11:20 for the morning session, and from 13:01 to 15:13 and only close positions after 15:00 for the afternoon session. Our strategy uses ordinary least squares to forecast the average mid-price change over the next 10 seconds (20 time-steps) using both instantaneous1 and lagged VOI. We build the linear model using the previous business day’s data and attempt to forecast the mid-price change for the current trading day. This set up is similar to Chordia and Subrahmanyam [4] where they use a linear regression model on lagged order imbalances to predict daily (open-to-close) stock returns. They do not include contemporaneous in the trading strategy as it would be a forward looking measure. The setup used by Huang et al. [7] is slightly different. They calculate order imbalance at 5, 10, and 15 minute intervals in intraday data. After trimming off 90% of small imbalances, the strategy is to buy (sell) when a positive (negative) imbalance 1
In our case, the instantaneous VOI is calculated the instant the market data is received and hence is not forward looking .
8
appears. Instead of building a linear model to forecast returns, they directly trade on the tails of order imbalance.
2.3
Statistical Analysis
We propose a linear model where we predict future price change with the current (instantaneous) and lagged VOI. Chordia [4], Huang [7], and Cont [5] all build linear models with lagged order imbalances as the explanatory variable and the immediate one-period price change as the response. However for high frequency data, one timestep mid-price changes are often zero. On a daily average, only 45% of one-period price movements are non-zero, so the model would not often capture the larger price movements that the strategy should be trading. Instead, we should consider an average price change over a longer time period, which we will call the forecast window . We present some statistical properties of the explanatory and response variables before analyzing the linear model. The initial linear model suggested by my supervisor, Dr. Zhaodong Wang, is: 5
∆M t,20 = β c +
β j OI t j + εt −
(2.3)
j =0
20 1 where ∆M t,20 = 20 j =1 M t+ j − M t is the average mid-price change with forecast window k = 20, OI t j is the j -lag VOI, β c is the constant coefficient, β j is the j -lag coefficient. We also make the assumption the errors ε t are independent and normally distributed with zero mean and constant variance (as per Gauss-Markov). This model is constructed independently for each of the 244 trading days in 2014 using ordinary least squares linear regression. Analogous to the study done by Chordia [4], their response variable would be equivalent to setting the forecast window of the average mid-price change in our model to k = 1 time-step. From hereon, we will present all linear regression coefficients in a similar style to Chordia [4] and Huang [7].
−
9
Intercept OI t
Average coefficient 1.198 × 10 3 2.842 × 10 3 5.175 × 10 4 −2.944 × 10 4 −2.948 × 10 4 −1.270 × 10 4 1.569 × 10 5 −
−
OI t
−
OI t
−
OI t
−
OI t
−
1 2 3 4
−
−
−
−
OI t 5 * at the 95% confidence level −
−
Percent positive 50.41% 100.00% 97.95% 13.52% 9.43% 27.46% 50.41%
Percent positive and significant 29.51% 100.00% 88.11% 3.69% 2.46% 7.38% 20.49% ∗
Percent negative and significant 27.87% 0.00% 0.00% 61.48% 60.25% 29.10% 14.34% ∗
Table 2.1: Linear Regression Results for Volume Order Imbalance Model. Blue cells indicate majority of the coefficients having significant positive or negative sign. The average of the daily instantaneous and lagged order imbalance results are shown in Table 2.1 above. We notice that the instantaneous VOI and the lag-1 VOI are both positive and significant at the 5% level for nearly all 244 trading days as indicated by the blue cells. Chordia [3, 4] argues that their lag-1 order imbalance (our instantaneous) has a positive coefficient due to autocorrelated price pressures imposed by past order imbalances. As mentioned in Huang [7], their results do not agree with Chordia’s as they found a negative coefficient in their lag-1 order imbalance. One possible reason that both our instantaneous and lag-1 VOI have a positive coefficient is because we take the average price change over 20 time intervals compared to the daily time interval used by Chordia or the 5-minute interval used by Huang. Chordia notes that the remaining lags order imbalance have negative coefficients due overweighting the impact of current imbalances. The price pressures associated with current imbalanced are slowly reversed through time as indicated by negative lag-2 to lag-4 VOI coefficients. The daily average R2 of the model (2.3) is 0.0298. This result is consistent with similar research done by Cont [5] on NASDAQ equity data. A plot of the fit for a sample date is shown in Figure 2.4 below. Although the coefficient of the linear model is positive and significant for the instantaneous VOI indicating that there is a positive relationship, it is not immediately obvious in the plot below.
10
Figure 2.4: Instantaneous VOI vs. Average Price Change on August 13, 2014. Blue line represents line of best fit. Given that the instantaneous and lagged order imbalance are significantly related with the average 20-step mid-price change, we can use this linear model to devise a trading strategy. At time t, as market data is received, we are able to calculate the instantaneous order imbalance OI t and obtain a forecast for the mid-price change. If the forecasted price change is greater than 0.2 (less than -0.2) ticks then we buy (sell) the maximum allowed position. The threshold, q = 0.2 ticks is chosen as it is the minimum tick size and therefore is also the smallest the bid-ask spread can be. The full trading algorithm is presented in appendix C. Furthermore, verifying that the price change and VOI process is stationary is important because if there are structural changes in the markets, using previous day’s linear model can lead to unfavourable trading signals [10]. Given stationarity, we assume the mean and covariance through time do not change. If the data is not stationary, it would be incorrect to assume that today’s price changes can be predicted using previous day’s model. The Augmented Dickey-Fuller (ADF) test and KPSS test are performed on each day’s average price change and VOI processes separately. In the case of the ADF test, not rejecting the null hypothesis of having a unit root indicates that the process is not stationary. For the KPSS test, rejecting the null hypothesis indicates the process is not stationary. It is important to make the distinction that neither test confirms that the process is stationary, but only if it is not not stationary.
11
ADF Test
KPSS Test
H 0 : x t has a unit root H 1 : x t does not have a unit root
H 0 : x t is stationary H 1 : x t is not stationary
Reject H 0 Fail to Reject H 0 ∗
∆M t,20 100.00% 0.00%
VOI 100.00% 0.00%
∆M t,20 Reject H 0 8.2% Fail to Reject H 0 91.8% ∗
∗
VOI 10.0% 90.0%
* at the 95% confidence level
Table 2.2: Percentage of days the average price change and VOI processes are considered stationary when applying the Augmented Dickey-Fuller and KPSS tests. Favourable results are highlighted in green. Table 2.2 above summarizes the tests of stationarity and reports the proportion of dates whose average price change and VOI processes that pass each test at the 95% confidence level. Using the ADF test, we see that the average price change and VOI processes both reject the null hypothesis of having a unit root. Further supporting the idea that our response and explanatory variables are stationary is the results from the KPSS test – no more than 10% of the days reject the null hypothesis of stationarity. This means on majority of trading days, we should be able to apply the same trading strategy to generate positively increasing profits due to the stationarity of our time-series processes [14].
2.4
Results and Performance
The results of using the linear model (2.3) as a trading strategy is summarized in the table below. The full set of results for this strategy is in appendix A.1. Statistical test: one-tailed, one-sample t-test (df = 243) H 0 : µ ≥ 0 H 1 : µ < 0 Mean daily Standard t-stat p-value Days with profit (CNY) error profit 9 19,528 3,290 5.9352 5.032 × 10 185 Average Daily Sharpe Ratio: 0.380 Annualized Sharpe Ratio: 5.935 −
Days with losses 58
Mean daily trade volume 634
Table 2.3: Trading strategy results using volume order imbalance linear model The results in Table 2.3 indicate that the strategy yields a statistically significant positive average daily profit and approximately 76% of the trading days generates positive returns. If we assume a margin of 100,000 CNY, the mean daily return is 12
approx approxima imately tely 19.5%. 19.5%. Despite Despite order imbalance imbalance having having a low low correlat correlation ion with the average price change, the strategy performs quite well. One reason for this is due to using the predicted price change as a multinomial classifier used for decision-making rather than for additional additional calculations. calculations. On average, average, the daily correlation correlation between the actual and predicted price change is only 0.166 but if we transform the prediction into a three-class variable {−1, 0, +1} based on the trading threshold ±0.2, the correlation correlation increases to 0.449.
Figure 2.5: Cumulative P&L by trade; red points indicate beginning of month In Figure 2.5 above, we notice there is a linear relationship between profit and the number nu mber of trades and also time in the first 11 months months of trading. trading. Each Each red point in the plot represents the beginning of a month. The cumulative cumulative P&L after December December grows at a greater rate then the previous 11 months and more than half of the trades were made in December alone. So what happened in December?
13
Figure 2.6: Daily transactional transactional trading volume volume for main contract by day in grey (leftaxis) overlayed by daily close mid-price in CNY in blue (right-axis) with each dotted line indicating beginning of a new month From Figure 2.6, we can see that the daily traded volume of the main futures contrac contractt nearly nearly doubled doubled in December December compared compared to the previous previous 11 months. months. This This is likely due to the price of the main contract rising at the same time. As the price rises, trading the asset becomes more attractive to more investors so volumes rise with it. This is evident based on the highly positive correlation between total traded daily volume volume and daily close price (0.828). In addition to higher prices and higher volumes, volumes, our strategy trades, on average per day, 13 times more and generates nearly 25 times as much profit in December compared to the rest of the year. The mean daily profit is highly positively correlated with total traded daily volume (0.863). There is a clear change in market conditions in December and we will address the strategy’s potential shortcomings in the next section. Chordia [4] reported a statistically significant positive average daily return on their order imbalanced imbalanced strategy of approximate approximately ly 0.09%. However However,, after accounting for potential transaction costs and commissions, he reasoned that the profits would be nu nulli llified. fied. The strategy strategy employ employed ed by Huang [7] generate generated d negativ negativee returns returns when trading on counterparty price but managed to give significant positive returns (0.49%) when trading on transaction price (mid-price, essentially). Another study done by Ravi and Sha [11] on equity markets from 1993 to 2010 finds that a strategy based on buying and selling pressure also produces significant positive returns. Similar to Chordia and Huang, they use Lee and Ready’s algorithm 14
[9] to classi classify fy the directi directional onal pressure pressure of each each stock. stock. Instead Instead of using using a linear linear model (as in Chordia [4]) or a percentile threshold signal (as in Huang [7]), they rank the top 10% of stocks with greatest buy (sell) pressure and form a buy (short) portfolio to trade trade each each day day. This This method method produced produced returns ranging ranging from 7.3 basis basis poin p oints ts (in 2007) to 47 basis points per day (in 1993). The results of each study indicate that order imbalance can be used to yield statistically significant positive returns and is consistent with our findings when the strategy strategy is applied applied at a high high frequenc frequency y level. level. Most Most notably notably,, the strategy strategy performs performs extremely extremely well when applied to high frequency Chinese Index Futures Futures and even better b etter when volume is abnormally high (as it was in December 2014). This strategy heavily relies on choosing a futures contract with high trading volume thereby being able to produce a strong imbalance signal which is derived from bid-ask volume. Lastly, we find that the forecast window k = 20 is not optimal for this linear model model and and can be param parametr etriz ized ed.. Figu Figure re 2.7 2.7 below below shows shows,, for for fixed fixed lag, lag, the the daily daily mean profit for various forecast windows k = 1, ..., ..., 30. We see that it peaks at k = 4 before decreasing linearly in k and gives us an idea of the optimal forecast window for the parametrized model.
0 0 ) 0 Y 0 N 2 C ( t 0 i f 0 o 0 r 8 P 1 y l i a 0 D 0 0 n 6 a 1 e M 0 0 0 4 1
0
5
10
15
20
25
30
Forecast Window (k)
Figure 2.7: Mean daily profit for various forecast windows A more detailed analysis on how average daily profits change with forecast window is presented in the next chapter.
15
2.5
Summary and Considerations
The order imbalance strategy proposed by Dr. Wang is highly successful on the Chinese Index Futures market when applied to high frequency data. Similar strategies designed by Chordia [4], Huang [7], and Ravi [11] all produce positive average daily returns when applied to larger time-scales, although the magnitude of these returns are nearly 200 times smaller than ours. Cont [5] also presented a similar positive relationship between order flow imbalance and future price change in high frequency NASDAQ data. As mentioned in the previous section, daily profit is highly correlated with daily trade volume so applying this strategy to futures with lower volumes would likely perform poorly. If there’s not enough volume, the bid-ask spread might be very wide and it would not be beneficial to trade at counterparty price. When applying the strategy on a futures contract with the second highest trading volume at market open, the mean daily profit is only 2,801 CNY (down 86% from main contract profit) and the win ratio is down nearly 30% from 76% to 49%. This means on more than half of the trading days, this strategy loses money trading a futures contract with lower volume. Finally, the annualized Sharpe ratio falls from 5.935 to 1.763. The full profit and loss results for applying the strategy to the secondary contract can be found in appendix A.2 Lastly, the linear model (2.3) considers only a single factor: the VOI up to lag 5. Previous sections showed that when fitting a linear model using ordinary least squares, the coefficients are statistically significant. Despite performing well as a trading strategy, the fit of the linear model was quite poor and does not explain the variation in price change well. However, we find that if we treated the predicted price change as a multinomial class variable, its correlation with the actual price change improved from 0.166 to 0.449. This suggests that we can improve our prediction if we considered additional features in the linear model. One drawback to the VOI is that it only considers the size of the order imbalance but not degree or strength of the imbalance. The next chapter will elaborate on additional factors and how they can capture more detailed imbalance information in the high frequency dataset.
16
Chapter 3 Improved Strategy We would like to improve upon the existing strategy presented in chapter 2 by extending the linear model with new factors and also by optimizing the regression and trading parameters. The improvements described in the following section produces a net daily profit of 58,600 CNY, a win ratio of 94.7%, and daily Sharpe ratio of 0.464. This is a 400% increase in profit, nearly 20% increase in dates with positive profits, and 22% increase in Sharpe ratio.
3.1 3.1.1
Additional Factors and Analysis Order Imbalance Ratio
The VOI only measures the magnitude of the imbalance which is not sufficient to describe the behaviour of the traders in the market. For example, if the current bid change volume is 300 and the current ask change volume is 200, the VOI is 100, which is considered a strong signal to buy. However, this does not take into consideration the ratio between the bid volume and ask volume which indicates the strength of the potential buyers in the market. Hence, we define a new factor called the Order Imbalance Ratio (OIR), as: V tB − V tA (3.1) ρt = B V t + V tA This factor complements the volume order imbalance by allowing us to distinguish cases where the difference is large but the ratio is small. In the example presented above, the OIR is only 0.2, indicating that the original signal to buy may not be that strong after all. The OIR is another measure of order imbalance and should share similar statistical properties to VOI. The autocorrelation is presented below in Figure 3.1 and they share the same signs and similar magnitudes with the autocorrelation of VOI in Figure 2.1. 17
Figure 3.1: Autocorrelation functions for OIR and ∆OIR However, we find that the relationship between OIR and contemporaneous price change is actually the opposite to VOI. The correlation between ρt and ∆M t is 0.3458. One interpretation of this is due to the same order-splitting theory by Chordia [4]. Since the autocorrelations of ρt is also significant and positive for the first 5 lags as VOI was, we can assume this is an equivalent representation of the ordersplitting behaviour of traders. By definition, a large OIR means that the bid volume is much greater than the ask volume at a given time, indicating many traders have the intention to buy, and very few have the intention to sell. But since a large OIR is associated with a negative price change, it means that more a larger proportion of traders are willing to buy when prices have fallen. This result demonstrate how the orders are split over time as opposed to the autocorrelations which only indicates the presence of order-splitting.
3.1.2
Mean Reversion of Mid-Price
Aside from the VOI and OIR, we include a way to classify trades as being buyerinitiated or seller-initiated. Using the traded volume and turnover information in the data set, we are able to determine the average trade price between two time-steps. We define the Average Trade Price, T P t from (t − 1, t] as:
M , 1 T − T T P = 300 V − V T P ,
t = 1
1
t
t
t−1
t
t−1
t−1
,
V t = V t
1
V t = V t
1
−
(3.2)
−
where T t is the turnover (trade volume in CNY) and V t is the transaction volume at time t. This process represents the average price that other market participants executed their trades at which can be interpreted as a proxy for trade imbalance. By 18
checking whether T P is closer to the ask (bid) price, we can classify trades as being more buyer (seller) initiated. However, instead of a binary classification, we define the factor as the distance of the average trade price from the average mid-price over the time-step (t − 1, t]: Rt = T P −
M t 1 + M t −
2
= T P t − M P t
(3.3)
where M t is the mid-price at time t. The factor Rt , which we call the mid-price basis (MPB), is an important predictor of price change because of its mean reversive properties. It gives a continuous classification of whether trades were buyer or seller initiated. A large positive (negative) quantity means the trades were, on average, closer to the ask (bid) price. Our definition of the MPB is similar to the definition of order imbalance definition used in [3, 4, 11] where they use the Lee and Ready algorithm [9] to classify trades as buyer or seller initiated. To check whether the process Rt is mean-reverting, we apply the variance ratio (VR) test outlined in [2]. For the time series Rt = φR t 1 + εt , the null hypothesis of the VR test is H 0 : φ = 1. If the series is a random walk (φ = 1), then for a k-period lag, we get the relationship: −
Rt − Rt
k
−
= (Rt − Rt 1 ) + ( Rt
1
= ε t + εt 1 + ... + εt
k+1
−
−
−
− Rt 2 ) + ... + ( Rt −
k+1
−
− Rt k ) −
(3.4)
−
k−1
=
εt
j
−
j =0
Assuming that the errors are independent and identically normally distributed1 with zero mean and constant variance, taking the variance of both sides gives: k−1
2
R − R = ε = k ε = k σˆ (1) = k R − R
σ ˆ (k) = V
t
t−k
V
t− j
(3.5)
j =0
V V
t
t
t−1
2
Hence, for a process which follows a random walk, we test whether variance ratio σ ˆ (k) is equal to 1. In this paper, we will not address the issue of a finite sample kσ ˆ (1) size as our daily sample size (around 30,000) is likely considered large enough for a variance ratio test of up to lag 20. Figure 3.2 below depicts the ratios for k = 2 to 2
2
1
For most dates, both the ADF-test and KPSS-test indicate Rt is a stationary process.
19
100 and indicate that they are below 1 for all lags, meaning the process Rt exhibits mean-reversion [2]. The result is statistically significant at the 99% confidence level.
Figure 3.2: Variance ratios for Rt on August 13, 2014 We expect that Rt will revert back to mean 0 so if Rt > 0, the mid-price will eventually increase and revert towards the average trade price and if R t < 0, then we would expect the mid-price to decrease back to average trade price. Thus, we have a buy signal when Rt > 0 and sell signal when Rt < 0. The positive relationship between Rt (MPB) and the average mid-price change (response) is shown below in Figure 3.3.
Figure 3.3: Scatterplot of the mid-price basis (Rt process) against the response variable (average price change) on August 13, 2014. Blue line indicates line of best fit.
20
3.1.3
Bid-Ask Spread
The bid-ask spread at time t is defined as S t = P tA − P tB . It is an important measure of liquidity and has a positive relationship with contemporaneous price volatility and negative relationship with trade volume based on findings by Wang and Yau [13] for various CME Futures. This information can be used to adjust our regression factors for different levels of liquidity by dividing them by instantaneous spread. This spread adjustment was found in collaboration with Xuan Liu [10].
Figure 3.4: Scatterplot of spread against average price change for August 13, 2014 (left) and December 3, 2014 (right) illustrating high spreads are associated for price changes near zero. From Figure 3.4 above, we see that when spread is large, there are very few observations where the average change in mid-price is away from zero. Hence when liquidity is low, the price is slow to change and therefore trading may be unfavourable. This will potentially reduce the risk of trading on a weak signal when the spread is large. One interesting observation is that a large VOI (negative or positive) is associated with smaller spreads. From Figure 3.5 below, we notice that large spreads only occur when order imbalance is near 0. Chordia [3] finds that higher spreads are associated with a larger (absolute) order imbalance but our findings above does not agree with his results. This may be due to the fact that we are using high frequency data and not aggregated daily data.
21
Figure 3.5: Scatterplot of spread against VOI for August 13, 2014 illustrating high spreads are associated with VOI near zero. Using these relationships between spread and price change and spread and order imbalance, we adjust our factors so that we would not falsely obtain a trading signal when spread is large. The final parametrized model which includes the spread adjustment is presented in the following section.
3.2 3.2.1
Parameter Selection and Results Parametrized Linear Model
We incorporate the new features OIR and MPB as defined by (3.1) and (3.3) respectively into our linear model. Each feature will also include the spread adjustment discussed in 3.1.3 by dividing by the spread. The final linear model is presented in equation (3.6) below. L
∆M t,k = β 0 +
j =0
OI t β OI,j S t
L j
−
+
j =0
β ρ,j
ρt j Rt + β R + εt S t S t −
(3.6)
where ∆M t,k = h1 jk=1 M t+ j − M t is the k-step average mid-price change, OI t j is the j -lag Volume Order Imbalance from the previous strategy, ρ t j is the j -lag Order Imbalance Ratio, R t is the instantaneous mid-price basis, and S t is the instantaneous bid-ask spread. We also parametrize the lag L for Volume Order Imbalance and Order Imbalance Ratio. For coefficients, β 0 is the constant term, β OI,j corresponds to the j -lag spread-adjusted VOI, β ρ,j corresponds to the j -lag spread-adjusted OIR, and β R corresponds to the spread-adjusted MPB. The errors εt are assumed to be independent
−
−
22
and identically normally distributed with zero mean and constant variance. This model will be built using ordinary least squares linear regression. We note from the previous model (2.3) that the parameters are set to k = 20 and L = 5 even though they may not be optimal for this strategy. The next section will discuss parameter optimization.
3.2.2
Comparison with Order Imbalance Strategy
Without any parameter optimization, we can compare the results of the two linear models (2.3) and (3.6) given the same forecast window k = 20, lags for order imbalance L = 5 (and trading threshold q = 0.2): 5
∆M t,20 = β 0 +
j =0
OI t β OI,j S t
5 j
−
+
j =0
β ρ,j
ρt j Rt + β R + εt S t S t −
(3.7)
That is, we will use the previous day’s linear model to forecast today’s 20-step average mid-price change and only trade if the change is above 0.2 (below -0.2). The linear model (3.7) has R2 = 0.0701 which is greater than the previous model (2.3).
Intercept 1
−
OI t S t OI t
−
S t
OI t
−
2
S t
OI t
−
3
S t
OI t
−
4
S t
OI t
−
5
S t
ρt
−
ρt
−
ρt
−
ρt
−
ρt
−
1 1
−
−
1
−
1
−
1
−
1
2
S t
3
S t
4
S t
5
S t
1
−
−
−
−
−
−
1
S t
1
−
−
1
−
1
−
1
Rt S t
1
−
−
ρt S t
−
−
−
1
Average coefficient 1.131 × 10 3 4.992 × 10 4 1.879 × 10 4 −3.698 × 10 5 −6.894 × 10 5 −4.224 × 10 5 −7.047 × 10 6 1.610 × 10 2 −1.147 × 10 2 −1.349 × 10 3 1.148 × 10 3 1.240 × 10 3 1.214 × 10 3 1.038 × 10 1 −
−
−
−
−
−
Percent positive 50.00% 100.00% 100.00% 36.89% 11.89% 21.31% 39.75% 99.59% 0.00% 4.51% 74.59% 82.79% 82.38% 100.00%
Percent positive and significant 31.97% 100.00% 100.00% 13.52% 4.51% 6.15% 15.16% 92.62% 0.00% 0.00% 20.90% 29.92% 32.38% 100.00%
Percent negative and significant 30.33% 0.00% 0.00% 31.97% 55.74% 38.93% 18.44% 0.00% 100.00% 52.46% 0.82% 0.00% 1.64% 0.00%
Table 3.1: Linear regression results for Improved Model (3.7) using the same parameters as the Volume Order Imbalance model (2.3): k = 20, q = 0.2, L = 5. Blue cells indicate majority of the coefficients having a significant positive or negative sign. Similar to the previous results in Table 2.1, the instantaneous and lag-1 VOI remain significant positive factors as indicated by the blue cells. Furthermore, the 23
new order imbalance ratio factors are also significant at least half the time up to lag-2. More interestingly, the instantaneous order imbalance ratio has a positive relationship with price change while the lag-1 and lag-2 OIR have a negative relationship. Using this definition of order imbalance, these coefficients are consistent with the findings in Chordia [4]. Evidence of the price pressure (induced by the instantaneous OIR) reversal by the lag-1 OIR coefficient is very pronounced as they were negative and significant for every trading day. This improved linear model gives a mean daily profit of 50,369 CNY and a winratio of 92.6% compared with the previous volume order imbalance strategy with mean daily profit 19,528 CNY and win-ratio of 75.8%. A one-tailed paired t-test (H 0 : µ new − µold ≤ 0, H 1 : µ new − µold > 0) on the daily net profit gives a p-value of 1.2317 × 10 9 , a highly significant result, and thus rejecting the null hypothesis. Simply by adding new factors to the linear model to represent the price pressure and trader intentions improves the mean daily profit by over 350%. We find that volume order imbalance alone is an inadequate measure of the buying and selling pressures in the market. By including the OIR and MPB factors, we have a better understanding of trader intention as they submit orders to the market. −
3.2.3
Parameter Analysis
We consider several optimizations in both the linear regression parameters and the trading parameters. The regression coefficients for the linear models exhibit strong daily autocorrelation as seen in Figure 3.6 below.
24
Figure 3.6: ACF of spread-adjusted VOI (top-left), spread-adjusted OIR (top-right) and spread-adjusted MPB (bottom). The plots indicate the factor coefficients (the daily β i s) exhibit strong daily autocorrelation. Instead of simply using the previous day’s regression coefficients, consider using a weighted moving average of the coefficients from the past p days: p
ˆ(d) = β i
p
(d− j )
w j β i
,
j =1
w j = 1
j =1
One method to estimate the weights w j is to fit an AR(p) model to the most significant regression coefficients (OI t S t 1 , ρ t S t 1, and R t S t 1 ) and set them proportional to the AR coefficients. Another method would be to simply take the simple moving average of the past p days. We test the strategy for fixed parameters k = 20 and L = 5 using various weights for the lagged coefficients. Test results in Table 3.2 show that the 2-day simple moving average, w1 = w 2 = 0.5, performs better than having no weighted average at all, the 3-day and 4-day simple moving averages. Using weights proportional to the spreadadjusted VOI, OIR, or MPB AR(2) models does not perform any better than the 2-day simple moving average. For simplicity, we will proceed with the 2-day simple average model for the rest of this chapter. −
−
25
−
Statistical tests: one-tailed paired t-test (df = 243) H 0 : µ 2 − µj ≤ 0 H 1 : µ 2 − µj > 0 2-day 3-day 4-day OI t -AR(2) simple simple simple weighted mean daily P&L 51,713 50,749 50,753 51,305 t-stat – 2.2694 1.6865 0.9974 p-value – 0.01206 0.04649 0.1598 * in CNY ∗
ρt -AR(2)
Rt -AR(2)
weighted 51,730 -0.1631 0.5647
weighted 51,721 -0.0962 0.5383
previous day only 50,369 1.7927 0.03713
Table 3.2: Strategy results for various lagged coefficient weights and parameters k = 20, q = 0.2, L = 5. The AR(2) weights for: OI t are (0.776, 0.224), ρt are (0.531, 0.469), and Rt are (0.516, 0.484). The 2-day simple moving average performs better or just as well as the other coefficient weights. We also test the strategy using various lags for the spread-adjusted VOI and OIR variables. Since lag selection is essentially feature selection for the parametrized linear model (3.6), we attempt to choose the model with the best fit using a step-wise algorithm. The goodness-of-fit will be measured by the Akaike information criterion (AIC) and results are presented in Table 3.3 below. Additonally, the results of onetailed paired t-tests on daily profits for the various lags L = 0, 1, ..., 7 are also shown. Statistical tests: one-tailed paired t-test (df = 243) H 0 : µ L=5 − µL=j ≤ 0 H 1 : µ L=5 − µL=j > 0 lag-5 no-lag lag-1 lag-2 mean daily P&L 51,713 43,811 49,457 50,264 t-stat – 6.2299 4.4429 3.9286 p-value – < 0 .01 < 0 .01 < 0.01 AIC 19,931 20,375 20,099 20,045 * in CNY ∗
lag-3 51,091 2.0689 0.01981 19,998
lag-4 51,190 2.2251 0.0135 19,961
lag-6 51,740 -0.14 0.5556 19,905
lag-7 51,642 0.3321 0.37 19,880
Table 3.3: Strategy results for lags L = 0, 1, ..., 7 using 2-day simple moving average for coefficient weights and parameters k = 20, q = 0.2. Notice that L = 5 outperforms L = 0,.., 4 and is no different than L = 6 or 7 at the 95% confidence level. Lag-7 model has lowest AIC, highlighted in green. We see that the lag selection has a significant effect on total profit when the coefficient weights, forecast window, and trading threshold are held fixed. Lag L = 5 performs better than the no-lag, lag-1, and lag-2 models at the 99% significance level; better than the lag-3 and lag-4 models at the 95% significance level; and no different than the lag-6 and lag-7 models. Furthermore, AIC indicates that the lag7 linear model has the best fit despite having slightly lower P&L than the lag-5 model (although insignificant). This suggests that a model’s goodness-of-fit is not 26
necessarily the best indicator of strategy performance. Out of model simplicity, we will keep L = 5 as the optimal lag for VOI and OIR variables.
3.2.4
Parameter Selection Results
Given the previous analysis done for the coefficient lag and the variable lag, we can now focus on selecting the optimal forecast window and trading threshold. Optimal parameter selection is done by running the strategy on a mesh defined by q ∈ [0.13, 0.20], ∆q = 0.005 and k = 1, 2, ..., 20. We will choose the optimal k and q with the greatest mean daily profit and calculate 90%, 95%, and 99% confidence regions for the parameters by inferring directly from the confidence regions of the daily profit. The reason we choose q = 0.20 as the upper bound is because increasing the threshold will only result in less trades and lower overall profit. After fitting the linear model (3.6) with lag L = 5 over different forecast windows, we can check how well the new factors, spread-adjusted VOI, OIR, and MPB, can explain the variation in the price change by comparing the R 2. However, as mentioned in the previous chapter, we should be careful looking at the goodness-of-fit of the models since a better fit does not necessarily indicate a more profitable strategy. From Figure 3.7 below, the R2 peaks when k = 2 and decreases as the forecast window increases. We will check the performance of the strategy for various forecast windows and see whether k = 2 actually generates the most profit.
Figure 3.7: R2 for model (3.6) for forecast windows k = 1 to 20. We present a heatmap in Figure 3.8 summarizing the profits on the mesh defined by k = 1, ..., 20 q ∈ [0 .13, 0.20], ∆q = 0.005 on the following page. Darker blue cells indicate a larger average daily P&L while darker red cells denote lower P&L.
27
t r k e i n k c e r h i c a t d e ffi e e h o l i t c h y d w b n a L d e 5 & t P a c = r i e d L g n r i a g l 5 a 1 l e . t h o 0 t i n = e w d ) s q 6 l d . l e n 3 ( c a l e e u 5 d l o b = m r e k r k s i a r e a L n i l D . & e 0 P 2 y h t , . l i g . . , a n 1 d i s u = n a y k e g d m e t t n s a a e r t 2 s . g r a e 0 l , . h t . . e , h r 5 t o f 3 h 1 . t i p 0 a , w m 3 s 1 t . r a 0 e e t h = e m s s q a o h r l s a d e p n m e a e h T t h fi t . o L r r p e v & o P y l i 5 r a . e d 0 w o n = l a e e w t M = o n e : 8 . w d s . 3 s l r t l e e r h e c u i g d g e d r i o F w e r b 2
1
28
From Figure 3.8 above, we notice that the parameters with the largest mean daily profit is the pair (k, q ) = (5, 0.15) as indicated by the thick border. The linear model constructed on day d, associated with these parameters is: 5 d
∆M t,5 = β 0 +
j =0
OI t− j d β OI,j S t
5
+
j =0
d β ρ,j
ρt j Rt + β Rd + εt S t S t −
(3.8)
Revisiting the goodness-of-fit for the models in Figure 3.7, we notice that despite having a lower R2 , a forecast window of 5 performs better than the model with a higher R2 (such as k = 2). One possibility is that the linear models for k = 1, 2, or 3 may fit well for the current day but is not a good model for the following business days to be used as a trading strategy. Average coefficient
51.64%
19.67%
15.57%
4.458 × 10
4
100.00%
93.44%
0.00%
1
1.868 × 10
4
100.00%
100.00%
0.00%
1
−2.452 × 10 −6.520 × 10 −4.553 × 10
−
5
43.03%
20.08%
33.61%
5
7.38%
2.87%
79.92%
5
12.30%
1.64%
68.44%
−1.625 × 10 5 1.876 × 10 2
28.28%
7.38%
38.11%
100.00%
100.00%
0.00%
−
0.00%
0.00%
100.00%
−
0.41%
0.00%
92.21%
57.79%
19.67%
5.74%
1
OI t
2 S t
−
−
−
1
−
OI t
3 S t
OI t
4 S t
−
1
−
−
5 S t −1 −
ρt S t
1
−
ρt
1 S t
ρt
2 S t
ρt
3 S t
ρt
4 S t
−
1
−
−
1
−
−
Rt S t
−
−
−
−
−1.026 × 10 2 −1.745 × 10 3 6.243 × 10 4 −
7.960 × 10
4
76.23%
32.38%
1.23%
1
7.879 × 10
4
76.23%
33.61%
2.87%
8.228 × 10
2
100.00%
99.18%
0.00%
−
5 S t −1
−
−
1
−
−
ρt
1
−
OI t
−
−
−
1 S t
Percent negative and significant
4
−
OI t
Percent positive and significant
3.088 × 10
Intercept OI t S t
Percent positive
−
−
−
Table 3.4: Linear Regression Results for Improved Model (3.8) using the optimal parameters: k = 5, q = 0.15, L = 5, w1 = 1. Blue cells indicate majority of the coefficients having a significant positive or negative sign. Table 3.4 above shows the average coefficients for model (3.8) with k = 5, which are comparable to the coefficients presented in Table 3.1 for model (3.7) with k = 20. The only difference between the two models is the forecast window in the response variable. However, we immediately see that the significance of the 3rd and 4th lag of the VOI factor and the 2nd lag of the OIR factor is more prominent – the coefficient is 29
negative and significant for a larger proportion of the year. Lastly, using model (3.8), the correlation between the actual and predicted price change is 0.434 and using the predicted price change as a trinomial class variable, the correlation is 0.758, giving very large improvements from the correlations in model (2.3). The results of the trading strategy with using the linear model (3.8) and trading parameters q = 0.15, w = (0.5, 0.5) is summarized in Table 3.5 below. The full results of this trading strategy can be found in appendix A.3. Statistical test: one-tailed, one-sample t-test (df = 243) H 0 : µ ≥ 0 H 1 : µ < 0 Mean daily Standard t-stat p-value Days with profit (CNY) error profit 12 58,600 8,091 7.2431 2.886 × 10 231 Average Daily Sharpe Ratio: 0.464 Annualized Sharpe Ratio: 7.243 −
Days with losses 12
Average daily trade volume 1,798
Table 3.5: Trading strategy results using improved linear model For every parameter pair (k, q ), we perform the following paired one-tailed t-test to find the confidence perimeter: H 0 : µ 5,0.15 − µk,q ≤ 0
(3.9)
H 1 : µ 5,0.15 − µk,q > 0
By calculating the t-statistic and p-value for every mesh point, we can find a perimeter in which the result becomes statistically insignificant at the 90%, 95%, and 99% confidence levels. We would thereby obtain the (k, q ) pairs that form this confidence perimeter and conclude that the true maximum mean daily profit occurs when (k, q ) lies entirely within the perimeter. The heatmap for the 90%, 95%, and 99% confidence regions are shown in Figure 3.9 below. The red cell is the benchmark at which we apply the above paired t-test (3.9) to the daily profits. The darkest blue cells represent the parameter pair at which we cannot reject the null hypothesis at the 99% confidence level. Similarly, the medium blue cells represent the 95% confidence level, and the lightest blue cells represent the 90% confidence level.
30
. e 0 5 . e c c 0 n n 2 e e o d d t = fi fi 3 n n w o o c c m o = r % f % 9 9 – w 9 9 s d e l a t v h h n a t r g e i , t t e % a n w 5 i e t 9 n g n , e r v e e a i % l c 0 t 9 a a ffi e e h s o h t a c e h T t , h o r . t e i y N v w g e . e ) t y w a 6 o r l . t e h 3 v , ( s i l t l w e a c o e d i d m p o t s i n m p e r w r o l s t a s s e l e t e a n c c i a e l c e i u r o e d l f h n t i b e h g l l k r T e n i a . s c d u d 6 e 1 . y R d n 0 g e . a d t , n 0 e a 2 r , u a t s . . . l b 5 3 , e 1 1 . h m 0 t u i n r = d o k e e f e d w p n m t a a , e m 2 e u b t . l a 0 b s e e i h , . . . t l h , g q n 5 i d o 3 l i l g 1 o . y h e b r 0 s , e e d r 3 c 1 e h n . t t e 0 n l e d a fi = s m r i n q e o p t e C h s r p o e : e e 9 . m r h a t 3 e , h s n e r t n o o u r i i g e g g i v F o e r e r 2
1
31
Based on the heatmap above, we find that the maximum daily profit can occur: At the 90% confidence level, for parameters 5 ≤ k ≤ 19 and 0.14 ≤ q ≤ 0.155 At the 95% confidence level, for parameters 4 ≤ k ≤ 20 and 0.14 ≤ q ≤ 0.16 At the 99% confidence level, for parameters 3 ≤ k ≤ 20 and 0.135 ≤ q ≤ 0.16. Although this optimization method is not ideal since changing the lag L on the VOI and OIR variables or changing the coefficient weights w j can impact the selection of the forecast window and trading threshold. But based on the some preliminary test results (see appendix B for details), for lags L = 2, L = 3, and L = 4 the optimal parameters (k, q ) are (5, 0.15), (6, 0.15), and (9, 0.15) respectively. As these parameters lie in our 95% confidence region for the lag-5 results in Figure 3.9 above, we cannot reject the null hypothesis and can only concude that lag-selection does not statistically impact the choice of k and q . As our strategy is highly successful and each trade execution generates positive profit on average, these parameter results make sense. We cannot expect to earn a greater profit by increasing the trading threshold as it would only decrease the amount of trades we make. Although economically speaking, decreasing the threshold to less than 0.2 means that we could potentially sell below buy price, it seems our signal is strong enough such that even if we forecast a 0.15 mid-price change, the actual midprice change is often greater. We find that for k = 5, on average 60% of mid-price changes greater than 0.15 are also greater than 0.20. By decreasing the threshold to 0.15, the strategy trades more often and thus generates a larger profit.
3.3
Summary and Final Considerations
The additional factors OIR and MPB and the spread adjustment to all factors have improved the daily profit by over 350% to 50,369 CNY and the win ratio by nearly 17% compared to the original strategy using the volume order imbalance model (2.3). The model and strategy is then further improved by selecting the optimal regression and trading parameters. First, we found that due to the strong positive autocorrelation of the daily coefficients of the linear model, using a 2-day simple moving average had a statistically significant increase in profit. We also found that the lag-5 model on VOI and OIR was the simplest model that significantly outperformed others. Lastly, for the remaining parameters, we showed a confidence region in which the optimal forecast window and trading threshold could lie at the 90%, 95% and 99% level. The 32
optimal parameters were found to be around k = 5 and q = 0.15 giving an average daily profit of 58,600 CNY. Finally, we saw a large improvement in the correlation between the actual price change and the predicted price change confirming that this strategy makes the correct trade more often. There are still many important considerations that must be taken into account to verify the validity of this strategy. Of the assumptions stated in section 2.2, (a) and (b) are not completely realistic. The financial markets are not devoid of competing traders so the assumption of always being able to take the best counterparty price (sell at bid, buy at ask) is not valid. It is unlikely that we will always be able to take the best counterparty price for every trading signal we receive. Although computers are able to receive market data, compute the trading signal using the model coefficients, and make a trading decision within milliseconds, by the time the order is sent back to the exchange, the actual execution price might already have changed. Even executing a few milliseconds earlier can result in more profitable trades [14]. We could improve the accuracy of this trading simulation by assuming we are able to take the counterparty price 50% of the time or building a program to model our competitors in the markets. Finally, we ask whether this strategy can be tricked by our competitors. Given that order imbalance is not an unknown technique as a trading strategy, there will be firms who will try to take advantage of traders using this trading signal. By looking carefully at the three factors we use to generate our trading signal: volume order imbalance (VOI), order imbalance ratio (OIR), and mid-price basis (MPB), we find that VOI and OIR heavily rely on the volume of the best bid and best ask prices. Competitors can manipulate these figures by quickly submitting a large buy or sell limit order and cancelling immediately after. If our trading algorithm picks up a large bid or ask volume due to the competitor’s spoofing technique, we would incorrectly calculate a large order imbalance (both VOI and OIR) and end up trading on a signal that is falsely generated. We will not be covering the topic of making the trading algorithm more robust to handle competitor spoofing as it is not within the scope of this paper.
33
Chapter 4 Conclusions We first introduced the area of high frequency trading and the data that will be used to test the trading strategy. By examining order imbalance, a measure of the difference in size of buy and sell orders in the market, we developed a simple trading strategy by fitting a linear model using ordinary least squares against a 20 time-step (10 second) average price change. We have shown that the strategy, using this linear model to forecast future price changes and trading when the forecast is greater than 0.2 ticks, is highly profitable. However, after some analysis was done on the profits made by the strategy, we found much of it was strongly positively correlated with the total trading volume in the market. We further improved on this trading signal by extending the linear model to include 2 new factors: order imbalance ratio, a measure of the degree of imbalance, and the mid-price basis, a mean-reverting process. All three factors were also adjusted by dividing by the bid-ask spread as we found that on most days, large spreads indicated low price changes. Lastly, we determined a confidence interval for the optimal regression and trading parameters: the forecast window for the average price change and the trading threshold and found that they were closer to 5 and 0.15 respectively.
4.1
Further Work
There are several areas of research that may improve the robustness and profitability of this trading strategy. We outline two ideas below. The study by Cont [5] analyzed the relationship between order flow imbalance and intraday volatility (diurnal). They found that the market depth during the 30 minutes after market open is quite shallow meaning that orders submitted by traders during that time can have a large impact on price movement. However, Huang [7] also attempted find a relationship between order imbalance and volatility by using 34
GARCH(1,1) but they found no such relationship. As these results appear to be inconsistent, this area can be explored further and either be used to enhance our existing signal or used to create another trading signal. Further model enhancements could also be done. In addition to linear regressors, we could model the response variable (k-step average price change) with a time-series AR(k + 1) model. Preliminary results indicate that the both the autocorrelation and partial autocorrelation in the response is significant past k + 1 lags meaning we could potentially use the lag-(k + 1) term as a feature in our model. The reason we cannot choose lags 1,...,k is because those are not known by the time the market data is received since the response depends on data k-steps ahead. Lastly, we may want to use more sophisticated statistical techniques to do model selection, including machine learning or lasso regression while bearing in mind that a better statistical model does not necessarily translate to better profits. The final suggestion would be to apply machine learning techniques to make trading decisions. As mentioned in the previous chapters, the predicted price change was essentially a trinomial classifier for the trading strategy based on the trading threshold q . We can take advantage of the high correlation between the trinomial variable and the actual price change. Instead of using the linear model to forecast a continuous variable, we could apply one of several machine learning techniques to build a trinomial classifier, such as logistic regression, support vector machines, or random forests. However, given the vast amount of data in high frequency trading, it would be important to split the data into training and testing sets to ensure the trading strategy does not make decisions using an overfitted classifier.
35
Bibliography [1] Irene Aldridge. High-Frequency Trading: A Practical Guide to Algorithmic Strategies and Trading Systems . John Wiley & Sons, Inc, 2010. [2] Am´ elie Charles and Olivier Darn´e. Variance ratio tests of random walk: An overview. Journal of Economic Surveys , 23(3):503–527, 2009. [3] Tarun Chordia, Richard Roll, and Avanidhar Subrahmanyam. Order imbalance, liquidity, and market returns. Journal of Financial Economics , 65:111–130, 2002. [4] Tarun Chordia and Avanidhar Subrahmanyam. Order imbalance and individual stock returns: Theory and evidence. Journal of Financial Economics , 72:485– 518, 2004. [5] Rama Cont, Arseniy Kukanov, and Sasha Stoikov. The price impact of order book events. Journal of Financial Econometrics , 12(1):47–88, 2014. [6] Martin D. Gould, Mason A. Porter, Stacy Williams, Mark McDonald, Daniel J. Fenn, and Sam D. Howison. Limit order books. Quantitative Finance , 13(11):1709–1742, 2013. [7] Han-Ching Huang, Yong-Chern Su, and Yi-Chun Liu. The performance of imbalance-based trading strategy on tender offer announcement day. Investment Management and Financial Innovations , 11(2):38–46, 2014. [8] Jonathan Karpoff. The relation between price changes and trading volume: A survey. Journal of Financial and Quantitative Analysis , 22(1):109–126, 1987. [9] Charles M.C. Lee and Mark J. Ready. Inferring trade direction from intraday data. The Journal of Finance , 46:733–747, 1991. [10] Xuan Liu. Stationary processes and hft. Master’s thesis, University of Oxford, 2015.
36
[11] Rahul Ravi and Yuqing Sha. Autocorrelated Order-Imbalance and Price Momentum in the Stock Market. International Journal of Economics and Finance , 6(10):39–54, 2014. [12] Ruey S. Tsay. Analysis of Financial Time Series . John Wiley & Sons, Inc, 2010. [13] Geroge H.K. Wang and Jot Yau. Trading volume, bid-ask spread, and price volatility in futures markets. Journal of Futures Markets , 20(10):943–970, 2000. [14] Zhaodong Wang and Weian Zheng. High-Frequency Trading and Probability Theory . World Scientific Publishing Co. Pte. Ltd, 2015.
37
Appendix A Daily Strategy P&L A.1
Volume Order Imbalance Strategy P&L: Main Contract Total days with profit: 185 Total days with losses: 58 Average Daily Sharpe Ratio: 0.380 Annualized Sharpe Ratio: 5.935 * all numbers reported in CNY Average: 10,078 9,449 Date Morning Afternoon 2014-01-02 0 0 2014-01-03 8057 2326 2014-01-06 -90 -161 2014-01-07 9535 -291 2014-01-08 12836 596 2014-01-09 6700 4697 2014-01-10 13036 6157 2014-01-13 -2700 9286 2014-01-14 1106 -4556 2014-01-15 -1164 27 2014-01-16 7923 140 2014-01-17 -3760 -659 2014-01-20 -6270 763 2014-01-21 -3411 -2593 2014-01-22 10460 -2965 2014-01-23 -4730 198 2014-01-24 -2211 2062 2014-01-27 -2004 -1011 2014-01-28 329 557 2014-01-29 -2910 -2231 2014-01-30 3294 7675 2014-02-07 -4544 7677 2014-02-10 13129 3071 2014-02-11 12940 -4032 2014-02-12 1965 -1259
19,528 Total P&L 0 10383 -251 9245 13432 11396 19193 6586 -3450 -1137 8063 -4419 -5507 -6004 7495 -4532 -149 -3015 887 -5141 10969 3134 16200 8908 706
38
634 Trade Volume 0 198 296 500 310 456 502 414 372 94 96 206 332 298 240 180 62 166 198 124 98 174 220 206 92
68.78 Commissions 0 17.09 24.96 41.98 26.14 38.42 41.74 34.27 30.75 7.78 7.98 17 27.23 24.62 20.12 15.16 5.24 13.88 16.57 10.41 8.16 14.33 18.6 17.56 7.87
Date 2014-02-13 2014-02-14 2014-02-17 2014-02-18 2014-02-19 2014-02-20 2014-02-21 2014-02-24 2014-02-25 2014-02-26 2014-02-27 2014-02-28 2014-03-03 2014-03-04 2014-03-05 2014-03-06 2014-03-07 2014-03-10 2014-03-11 2014-03-12 2014-03-13 2014-03-14 2014-03-17 2014-03-18 2014-03-19 2014-03-20 2014-03-21 2014-03-24 2014-03-25 2014-03-26 2014-03-27 2014-03-28 2014-03-31 2014-04-01 2014-04-02 2014-04-03 2014-04-04 2014-04-08 2014-04-09 2014-04-10 2014-04-11 2014-04-14 2014-04-15 2014-04-16 2014-04-17 2014-04-18 2014-04-21 2014-04-22 2014-04-23 2014-04-24 2014-04-25
Morning -4668 -1139 5193 -1074 943 12420 -1761 4433 2765 8192 5483 -277 11857 5003 7905 10695 14930 4806 14284 11208 14250 4275 7915 1168 -309 13660 -1758 9340 12579 3525 -7230 10408 759 5807 1348 -1798 4123 12831 -3002 -2806 1392 2719 5317 9684 5449 12421 19988 4348 10467 1030 -3741
Afternoon -6092 -582 -789 -890 612 -2303 -2085 6251 21149 -6909 7887 10546 -4360 5718 6406 6876 -982 3913 -3952 7963 10062 -1355 -1087 -5225 -1105 8437 43880 9276 3554 2412 14603 6301 8403 4816 4234 1469 -1440 14901 -335 6943 521 2738 -7489 4378 274 2215 5626 10778 3315 -1490 1524
Total P&L -10760 -1722 4403 -1964 1555 10117 -3846 10684 23914 1284 13371 10270 7496 10721 14310 17571 13948 8720 10332 19171 24312 2920 6828 -4057 -1414 22097 42122 18617 16133 5937 7373 16709 9162 10623 5582 -329 2683 27732 -3337 4137 1912 5456 -2172 14062 5723 14636 25614 15126 13782 -461 -2216
39
Trade Volume 152 34 16 90 244 356 328 94 454 550 606 520 546 406 428 516 672 422 888 574 736 482 148 924 86 358 662 1202 602 312 324 526 574 334 310 156 248 244 376 170 324 180 154 324 124 224 780 502 250 222 172
Commissions 13 2.91 1.38 7.72 21.02 30.72 27.93 7.78 37.33 44.28 48.95 41.95 44.42 32.79 34.65 41.45 54.46 33.2 69.24 44.85 58.14 37.9 11.76 73.68 6.77 28.12 52.19 96.82 48.63 25.22 26.13 42.45 46.29 26.98 25.19 12.74 20.18 20.34 31.69 14.41 27.64 15.32 12.96 27.19 10.39 18.62 64.83 41.07 20.49 18.2 14.08
Date 2014-04-28 2014-04-29 2014-04-30 2014-05-05 2014-05-06 2014-05-07 2014-05-08 2014-05-09 2014-05-12 2014-05-13 2014-05-14 2014-05-15 2014-05-16 2014-05-19 2014-05-20 2014-05-21 2014-05-22 2014-05-23 2014-05-26 2014-05-27 2014-05-28 2014-05-29 2014-05-30 2014-06-03 2014-06-04 2014-06-05 2014-06-06 2014-06-09 2014-06-10 2014-06-11 2014-06-12 2014-06-13 2014-06-16 2014-06-17 2014-06-18 2014-06-19 2014-06-20 2014-06-24 2014-06-25 2014-06-26 2014-06-27 2014-06-30 2014-07-01 2014-07-02 2014-07-03 2014-07-04 2014-07-07 2014-07-08 2014-07-09 2014-07-10 2014-07-11
Morning -3206 -2364 -1196 5512 -307 123 9487 446 -55 -6729 -4538 -267 -6534 5700 3862 4097 20447 -1810 5337 3460 1507 -1943 1662 1906 3038 -2346 3631 -7626 7686 -2102 84 3450 -385 -6599 -1418 -2996 124 -1522 3565 1290 -584 6719 6648 1813 2045 -305 4060 816 -76 -164 649
Afternoon 2103 525 1998 5354 -475 2104 2975 907 3738 -3831 1610 -2230 -3717 3567 -6583 311 -1625 3948 -2935 3572 1863 -234 -5558 1598 -403 1932 6293 3797 8758 -3723 -696 2237 2090 -3032 525 2785 4635 -11 1123 3184 4278 -554 587 3327 -1769 -875 1480 1065 4567 -416 1777
Total P&L -1103 -1839 802 10866 -782 2227 12462 1353 3684 -10560 -2928 -2496 -10250 9267 -2721 4408 18823 2138 2402 7033 3371 -2177 -3896 3504 2635 -414 9924 -3829 16444 -5825 -612 5687 1705 -9630 -893 -211 4759 -1533 4689 4474 3695 6164 7236 5140 276 -1179 5540 1881 4491 -581 2426
40
Trade Volume 366 352 32 22 334 216 262 264 338 372 14 62 108 120 324 222 290 306 134 152 152 212 48 58 102 116 100 198 410 428 64 60 196 68 18 88 160 126 120 226 110 90 150 120 90 80 32 32 86 40 88
Commissions 29.52 28.39 2.59 1.77 27.01 17.36 21.09 21.13 27.48 30.3 1.14 4.98 8.65 9.47 25.61 17.56 23.19 24.41 10.79 12.24 12.25 17.18 3.88 4.68 8.12 9.27 7.98 15.85 32.98 34.52 5.16 4.87 16.08 5.55 1.46 7.05 12.81 10.06 9.56 18.13 8.83 7.28 12.12 9.7 7.32 6.5 2.6 2.59 6.94 3.2 7.07
Date 2014-07-14 2014-07-15 2014-07-16 2014-07-17 2014-07-18 2014-07-21 2014-07-22 2014-07-23 2014-07-24 2014-07-25 2014-07-28 2014-07-29 2014-07-30 2014-07-31 2014-08-01 2014-08-04 2014-08-05 2014-08-06 2014-08-07 2014-08-08 2014-08-11 2014-08-12 2014-08-13 2014-08-14 2014-08-15 2014-08-18 2014-08-19 2014-08-20 2014-08-21 2014-08-22 2014-08-25 2014-08-26 2014-08-27 2014-08-28 2014-08-29 2014-09-01 2014-09-02 2014-09-03 2014-09-04 2014-09-05 2014-09-09 2014-09-10 2014-09-11 2014-09-12 2014-09-15 2014-09-16 2014-09-17 2014-09-18 2014-09-19 2014-09-22 2014-09-23
Morning -881 -3649 -3385 -2806 -1570 -366 4317 1855 5924 1500 16003 6392 12254 6306 5976 10986 6223 1037 12195 3775 9443 538 11373 4091 5323 14154 8861 -2378 2600 246 2405 7947 1435 -1152 -630 4491 -1891 1507 -4454 1268 4737 -2743 8620 1424 1476 7676 -4537 10991 10407 4820 3547
Afternoon 114 -2864 1103 1016 -2160 -1570 3043 453 -51 6324 1120 7479 -6086 -828 19497 6686 8460 4490 12035 2180 204 750 -2036 7657 2288 585 1455 3835 2102 5054 4093 77 -908 1692 -844 -2154 6617 366 8452 -1153 7125 340 9644 6222 158 5616 950 139 1454 7272 8860
Total P&L -766 -6513 -2283 -1791 -3730 -1936 7360 2308 5873 7824 17123 13871 6168 5479 25473 17672 14683 5527 24230 5955 9647 1288 9337 11748 7612 14739 10316 1457 4702 5299 6498 8024 528 540 -1474 2337 4726 1874 3998 115 11862 -2402 18264 7646 1634 13292 -3587 11129 11861 12092 12407
41
Trade Volume 40 76 26 18 256 64 60 188 130 340 288 946 374 344 262 654 648 556 364 444 258 420 178 380 406 526 398 222 254 192 264 216 134 120 108 92 146 208 318 212 232 174 146 568 134 196 176 360 268 548 500
Commissions 3.23 6.17 2.11 1.45 20.75 5.18 4.9 15.46 10.83 28.68 25.08 83.04 32.76 30.21 23.24 58.04 57.68 49.16 32.15 38.93 22.86 37.06 15.71 33.66 36.04 46.91 35.42 19.72 22.39 17 23.31 18.98 11.76 10.5 9.47 8.11 12.97 18.83 28.91 19.52 21.39 15.91 13.38 51.77 12.23 17.84 15.84 32.55 24.4 49.34 45.07
Date 2014-09-24 2014-09-25 2014-09-26 2014-09-29 2014-09-30 2014-10-08 2014-10-09 2014-10-10 2014-10-13 2014-10-14 2014-10-15 2014-10-16 2014-10-17 2014-10-20 2014-10-21 2014-10-22 2014-10-23 2014-10-24 2014-10-27 2014-10-28 2014-10-29 2014-10-30 2014-10-31 2014-11-03 2014-11-04 2014-11-05 2014-11-06 2014-11-07 2014-11-10 2014-11-11 2014-11-12 2014-11-13 2014-11-14 2014-11-17 2014-11-18 2014-11-19 2014-11-20 2014-11-21 2014-11-24 2014-11-25 2014-11-26 2014-11-27 2014-11-28 2014-12-01 2014-12-02 2014-12-03 2014-12-04 2014-12-05 2014-12-08 2014-12-09 2014-12-10
Morning 8679 2781 5739 3378 -169 -6806 5121 536 3435 1881 4390 1164 4797 1944 7242 3524 2267 1857 3165 -3318 2521 2282 4961 2905 907 -4212 111 3541 9412 17337 -560 657 671 5929 3800 -795 -1726 8343 15880 -1434 18841 8690 3060 20810 13856 168577 116192 217004 108507 132763 239180
Afternoon 2806 16183 4892 5742 -1790 5460 804 2152 614 3175 6941 1668 11118 4025 1510 -1353 3634 2782 -3080 1354 -1732 4636 15194 2466 1157 -3837 2211 10257 4139 17112 3614 -3074 9517 8176 3194 -725 -4571 9881 9317 12914 13285 17374 34733 23580 73994 82763 128421 113837 101458 222644 104059
Total P&L 11484 18963 10631 9120 -1959 -1346 5925 2688 4048 5056 11331 2833 15915 5969 8751 2171 5901 4639 86 -1964 789 6918 20154 5372 2064 -8049 2322 13798 13551 34450 3054 -2417 10188 14106 6994 -1519 -6297 18224 25197 11480 32126 26064 37793 44390 87850 251340 244613 330841 209965 355407 343239
42
Trade Volume 360 572 636 486 230 196 278 250 146 372 128 256 516 194 180 196 98 112 86 252 114 220 292 430 158 112 100 254 730 698 866 408 428 322 726 86 280 228 608 1102 590 914 686 1214 1280 2196 4540 3340 6230 5554 6188
Commissions 32.88 53.08 58.44 44.7 21.2 18.13 25.88 23.16 13.36 34.12 11.75 23.64 47.32 17.85 16.54 17.95 8.9 10.11 7.67 22.72 10.45 20.31 27.33 40.64 14.88 10.54 9.39 24.01 69.35 67.15 83.13 39.38 41.16 31.17 69.43 8.2 26.68 21.98 60.61 111.2 60.47 94.08 71.13 128.45 137.65 247.2 524.73 398.69 755.27 693.47 748.91
Date 2014-12-11 2014-12-12 2014-12-15 2014-12-16 2014-12-17 2014-12-18 2014-12-19 2014-12-22 2014-12-23 2014-12-24 2014-12-25 2014-12-26 2014-12-29 2014-12-30 2014-12-31
Morning 55994 82522 5708 77784 67746 25066 57666 42810 19916 52519 12081 53049 71137 82006 2867
Afternoon 81541 27095 -15445 28768 21052 107545 77215 95357 49924 54053 67774 94586 36480 48640 23121
Total P&L 137535 109618 -9737 106552 88798 132610 134881 138167 69840 106572 79855 147635 107616 130646 25987
Trade Volume 7358 5136 3418 2414 1842 3274 4444 3744 4726 3626 4084 3532 4022 4372 3998
Commissions 890.62 623.11 411.68 296.44 230.11 428.35 577.8 488.17 604.8 444.84 504.92 452.82 532.92 571.67 528.86
Table A.1: Daily P&L results for volume order imbalance strategy trading main futures contract. Pink cells indicate a loss during the session or entire day.
A.2
Volume Order Imbalance Strategy P&L: Secondary Contract Total days with profit: 119 Total days with losses: 99 Average Daily Sharpe Ratio: 0.113 Annualized Sharpe Ratio: 1.763 * all numbers reported in CNY Average: 1,339 1,462 Date Morning Afternoon 2014-01-02 0 0 2014-01-03 7225 325 2014-01-06 14546 -574 2014-01-07 -9824 473 2014-01-08 2325 2453 2014-01-09 5932 5306 2014-01-10 0 0 2014-01-13 227 2508 2014-01-14 -3400 113 2014-01-15 -2426 2301 2014-01-16 -33 1580 2014-01-17 9621 -551 2014-01-20 -5750 -2242 2014-01-21 -3411 -2593 2014-01-22 10460 -2965 2014-01-23 -4730 198 2014-01-24 -2211 2062
2,801 Total P&L 0 7551 13972 -9351 4778 11239 0 2735 -3286 -126 1546 9070 -7992 -6004 7495 -4532 -149
43
255 Trade Volume 0 4 4 28 12 6 0 34 10 22 8 14 286 298 240 180 62
28.22 Commissions 0 0.35 0.34 2.36 1.01 0.51 0 2.82 0.83 1.83 0.67 1.15 23.46 24.62 20.12 15.16 5.24
Date 2014-01-27 2014-01-28 2014-01-29 2014-01-30 2014-02-07 2014-02-10 2014-02-11 2014-02-12 2014-02-13 2014-02-14 2014-02-17 2014-02-18 2014-02-19 2014-02-20 2014-02-21 2014-02-24 2014-02-25 2014-02-26 2014-02-27 2014-02-28 2014-03-03 2014-03-04 2014-03-05 2014-03-06 2014-03-07 2014-03-10 2014-03-11 2014-03-12 2014-03-13 2014-03-14 2014-03-17 2014-03-18 2014-03-19 2014-03-20 2014-03-21 2014-03-24 2014-03-25 2014-03-26 2014-03-27 2014-03-28 2014-03-31 2014-04-01 2014-04-02 2014-04-03 2014-04-04 2014-04-08 2014-04-09 2014-04-10 2014-04-11 2014-04-14 2014-04-15
Morning -2004 329 -2910 3294 -1953 0 0 -1029 0 26 0 1217 -5211 -902 -3694 -4400 2765 8192 5483 -277 687 -5857 -351 0 -1295 -4292 -9302 441 -9328 -1871 0 854 1109 -11827 -1417 3592 12579 3525 -7230 10408 759 0 -3532 -873 -6365 1335 -3221 -1414 -5014 -4722 0
Afternoon -1011 557 -2231 7675 -4093 0 0 0 1166 0 0 1714 2106 3326 1529 -2015 21149 -6909 7887 10546 0 3983 -125 -1357 -3171 0 0 -5120 -4449 706 0 -5392 5369 4949 10695 -918 3554 2412 14603 6301 8403 0 -3882 0 -1385 -3155 0 -6454 -1414 1046 0
Total P&L -3015 887 -5141 10969 -6046 0 0 -1029 1166 26 0 2931 -3105 2424 -2166 -6415 23914 1284 13371 10270 687 -1874 -476 -1357 -4465 -4292 -9302 -4679 -13777 -1165 0 -4538 6477 -6878 9279 2675 16133 5937 7373 16709 9162 0 -7414 -873 -7750 -1820 -3221 -7868 -6428 -3676 0
44
Trade Volume 166 198 124 98 10 0 0 4 2 2 0 18 34 16 18 152 454 550 606 520 2 12 22 6 46 2 4 100 48 40 0 44 4 10 24 266 602 312 324 526 574 0 28 2 8 30 6 4 4 8 0
Commissions 13.88 16.57 10.41 8.16 0.83 0 0 0.34 0.17 0.17 0 1.55 2.93 1.38 1.53 12.57 37.33 44.28 48.95 41.95 0.16 0.97 1.78 0.49 3.73 0.16 0.31 7.79 3.78 3.12 0 3.49 0.31 0.79 1.91 21.43 48.63 25.22 26.13 42.45 46.29 0 2.27 0.16 0.65 2.5 0.5 0.34 0.34 0.68 0
Date 2014-04-16 2014-04-17 2014-04-18 2014-04-21 2014-04-22 2014-04-23 2014-04-24 2014-04-25 2014-04-28 2014-04-29 2014-04-30 2014-05-05 2014-05-06 2014-05-07 2014-05-08 2014-05-09 2014-05-12 2014-05-13 2014-05-14 2014-05-15 2014-05-16 2014-05-19 2014-05-20 2014-05-21 2014-05-22 2014-05-23 2014-05-26 2014-05-27 2014-05-28 2014-05-29 2014-05-30 2014-06-03 2014-06-04 2014-06-05 2014-06-06 2014-06-09 2014-06-10 2014-06-11 2014-06-12 2014-06-13 2014-06-16 2014-06-17 2014-06-18 2014-06-19 2014-06-20 2014-06-24 2014-06-25 2014-06-26 2014-06-27 2014-06-30 2014-07-01
Morning 9965 1820 -26 4839 4348 10467 1030 -3741 -3206 -2364 -1196 0 0 -5808 -9309 -692 6443 422 0 1495 0 -1829 3862 4097 20447 -1810 5337 3460 1507 -1943 1662 0 2068 0 0 1768 5144 -4657 0 6268 747 87 0 -725 1648 -1703 3565 1290 -584 6719 0
Afternoon -3989 3712 -1193 2186 10778 3315 -1490 1524 2103 525 1998 0 0 -2268 5188 0 862 1144 -3905 203 868 -324 -6583 311 -1625 3948 -2935 3572 1863 -234 -5558 0 -1892 0 2456 -572 -3187 628 0 0 -4506 0 0 0 -1491 2712 1123 3184 4278 -554 0
Total P&L 5976 5532 -1219 7026 15126 13782 -461 -2216 -1103 -1839 802 0 0 -8076 -4121 -692 7305 1566 -3905 1698 868 -2153 -2721 4408 18823 2138 2402 7033 3371 -2177 -3896 0 177 0 2456 1196 1957 -4029 0 6268 -3758 87 0 -725 157 1009 4689 4474 3695 6164 0
45
Trade Volume 30 96 30 90 502 250 222 172 366 352 32 0 0 36 10 2 12 44 4 10 2 68 324 222 290 306 134 152 152 212 48 0 4 0 4 4 50 8 0 2 6 2 0 4 54 42 120 226 110 90 0
Commissions 2.52 8.04 2.49 7.47 41.07 20.49 18.2 14.08 29.52 28.39 2.59 0 0 2.88 0.8 0.16 0.97 3.57 0.32 0.81 0.16 5.37 25.61 17.56 23.19 24.41 10.79 12.24 12.25 17.18 3.88 0 0.32 0 0.32 0.32 4.01 0.64 0 0.16 0.49 0.16 0 0.32 4.31 3.36 9.56 18.13 8.83 7.28 0
Date 2014-07-02 2014-07-03 2014-07-04 2014-07-07 2014-07-08 2014-07-09 2014-07-10 2014-07-11 2014-07-14 2014-07-15 2014-07-16 2014-07-17 2014-07-18 2014-07-21 2014-07-22 2014-07-23 2014-07-24 2014-07-25 2014-07-28 2014-07-29 2014-07-30 2014-07-31 2014-08-01 2014-08-04 2014-08-05 2014-08-06 2014-08-07 2014-08-08 2014-08-11 2014-08-12 2014-08-13 2014-08-14 2014-08-15 2014-08-18 2014-08-19 2014-08-20 2014-08-21 2014-08-22 2014-08-25 2014-08-26 2014-08-27 2014-08-28 2014-08-29 2014-09-01 2014-09-02 2014-09-03 2014-09-04 2014-09-05 2014-09-09 2014-09-10 2014-09-11
Morning 0 0 0 0 0 0 -692 0 -332 0 0 -402 -3937 -2119 4317 1855 5924 1500 16003 6392 12254 6306 -756 -1624 -2993 -834 -5073 -4669 -897 -6809 6692 5555 -326 4973 8861 -2378 2600 246 2405 7947 1435 -1152 -630 0 -731 8362 -1358 -4851 715 3263 6664
Afternoon 0 -1293 0 0 0 0 -692 0 -605 -1597 0 -2792 -1208 -37 3043 453 -51 6324 1120 7479 -6086 -828 -13776 -1187 -3282 3123 1998 -2547 2377 -2610 -6626 -1221 -3411 -2588 1455 3835 2102 5054 4093 77 -908 1692 -844 0 -6791 1344 5031 3867 -6167 0 5830
Total P&L 0 -1293 0 0 0 0 -1384 0 -937 -1597 0 -3194 -5145 -2156 7360 2308 5873 7824 17123 13871 6168 5479 -14531 -2810 -6275 2290 -3076 -7217 1480 -9419 66 4334 -3737 2385 10316 1457 4702 5299 6498 8024 528 540 -1474 0 -7522 9705 3673 -984 -5452 3263 12494
46
Trade Volume 0 2 0 0 0 0 4 0 6 6 0 12 36 22 60 188 130 340 288 946 374 344 4 50 86 40 82 76 18 44 64 40 52 650 398 222 254 192 264 216 134 120 108 0 18 14 42 24 32 2 22
Commissions 0 0.16 0 0 0 0 0.32 0 0.49 0.49 0 0.97 2.92 1.78 4.9 15.46 10.83 28.68 25.08 83.04 32.76 30.21 0.36 4.45 7.68 3.55 7.28 6.68 1.6 3.89 5.67 3.53 4.59 57.97 35.42 19.72 22.39 17 23.31 18.98 11.76 10.5 9.47 0 1.61 1.27 3.83 2.22 2.96 0.18 2.03
Date 2014-09-12 2014-09-15 2014-09-16 2014-09-17 2014-09-18 2014-09-19 2014-09-22 2014-09-23 2014-09-24 2014-09-25 2014-09-26 2014-09-29 2014-09-30 2014-10-08 2014-10-09 2014-10-10 2014-10-13 2014-10-14 2014-10-15 2014-10-16 2014-10-17 2014-10-20 2014-10-21 2014-10-22 2014-10-23 2014-10-24 2014-10-27 2014-10-28 2014-10-29 2014-10-30 2014-10-31 2014-11-03 2014-11-04 2014-11-05 2014-11-06 2014-11-07 2014-11-10 2014-11-11 2014-11-12 2014-11-13 2014-11-14 2014-11-17 2014-11-18 2014-11-19 2014-11-20 2014-11-21 2014-11-24 2014-11-25 2014-11-26 2014-11-27 2014-11-28
Morning -1042 8577 -4130 -2725 3204 -2413 -2766 3547 8679 2781 5739 3378 -169 0 2745 0 4043 1856 7583 -3111 1544 -1696 7242 3524 2267 1857 3165 -3318 2521 2282 4961 -2754 -998 -2618 -1553 2555 -294 5980 -1800 -4758 1157 12965 1093 501 0 4522 0 -6480 478 -11437 0
Afternoon -2523 -2473 935 -721 1464 -1263 4285 8860 2806 16183 4892 5742 -1790 -2797 1103 0 -1190 -5343 2372 0 -2262 -1241 1510 -1353 3634 2782 -3080 1354 -1732 4636 15194 0 -653 -938 -7215 4652 4136 -3885 -3376 -1535 2610 -6487 -2058 2050 0 -175 0 -15298 8277 -3344 -12222
Total P&L -3565 6104 -3195 -3446 4668 -3676 1519 12407 11484 18963 10631 9120 -1959 -2797 3848 0 2853 -3488 9956 -3111 -718 -2937 8751 2171 5901 4639 86 -1964 789 6918 20154 -2754 -1651 -3555 -8768 7207 3842 2095 -5176 -6292 3767 6478 -964 2551 0 4346 0 -21778 8755 -14781 -12222
47
Trade Volume 90 14 14 48 4 34 332 500 360 572 636 486 230 2 6 0 8 20 10 6 36 378 180 196 98 112 86 252 114 220 292 6 8 4 10 44 110 134 116 12 38 130 116 102 0 8 0 270 44 376 2
Commissions 8.23 1.28 1.28 4.33 0.36 3.08 29.91 45.07 32.88 53.08 58.44 44.7 21.2 0.19 0.56 0 0.74 1.84 0.92 0.55 3.29 34.79 16.54 17.95 8.9 10.11 7.67 22.72 10.45 20.31 27.33 0.57 0.75 0.38 0.94 4.17 10.49 12.93 11.18 1.16 3.66 12.61 11.12 9.74 0 0.77 0 27.29 4.52 38.81 0.21
Date 2014-12-01 2014-12-02 2014-12-03 2014-12-04 2014-12-05 2014-12-08 2014-12-09 2014-12-10 2014-12-11 2014-12-12 2014-12-15 2014-12-16 2014-12-17 2014-12-18 2014-12-19 2014-12-22 2014-12-23 2014-12-24 2014-12-25 2014-12-26 2014-12-29 2014-12-30 2014-12-31
Morning -4200 10641 -23221 -25761 -11478 -49925 20690 -94647 -32035 16686 -24622 -21529 63559 -7668 14855 27659 19916 52519 12081 53049 71137 82006 2867
Afternoon -962 21361 -20922 -30395 1041 -41967 -92473 -37320 -57564 -3412 11151 4123 46585 1913 12668 69559 49924 54053 67774 94586 36480 48640 23121
Total P&L -5162 32003 -44144 -56156 -10437 -91892 -71783 -131967 -89599 13274 -13471 -17406 110144 -5755 27523 97218 69840 106572 79855 147635 107616 130646 25987
Trade Volume 156 46 752 776 230 774 116 1438 468 124 178 58 1054 432 70 2162 4726 3626 4084 3532 4022 4372 3998
Commissions 16.51 4.99 84.82 90.28 27.59 94.36 14.51 175.33 57.39 15.23 21.76 7.23 135.38 54.58 8.78 281.91 604.8 444.84 504.92 452.82 532.92 571.67 528.86
Table A.2: Daily P&L results for volume order imbalance strategy trading secondary futures contract. Pink cells indicate a loss during the session or entire day.
A.3
Final Improved Strategy P&L: Main Contract Total days with profit: 185 Total days with losses: 58 Average Daily Sharpe Ratio: 0.464 Annualized Sharpe Ratio: 7.243 * all numbers reported in CNY Strategy Parameters: k = 5, q = 0.15, w1 = w 2 = 0.5, L = 5 Average: 32,701 25,900 58,600 1,798 Date Morning Afternoon Total P&L Trade Volume 2014-01-02 0 0 0 0 2014-01-03 23176 5460 28637 1146 2014-01-06 39037 5168 44205 1446 2014-01-07 36008 -565 35443 2042 2014-01-08 34885 11241 46126 1922 2014-01-09 22887 5567 28454 1638 2014-01-10 30790 6892 37683 1898 2014-01-13 16159 7321 23480 1702 2014-01-14 12188 -4062 8126 1828 2014-01-15 7723 12808 20530 1104
48
184.49 Commissions 0 98.92 121.88 171.38 162.07 137.93 157.79 140.9 151.07 91.45
Date 2014-01-16 2014-01-17 2014-01-20 2014-01-21 2014-01-22 2014-01-23 2014-01-24 2014-01-27 2014-01-28 2014-01-29 2014-01-30 2014-02-07 2014-02-10 2014-02-11 2014-02-12 2014-02-13 2014-02-14 2014-02-17 2014-02-18 2014-02-19 2014-02-20 2014-02-21 2014-02-24 2014-02-25 2014-02-26 2014-02-27 2014-02-28 2014-03-03 2014-03-04 2014-03-05 2014-03-06 2014-03-07 2014-03-10 2014-03-11 2014-03-12 2014-03-13 2014-03-14 2014-03-17 2014-03-18 2014-03-19 2014-03-20 2014-03-21 2014-03-24 2014-03-25 2014-03-26 2014-03-27 2014-03-28 2014-03-31 2014-04-01 2014-04-02 2014-04-03
Morning 9524 22656 11749 17147 28170 2867 13955 8552 4983 9571 5183 4792 11611 6352 16849 1233 4014 4753 4766 4029 10437 10100 16036 10684 25956 11598 11801 37540 24453 28527 28440 29607 51722 38003 65469 45000 18509 55861 9043 22404 21833 10984 32249 34040 14110 14962 44588 17891 26264 16583 17150
Afternoon 6896 11412 5363 4345 11057 -4269 8943 7361 931 1003 10112 79 4111 6898 -1336 7266 1789 722 656 6806 6566 5071 9269 36302 11733 21190 36872 9556 15171 9417 27469 9659 14819 8540 21878 13235 4589 -492 346 8127 13697 74437 20848 6108 5092 41097 20512 14329 23741 1302 9272
Total P&L 16420 34067 17113 21492 39227 -1402 22898 15913 5914 10574 15295 4871 15722 13250 15513 8499 5802 5475 5422 10835 17003 15171 25305 46986 37689 32788 48673 47096 39625 37944 55909 39266 66541 46543 87347 58236 23098 55370 9389 30532 35530 85420 53097 40148 19202 56059 65100 32219 50004 17885 26421
49
Trade Volume 810 848 1148 1390 1364 1006 846 656 884 664 552 498 674 958 808 594 436 256 380 684 656 680 914 1182 1490 1540 1654 1686 1948 1800 1872 1890 1980 2388 2596 2372 2434 2002 1996 1840 1468 2166 2506 2796 2124 1888 1862 2318 2276 2120 1604
Commissions 67.3 69.96 94.14 114.84 114.36 84.71 71.51 54.84 73.93 55.73 45.93 41.04 56.99 81.65 69.13 50.81 37.29 22.13 32.59 58.92 56.58 57.95 75.68 97.17 119.96 124.36 133.44 137.12 157.38 145.68 150.65 153.17 155.69 186.09 202.86 187.32 191.41 159.05 159.16 144.94 115.15 170.2 201.91 225.86 171.59 152 150.3 186.9 183.78 172.18 130.99
Date 2014-04-04 2014-04-08 2014-04-09 2014-04-10 2014-04-11 2014-04-14 2014-04-15 2014-04-16 2014-04-17 2014-04-18 2014-04-21 2014-04-22 2014-04-23 2014-04-24 2014-04-25 2014-04-28 2014-04-29 2014-04-30 2014-05-05 2014-05-06 2014-05-07 2014-05-08 2014-05-09 2014-05-12 2014-05-13 2014-05-14 2014-05-15 2014-05-16 2014-05-19 2014-05-20 2014-05-21 2014-05-22 2014-05-23 2014-05-26 2014-05-27 2014-05-28 2014-05-29 2014-05-30 2014-06-03 2014-06-04 2014-06-05 2014-06-06 2014-06-09 2014-06-10 2014-06-11 2014-06-12 2014-06-13 2014-06-16 2014-06-17 2014-06-18 2014-06-19
Morning 13391 25564 2441 2906 7727 7978 14539 19012 -2346 23205 32452 16036 12853 10884 28236 24376 2459 1731 7692 5424 6587 13201 2760 31834 -260 3340 1303 957 11017 9785 19985 19849 3898 8152 1350 19673 3531 5761 4032 -1621 1742 1162 13968 18271 4532 -1020 7175 1954 3868 -3381 3845
Afternoon 6549 16327 409 47903 7973 3428 10835 13362 -549 6247 10018 22105 7027 12246 16155 7336 13483 -2878 14920 6591 7381 9315 17237 11658 -590 1266 5551 6808 1743 2656 6767 8478 15165 9774 5348 13150 723 5097 1026 1097 7715 7413 3572 19316 -226 -1316 7173 8011 356 3798 6995
Total P&L 19939 41892 2850 50809 15700 11406 25374 32373 -2895 29452 42469 38142 19879 23130 44391 31712 15942 -1147 22612 12015 13968 22516 19997 43493 -850 4606 6855 7765 12761 12441 26753 28326 19063 17927 6698 32823 4255 10858 5059 -524 9457 8575 17540 37587 4305 -2337 14348 9964 4224 417 10839
50
Trade Volume 1404 1582 1636 1828 1408 1424 1034 1278 1140 1026 1412 2322 1818 1444 1390 1460 1468 1028 554 704 1098 1054 1284 1366 1260 760 260 418 606 1126 1260 960 1032 742 676 778 744 724 404 534 478 466 550 1058 1228 766 472 578 612 236 330
Commissions 114.2 131.64 137.85 154.55 120.1 121.17 87.03 107.23 95.48 85.24 117.35 189.99 149 118.35 113.74 117.74 118.29 83.14 44.44 56.93 88.26 84.82 102.81 111.04 102.65 61.87 20.93 33.48 47.8 88.99 99.64 76.77 82.28 59.77 54.41 62.69 60.33 58.51 32.61 42.52 38.22 37.23 44 85.06 99.07 61.78 38.36 47.38 49.98 19.22 26.5
Date 2014-06-20 2014-06-24 2014-06-25 2014-06-26 2014-06-27 2014-06-30 2014-07-01 2014-07-02 2014-07-03 2014-07-04 2014-07-07 2014-07-08 2014-07-09 2014-07-10 2014-07-11 2014-07-14 2014-07-15 2014-07-16 2014-07-17 2014-07-18 2014-07-21 2014-07-22 2014-07-23 2014-07-24 2014-07-25 2014-07-28 2014-07-29 2014-07-30 2014-07-31 2014-08-01 2014-08-04 2014-08-05 2014-08-06 2014-08-07 2014-08-08 2014-08-11 2014-08-12 2014-08-13 2014-08-14 2014-08-15 2014-08-18 2014-08-19 2014-08-20 2014-08-21 2014-08-22 2014-08-25 2014-08-26 2014-08-27 2014-08-28 2014-08-29 2014-09-01
Morning 5500 6743 1059 501 2601 12762 4499 2938 5872 2145 992 5203 5158 -1222 3420 996 196 -4306 1250 283 609 7178 3668 19479 11141 71686 2498 24677 13775 24675 24172 21434 17277 27246 7494 31675 12897 10761 8152 11717 25030 8592 5455 5926 3414 5675 14004 4696 402 -3371 1385
Afternoon 6371 634 3256 2427 3195 1584 3973 4303 7334 363 1033 1244 3277 246 1326 6065 -273 208 -1033 -609 592 4322 -1077 3708 4652 18991 11720 1388 1799 19439 21151 14990 10603 12845 7355 8156 8982 11189 6199 27166 9590 5768 5020 4238 4858 6419 6885 1518 6924 2520 619
Total P&L 11871 7377 4315 2928 5796 14346 8472 7241 13206 2508 2024 6447 8435 -976 4746 7061 -76 -4098 217 -325 1201 11500 2591 23187 15793 90677 14218 26066 15573 44114 45324 36424 27879 40091 14849 39831 21878 21949 14350 38883 34620 14360 10475 10164 8273 12094 20889 6213 7326 -851 2004
51
Trade Volume 338 402 298 442 480 456 378 454 376 274 230 202 258 192 302 172 160 134 46 320 252 240 324 542 540 1046 1562 1910 1212 1180 1374 1762 1890 1512 1586 1500 1184 1020 1100 1170 1100 1192 1126 812 810 878 870 692 562 418 366
Commissions 27.05 32.12 23.73 35.46 38.52 36.87 30.54 36.69 30.57 22.26 18.68 16.36 20.83 15.38 24.27 13.89 12.98 10.89 3.72 25.93 20.4 19.6 26.64 45.16 45.54 91.11 137.11 167.27 106.33 104.63 121.98 156.88 167.2 133.44 139.05 132.94 104.51 90.05 97.45 103.79 98.1 106.1 100.02 71.58 71.74 77.53 76.46 60.73 49.17 36.65 32.28
Date 2014-09-02 2014-09-03 2014-09-04 2014-09-05 2014-09-09 2014-09-10 2014-09-11 2014-09-12 2014-09-15 2014-09-16 2014-09-17 2014-09-18 2014-09-19 2014-09-22 2014-09-23 2014-09-24 2014-09-25 2014-09-26 2014-09-29 2014-09-30 2014-10-08 2014-10-09 2014-10-10 2014-10-13 2014-10-14 2014-10-15 2014-10-16 2014-10-17 2014-10-20 2014-10-21 2014-10-22 2014-10-23 2014-10-24 2014-10-27 2014-10-28 2014-10-29 2014-10-30 2014-10-31 2014-11-03 2014-11-04 2014-11-05 2014-11-06 2014-11-07 2014-11-10 2014-11-11 2014-11-12 2014-11-13 2014-11-14 2014-11-17 2014-11-18 2014-11-19
Morning 1565 24814 -1791 11577 10665 9927 18732 11324 15726 15678 7587 8252 8048 22193 8470 22944 31533 33211 8615 6769 3002 10202 5117 19569 7301 16669 12353 27655 17584 3112 5724 8323 2407 5530 3466 -557 10401 15569 2632 196 3836 9834 6037 37400 37363 3453 24943 12377 34068 6210 -4331
Afternoon 16863 3229 9378 11564 11664 -1779 35283 4851 5323 20574 4686 3131 17489 12319 11832 30454 23611 19485 4056 3388 9734 208 7900 -831 10156 12467 11051 14380 -920 1969 4493 6132 841 -1345 11377 16476 9693 26133 3544 552 -2708 6285 23067 15380 45439 10249 13086 7289 25959 15597 -2486
Total P&L 18428 28043 7587 23141 22329 8148 54015 16176 21050 36252 12273 11383 25537 34512 20302 53398 55144 52696 12671 10157 12736 10410 13017 18739 17458 29136 23404 42036 16663 5081 10217 14454 3248 4184 14842 15919 20094 41702 6176 748 1128 16120 29105 52780 82802 13702 38030 19666 60027 21806 -6817
52
Trade Volume 456 602 804 884 660 742 818 1104 1132 1018 918 1368 1218 1186 1430 1708 1694 2000 1718 1350 940 730 988 962 1230 1198 1056 1372 1080 928 622 728 568 596 602 608 514 862 1006 1088 606 448 736 1460 2292 2140 2008 1520 1610 2050 1522
Commissions 40.46 54.49 73.06 81.39 60.86 67.86 74.92 100.62 103.25 92.64 82.64 123.68 110.82 106.74 128.89 156.01 157.18 183.82 158.05 124.42 86.92 67.95 91.52 88.11 112.81 109.92 97.48 125.82 99.38 85.3 56.92 66.03 51.26 53.18 54.19 55.71 47.43 80.69 95.12 102.46 57.06 42.1 69.58 138.7 220.49 205.39 193.85 146.17 155.87 196.07 145.08
Date 2014-11-20 2014-11-21 2014-11-24 2014-11-25 2014-11-26 2014-11-27 2014-11-28 2014-12-01 2014-12-02 2014-12-03 2014-12-04 2014-12-05 2014-12-08 2014-12-09 2014-12-10 2014-12-11 2014-12-12 2014-12-15 2014-12-16 2014-12-17 2014-12-18 2014-12-19 2014-12-22 2014-12-23 2014-12-24 2014-12-25 2014-12-26 2014-12-29 2014-12-30 2014-12-31
Morning 12335 4694 59283 10942 58659 23011 9528 50957 43445 263952 211786 421575 281148 373015 532142 325270 230975 122493 235641 56763 201636 154247 213463 175206 248019 131819 201691 218471 218631 93627
Afternoon 5444 18645 27491 31556 27422 13739 74458 32155 173840 128285 191603 207395 239837 379991 293283 296059 116784 -7503 98619 16812 246869 225034 237297 172424 200450 178632 242689 221582 222219 112697
Total P&L 17779 23339 86774 42498 86081 36750 83986 83112 217285 392237 403389 628969 520985 753006 825425 621328 347759 114990 334259 73575 448505 379280 450760 347631 448470 310451 444379 440053 440850 206323
Trade Volume 852 720 1402 2242 2738 2668 2674 2900 3818 4756 6750 7720 8922 8886 9082 10334 11102 10754 9182 8898 6858 7048 8812 9186 9590 9612 9064 8856 9534 9718
Commissions 81.21 69.31 139.73 226.11 280.59 274.65 276.97 306.84 411.17 535.72 780.86 921.35 1082.37 1109.37 1098.87 1250.26 1347 1294.65 1126.8 1112.02 897.28 917 1149.4 1175.15 1176.15 1188.24 1162.4 1174.14 1246.35 1284.98
Table A.3: Daily P&L results for final improved strategy with parameters k = 5, q = 0.15, w1 = w 2 = 0.5, L = 5, trading main futures contract. Pink cells indicate a loss during the session or entire day.
53
Appendix B Daily P&L Heatmaps for Various Lags
54
. s d r t e e h r d g r r i e e o w k b t r a k c n d i e i e h c l i t e ffi h e w h t o c L y , 2 & b d = P e r t e a L c r i g g d a a l l n i e h t i t o 5 1 . w n 0 e ) d 6 . s = 3 l q ( l l e e c d d e n a o l u 5 m b r r = a e k e k n r s i l a i e D L h . & t 0 g 2 P y n , . l i s . . i a u , d 1 y g = n e t k a e a m r t t s d n s e a e g h t 2 . r a r 0 l , o . f . . e p , h t a 5 h t m 3 1 t . i a 0 w e , h 3 s r 1 e s . s 0 t e o l d = m a n q r a a t h s p fi e e o h r m p e T . y h L l t i a r & d e v P n o r a , e e 5 w . o l M 0 : e 1 . = t o B n w e e r d s u = g l l i e F w c
p a m t a e H L & P 2 g a L
2
1 . B
1
55
. s d r t e e h r d g r r i e e o w k b t r a k c n d i e i e h c l i t e ffi h e w h t o c L y , 3 & b d = P e r t e a L c r i g g d a a l l n i e h t i t o 5 1 . w n 0 e ) d 6 . s = 3 l q ( l l e e c d d e n a o l u 6 m b r r = a e k e k n r s i l a i e D L h . & t 0 g 2 P y n , . l i s . . i a u , d 1 y g = n e t k a e a m r t t s d n s e a e g h t 2 . r a r 0 l , o . f . . e p , h t a 5 h t m 3 1 t . i a 0 w e , h 3 s r 1 e s . s 0 t e o l d = m a n q r a a t h s p fi e e o h r m p e T . y h L l t i a r & d e v P n o r a , e e 5 w . o l M 0 : e 2 . = t o B n w e e r d s u = g l l i e F w c
p a m t a e H L & P 3 g a L
2
2 . B
1
56
. s d r t e e h r d g r r i e e o w k b t r a k c n d i e i e h c l i t e ffi h e w h t o c L y , 4 & b d = P e r t e a L c r i g g d a a l l n i e h t i t o 5 1 . w n 0 e ) d 6 . s = 3 l q ( l l e e c d d e n a o l u 9 m b r r = a e k e k n r s i l a i e D L h . & t 0 g 2 P y n , . l i s . . i a u , d 1 y g = n e t k a e a m r t t s d n s e a e g h t 2 . r a r 0 l , o . f . . e p , h t a 5 h t m 3 1 t . i a 0 w e , h 3 s r 1 e s . s 0 t e o l d = m a n q r a a t h s p fi e e o h r m p e T . y h L l t i a r & d e v P n o r a , e e 5 w . o l M 0 : e 3 . = t o B n w e e r d s u = g l l i e F w c
p a m t a e H L & P 4 g a L
2
3 . B
1
57
Appendix C Trading Simulation R Code 1 # f un ct io n t o r ea d i n t he m ar ke t d at a f ro m C SV f il es 2 ReadFiles < - f u n c ti o n ( path , c o nt r ac t ) { 3 files < - l is t . f i l e s ( path = path ) d a ta < - l i st () 4 fo r ( f in f il es ) { 5 6 ke y < - s u b st r (f,7,14) 7 temp < - r e ad . cs v ( paste ( path , f , s e p = ’ ’ ) , h e a de r = T , s t r i n g sA s F a c t or s = F ) data [[key]] <- temp[ which ( substr (temp InstrumentID ,1,2)==contract ), c (1,3:11,18)] 8 9 } 10 save . image ( data , file = paste ( path , ’/ DataSet.RData’,sep=’’)) 11 return ( f i l e p a t h ) 12 }
Listing C.1: ReadFiles.R: reads market data CSV files into R dataset 1 GetMainContract < - f u n c ti o n ( data , o pe n. in t = F ) { 2 if ( o pe n .i nt = = T ) { 3 temp < - d a ta [ which ( data S e c o nd O f D ay < 3 3 2 4 0) , ] temp <- temp[temp OpenInterest== ma x (temp OpenInterest),] 4 } else { 5 6 temp < - d a ta [ which ( data S e c o n dO f D a y = = 3 3 3 00 ) , ] 7 temp <- temp[temp Volume== ma x (temp Volume),] } 8 9 return (head(temp I nstrumentID ,1)) 10 }
Listing C.2: GetMainContract.R: given the market data for a trading day, determines the main contract Instrument ID either based on Open Interest or Volume 1 source ( file = ’ G e t M a i n Co n t r a c t . R ’ ) 2 BuildLinearData < - f u n c ti o n ( data , m or ni ng = T , o pe n . in t = F , delay = 20 , l ags = 5 , 3 4 5 6 7 8 9 10 11 12 13 14 15 16
f u nc t io n s = N UL L ) { library ( z o o ) library ( T T R ) # d e cl a r e c on s t a n ts day. s t ar t < - 33300 # 9 :1 5 AM . s t ar t < - 33300 # 9 :1 5 AM.open <- 33360 # 9 :1 6 - t ra de o pe n AM . c l os e < - 40800 # 1 1: 20 - t ra de c lo se AM . e nd < - 41280 # 1 1 :2 8 PM . s t ar t < - 46800 # 1 3 :0 0 PM.open <- 46860 # 1 3: 01 - t ra de o pe n PM . c l os e < - 54000 # 1 5: 00 - t ra de c lo se PM . e nd < - 54780 # 1 5 :1 3 start . t i me < - i f el s e (morning , AM. start , PM . start ) # - d at a s ta rt
58
17 18 19 20 21 22 23 24
open. t im e < - i f el s e ( m o r ni n g , A M . o pe n , P M . o p en ) # - t ra de op en close . t i me < - i f el s e (morning , AM. close , PM . close ) # - t ra de c lo se en d . t i me < - i f el s e (morning , AM. en d , PM . en d ) # - d at a e nd # g e t ma i n c on t ra c t instrument <- GetMainContract( data , o pe n . i nt )
in d < - w h ic h ( data InstrumentID==instrument & d a ta S e c o n dO f D a y > = start . t i me & d at a S e c o n dO f D a y < en d . time ) 25 main. d at a < - d at a [ind,] 26 n < - n ro w (main. data ) 27 28 29 30 31 32 33 34 35 36
time .secs <- main. data S e c o nd O fD a y + m a in . data UpdateMillisec / 1000 ind.open <- head( which ( time .secs >=open. time ),1) ind. c l os e < - head( which ( time .secs >= close . time ),1) # c a lc u l a t e va r i a bl e s mid.price <- (main. data B i d Pr i ce 1 + m ai n . data AskPrice1) /2 spread <- main. data AskPrice1 -main . data BidPrice1
OIR. a r ra y < - (main. data B i d V ol u me 1 - m a in . data AskVolume1) / ( m a i n . data BidVolume1 + m a in . data AskVolume1) 37 dBid.price <- c (0 , diff ( m a i n . data BidPrice1)) 38 dAsk.price <- c (0 , diff ( m a i n . data AskPrice1)) 39 40 41
# # b u i l d o r d er i m ba l an c e s i g n al a c co r di n g t o S p ec bid.CV <- ( m a i n . data B i d V ol u m e 1 - ifelse (dBid.price==0, c (0,main. data BidVolume1[-n ]) , re p (0,n))) * as . integer (dBid.price >=0) 42 ask.CV <- ( m a i n . data A s k V ol u m e 1 - ifelse (dAsk.price==0, c (0,main. data AskVolume1[-n ]) , re p (0,n))) * as . integer (dAsk.price <=0) 43 VOI. a r ra y < - b id . C V - a sk . C V 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
dVol <- c (NA, diff (main. data Volume)) dT O <- c ( N A , diff ( m a i n . data Turnover)) AvgTrade.price <- dT O / dVol / 30 0 AvgTrade.price[ which ( is . na n (AvgTrade.price))] <- NA AvgTrade.price < - n a . l o c f ( na . l o c f ( A v g T r a d e . p r i c e , na . rm = F ) , f r o m La s t = T ) MPB. a r ra y < - ( A v g T ra d e . p r i ce - c( m i d . p r i ce [ 1 ] , r o l l me a n ( m i d . p ri c e , k = 2 ) ) )
k < - d e la y p <- lags ne w .ind <- ( p + 1 ) : ( n - k ) # # a r it h me t ic a v er a ge o f f u t u re k m i dp r ic e s m i n u s c u r r en t m i dp r ic e if ( k > 0) { library ( z o o ) fp c <- r o l l me a n ( m i d . p ri c e , k = k ) [ - 1 ] - m i d . p r ic e [ 1 : ( n - k ) ] dMid.Response <- c ( f p c , re p ( N A , k ) ) } else { dMid.Response < - r ep (0,n) }
# b ui ld V OI , d Mi d , O I R - f ir st p e nt ri es a re u se le ss VO I < - c b in d ( V O I . array ) OI R < - c b in d ( O I R . array ) MP B < - c b in d ( M P B . array ) if ( p > 0) { fo r ( j i n 1 :p ) { VO I < - c b in d ( V O I , c ( re p ( NA , j ) , V OI . array [1:(n-j)])) OI R < - c b in d ( O I R , c ( re p ( NA , j ) , O IR . array [1:(n-j)])) MP B < - c b in d ( M P B , c ( re p ( NA , j ) , M PB . array [1:(n-j)])) } }
# t r im t h e v a ri a bl e s
59
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 }
dMid.Response <- dMid.Response[ ne w . i n d ] VO I <- VOI[ ne w . i n d , , drop = F A L S E ] OI R <- OIR[ ne w . i n d , , drop = F A L S E ] MP B <- MPB[ ne w . i n d , , drop = F A L S E ] colnames ( V O I ) < - p a s te ( ’ V O I . t ’ , se q (0,p),sep=’’) colnames ( O I R ) < - p a s te ( ’ O I R . t ’ , se q (0,p),sep=’’) colnames ( M P B ) < - p a s te ( ’ M P B . t ’ , se q (0,p),sep=’’) # t r i m t he o t h e r s u pp o rt i ng d at a mid.price <- mid.price[ ne w . i n d ] spread <- spread[ ne w . i n d ] AvgTrade.price <- AvgTrade.price[ ne w . i n d ] main. d at a < - main. data [ ne w .ind,] time .secs < - t im e .secs[ ne w . i n d ] ind.open <- i nd . o pe n - p ind. c l os e < - ind. close - p # r e tu rn a n R o b j ec t value <- {} value d a ta < - main. data value dMid.Response <- dMid.Response value VO I <- VO I value OI R <- OI R value MP B <- MP B value time .secs < - t im e .secs value ind.open <- ind.open value ind. c l os e < - ind. close value mid.price <- mid.price value spread <- spread value AvgTrade.price <- AvgTrade.price return ( v a l u e )
Listing C.3: BuildLinearData.R: given the market data for a trading session, builds the variables to be used in a linear model for the trading strategy 1 source ( file = ’ B u i l d L i ne a r D a t a . R ’ ) 2 BuildLinearModel < - f u n c ti o n ( k e y , data , f ul l . da y = T , m or ni ng = T , o pe n . in t = F , 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
delay = 2 0, l ag s = 5 , s tr at eg y = ’ ’ , f u nc ti on s = N UL L ) { # c he ck i f w e n ee d a f ul l - da y l i n ea r m od el o r f o r a s in gl e t ra di ng s es si on if ( f ul l .d ay = = T ) { morning. d a ta < - BuildLinearData( data , m o r n in g = T , o p e n . i nt = o p e n . i nt , delay = delay , l a g s = la g s , f u n c ti o n s = f u n c t io n s ) evening. d a ta < - BuildLinearData( data , m o r n in g = F , o p e n . i nt = o p e n . i nt , delay = delay , l a g s = la g s , f u n c ti o n s = f u n c t io n s ) dMid.Response <- c ( m o r n i n g . data dMid. Response , evening. data dMid.Response) VO I < - r b in d ( m o r n i n g . data V OI , e v e n in g . data VOI) OI R < - r b in d ( m o r n i n g . data O IR , e v e n in g . data OIR) time .secs <- c ( m o r n i n g . data time . s e cs , e v e n in g . data time .secs) mid.price <- c ( m o r n i n g . data m i d . p ri c e , e v e n in g . data mid.price) spread <- c ( m o r n i n g . data spread ,evening. data spread) AvgTrade.price <- c ( m o r n i n g . data A v g T r a d e . p ri c e , e v e n in g . data AvgTrade.price) MP B < - r b in d ( m o r n i n g . data M PB , e v e n in g . data MPB) trading. d a ta < - r b in d ( m o r n i n g . data data , e v en i ng . data data ) } else { trading. d a ta < - BuildLinearData( data , m o rn i ng = m or ni ng , o p en . i nt = o pe n . in t , delay = delay , l ag s = l ag s , f u nc t io n s = f un c ti o ns ) dMid.Response <- trading. data dMid.Response VO I <- trading. data VO I OI R <- trading. data OI R time .secs <- trading. data time .secs mid.price <- trading. data mid.price
60
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
spread <- trading. data spread AvgTrade.price <- trading. data AvgTrade.price MP B <- trading. data MP B trading. d a ta < - trading. data data
}
# # b u il d t he f e at u re s m a tr i x ( x - v a ri a bl e ) b a se d o n s t r a te g y # # t r a n sf o rm t he v a ri a bl e s i f n e ce s sa r y identity < - f u n c ti o n ( x) x i n v er s e < - f u n c ti o n ( x) 1 / x f.VOI < - i f ( is . null ( f u n c t i on s [ [ ’ V O I ’ ] ]) ) i d e n ti t y else functions[[’VOI’]] f.OIR < - i f ( is . null ( f u n c t i on s [ [ ’ O I R ’ ] ]) ) i d e n ti t y else functions[[’OIR’]] # # b u i ld t he e x pl a na t or y v a ri a bl e s x < - l is t () x[[’A’]] < - d a ta . frame (y=dMid. Response , VOI=f.VOI(VOI)) x[[’B’]] < - d a ta . frame (y=dMid. Response , VOI=f.VOI(VOI) / spread , OIR=f.OIR(OIR) / spread , MPB=MPB[,1] / spread)
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 }
value <- {} # b u i ld t h e l i n ea r m o d el u s in g O L S if (strategy != ’ ’) { s <- strategy value m o de l < - l m (y ~ . , data =x[[s]]) } # # r et u rn v a l ue s value dMid.Response <- dMid.Response # # y - v a lu e value VO I <- VO I value OI R <- OI R value spread <- spread value y <- dMid.Response value x <- x value d a ta < - trading. data value AvgTrade.price <- AvgTrade.price value mid.price <- mid.price value MP B <- MP B value time .secs < - t im e .secs
return ( v a l u e )
Listing C.4: BuildLinearModel.R: given the market data for a trading session, builds the linear model to be used by the strategy 1 ################################################## ## 2 ## L IN EA R M O DE L S T R AT EG Y : B UY S IG NA L ( at t ) 3 ## * E [ F PC ( t ) ] > = 0 .2 4 ## 5 ## S EL L S IG NA L ( at t ) 6 ## * E [ F PC ( t ) ] < = - 0. 2 7 ## 8 ## 9 ## i f s i g na l h it s , b uy o r s e ll m ax im um p os it io n 10 ################################################## ## 11 source ( file = ’ G e t M a i n Co n t r a c t . R ’ ) 12 source ( file = ’ B u i l d L i ne a r D a t a . R ’ ) 13 LinearStrategy < - f u n c ti o n ( data , c oe fs , l ag s , s t ra t eg y = ’ A ’ , t h r es h ol d = 0 .2 ,
mo rn in g = T , op en . in t = F , tr ad e . at . mi d = F , fu nc ti on s = NU LL ) { 14 15 16 17
# # g et a ll t he m ar ke t d at a ( t hi s w ou ld b e a d at a - st re am i n a r ea l - ti me s ys te m ) TR.COST <- 2. 5 * 1e-5 value <- BuildLinearData( data , m o rn i ng = m or n in g , o pe n . i nt = o p en . i nt , delay = 0 , l a gs = l ag s ) 18 main. d at a < - value data
61
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
n < - n ro w (main. data )
mid.price <- value mid.price spread <- value spread time .secs <- value time .secs ind.open <- value ind.open ind. c l os e < - value ind. close ow n <- F p os < - 0 strat < - r ep (0,n) realized.pnl < - r ep (NA,n) total.trade.pnl <- c () returns <- c () pn l <- 0 trade.costs <- 0 buy.price <- 0 sell.price <- 0 entry <- 0 trade.volume <- 0 sharpes <- c () # g e t t he v e ct or o f b i d / a sk p r ic e s ( t h i s w i l l b e s c al a r i n d a ta s t re a m ) as k < - i f ( t r a d e . a t . mi d ) m i d . p r ic e else main. data AskPrice1 bi d < - i f ( t r a d e . a t . mi d ) m i d . p r ic e else main. data BidPrice1
# S et t he x - v a l u es t o b e u se d i n p r ed i ct i on d e pe n di n g o n s t ra t eg y # t he se w ou ld b e s c al ar i n a d at a s t re am VO I <- value VO I OI R <- value OI R MP B <- value MP B identity < - f u n c ti o n ( x) x f.VOI < - i f ( is . null ( f u n c t i on s [ [ ’ V O I ’ ] ]) ) i d e n ti t y else functions[[’VOI’]] f.OIR < - i f ( is . null ( f u n c t i on s [ [ ’ O I R ’ ] ]) ) i d e n ti t y else functions[[’OIR’]] x < - c b in d ( re p (1,n)) if ( s t ra t eg y = = ’ A ’ ) { x < - c b in d ( x , f . V O I ( V OI ) ) } e l se i f ( s t ra t eg y = = ’ B ’) { x < - c b in d ( x , f . V O I ( V O I ) / spread , f.OIR(OIR) / spread , MPB[,1] / spread) } else { stop ( paste ( ’ M i s s i ng L i n e ar S t r a te g y : ’ , s t r a te g y ) ) }
# t hi s i s w he re w e a s s um e w e g e t a d at a s tr ea m i ns te ad o f l o op in g t hr ou gh t he dataset # m u lt i pl y t he c o ef f ic i en t s w i t h t h e f a ct o rs a nd c he c k i f i t ’ s a bo v e / below threshold # a n d t r ad e i f t h e s i gn al i s g oo d
# i n a n a c tu a l t r ad i ng s ys te m , t he d e ci s io n w o ul d b e c a lc u la t ed b y a s t ra t eg y engine 69 # h a vi n g t h e r ea l - t i me d at a f e d i n t o t h e e n g in e v i a a d at a s t r e am 70 # b ut i n t h i s s i m u la t io n , w e j u s t a s s u me w e h a v e t h e f u ll d a ta s et a nd t he # s t ra t eg y e n gi n e i s t he c o ef f ic i en t m u l ti p li c at i on o n t h e n e xt l in e 71 72 efpc.vec <- rowSums(x * m a tr i x ( re p (coefs,n),byrow=T, nrow = n ) ) 73 # e ac h k = 50 0m s; fo r ( k i n t ra de . i nd ) { 74 efpc <- efpc.vec[k] 75 76 77 78 79 80 81 82 83
# # c he c k if w e ar e w it h in t r a di n g h ou r s if ( k > = i n d . o pe n & k < i n d . c l os e & o wn == F & e fp c > = t h re s ho l d ) { # # B UY t o O PE N strat[k] <- 1 own = T p os < - 1 buy.price <- ask[k]
62
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
entry <- k tc <- buy.price * TR.COST trade.costs <- t r ad e . c os ts + t c trade.volume <- t r ad e . v ol u me + 1 } e l se i f ( k > = i n d . o pe n & k < i n d . c l os e & o wn == F & e fp c < = - t h r e sh o ld ) { # # S EL L t o O PE N strat[k] <- -1 own = T p os < - -1 sell.price <- bid[k] entry <- k tc <- sell.price * TR.COST trade.costs <- t r ad e . c os ts + t c trade.volume <- t r ad e . v ol u me + 1 } e l se i f ( ow n = = T & p os == 1 & e f pc < = - t h r e sh o ld ) { # # S EL L t o C LO SE strat[k] <- -1 ow n <- F p os < - 0 sell.price <- bid[k] tc <- t c + s el l . p ri c e * TR.COST trade.costs <- t r ad e . c os ts + t c trade.pnl <- s e ll . p r i ce - b u y . p r ic e - t c pn l <- p nl + t r ad e . p nl trade.volume <- t r ad e . v ol u me + 1 total.trade.pnl <- c ( t o t a l . t r ad e . p nl , t r a de . p n l ) if ( k > = i n d . o pe n & k < ind . close ) { # # S EL L t o O PE N strat[k] <- -2 ow n <- T p os < - -1 sell.price <- bid[k] entry <- k tc <- sell.price * TR.COST trade.costs <- t r ad e . c os ts + t c trade.volume <- t r ad e . v ol u me + 1 } } e l se i f ( ow n = = T & p os = = -1 & e fp c > = t h re s ho l d ) { # # B UY t o C LO SE strat[k] <- 1 own = F p os < - 0 buy.price <- ask[k] tc <- t c + b uy . p r ic e * TR.COST trade.costs <- t r ad e . c os ts + t c trade.pnl <- s e ll . p r i ce - b u y . p r ic e - t c pn l <- p nl + t r ad e . p nl trade.volume <- t r ad e . v ol u me + 1 total.trade.pnl <- c ( t o t a l . t r ad e . p nl , t r a de . p n l )
if ( k > = i n d . o pe n & k < ind . close ) { # # B UY t o O PE N strat[k] <- 2 ow n <- T p os < - 1 buy.price <- ask[k] entry <- k tc <- buy.price * TR.COST trade.costs <- t r ad e . c os ts + t c trade.volume <- t r ad e . v ol u me + 1 } } realized.pnl[k] <- pn l
}
# c he ck i f w e h av e a l ef t - ov er p os it io n a t e nd - of - d ay a nd c lo se i t if ( su m ( s tr at ) = = 1 ) {
63
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 }
}
if ( s tr at [ n ] = = 1 ) { strat[n] <- 0 trade.volume <- t r ad e . v ol u me - 1 } else { strat[n] <- -1 sell.price <- bid[n] tc <- t c + s el l . p ri c e * TR.COST trade.costs <- t r ad e . c os ts + t c trade.pnl <- s e ll . p r i ce - b u y . p r ic e - t c pn l <- p nl + t r ad e . p nl realized.pnl[n] <- pn l total.trade.pnl <- c ( t o t a l . t r ad e . p nl , t r a de . p n l ) trade.volume <- t r ad e . v ol u me + 1 } e l se i f ( su m ( s t r a t ) = = - 1) { if ( s tr a t [n ] = = - 1) { strat[n] <- 0 trade.volume <- t r ad e . v ol u me - 1 } else { strat[n] <- 1 buy.price <- ask[n] tc <- t c + b uy . p r ic e * TR.COST trade.costs <- t r ad e . c os ts + t c trade.pnl <- ( s e ll . p r i ce - b u y . p r ic e ) - t c pn l <- p nl + t r ad e . p nl realized.pnl[n] <- pn l total.trade.pnl <- c ( t o t a l . t r ad e . p nl , t r a de . p n l ) trade.volume <- t r ad e . v ol u me + 1 }
} # r et u rn s t at s realized.pnl < - n a . l o c f ( c (0,realized.pnl))[-1] value <- {} value t i me < - t i m e .secs value pn l <- realized.pnl value strategy <- strat value trade.volume <- trade.volume value trade.pnl <- total.trade.pnl value trade.costs <- trade.costs return ( v a l u e )
Listing C.5: LinearStrategy.R: the trading strategy given a linear model to forecast price changes 1 load ( file = ’ D a t a S et . R D a t a ’ ) 2 3 source ( ’ B u i l d L i n e a r M o d e l . R ’ ) 4 source ( ’ L i n e a r S t r a t e g y . R ’ ) 5 6 # # ## A V ER A GE D L AG L I NE A R S T RA T EG Y # ## # 7 8 # # s et t r ad i ng a nd m o de l p a ra m et e rs 9 threshold <- 0. 2 10 period <- 20 11 lags <- 5 12 strategy <- ’A ’ 13 coefs <- c () 14 15 # # b u il d t he l i ne a r m o de l s a nd s t or e t h ei r c o ef f ic i en t s 16 fo r ( i i n 1 :length ( data )) { ke y < - n a me s ( data )[i] 17 18 # f ul l - d a y c o e f fi c i e n ts 19 value <- BuildLinearModel(key, data [ [ i ]] , f ul l . d ay = T , delay = p er io d , l ag s = l ag s
, s t ra t eg y = s t ra t eg y )
64