Barmish 2021

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

This article has been accepted for publication in a future issue of this journal, but has not been

fully edited. Content may change prior to final publication. Citation information: DOI 10.1109/TAC.2021.3086328, IEEE
Transactions on Automatic Control

GENERIC COLORIZED JOURNAL, IEEE TAC, VOL. XX, NO. XX, XXXX 2020 1

On Feedforward Stock Trading Control


Using a New Transaction Level Price Trend Model
B. Ross Barmish, Fellow, IEEE , James A. Primbs, and Sean Warnick, Member, IEEE

Abstract— In this paper, we provide a new Markovian-type model


for stock price trend analysis at the transaction level, and illustrate
its use for trading in conjunction with a controller which makes
buy and sell decisions. Central to our formulation is a sequence
of i.i.d. random variables Tk which corresponds to the number of
transactions between reversals in price direction. For a trader, this
is an important indicator of the “duration” of a trend. For processes
with “large” Tk , there is an incentive to try and capitalize by buying
stock when a temporary trend is “up” and selling when it is “down.”
The extent to which this is possible is determined by a model
parameter pe , called the probability of efficiency, which indicates the
likelihood that the bid, ask and current price are such that one can
seamlessly enter or exit the market without slippage. The degree
to which a trader can exploit trending behavior is quantified in our
main result which provides the expected value of the trading gain Fig. 1. Stock Trading Controller
resulting from a strategically constructed feedforward switching
controller. The paper also includes an example illustrating appli-
cation of the theory using historical data. do not conform to the typical uncorrelated stochastic processes, often
Index Terms— feedforward control, financial engineering, used in finance, such as the celebrated Brownian motion originating in
the work of Bachelier [14] in 1900 and carried forward in papers such
algorithmic stock trading, stochastic systems.
as those of Samuelson [15] and Merton [16]. Rather, it is argued that
more complicated models involving memory and correlation provide
I. I NTRODUCTION a better fit. In the sequel, building on this idea, we model trend lengths
In this paper, we put forward a new model aimed at capturing directly, rather than attempting to induce their distribution from some
transaction level stock price trending behavior and provide condi- underlying and perhaps complicated model of prices.
tions under which a trader can capitalize via the use of a simple Assuming an ideal market with no transaction costs or latency
feedforward controller which determines the investment level. When effects, the most salient technical novelty of this paper, differentiating
viewed in the context of finance literature, our approach falls under it from existing literature, is a parameter pe , the probability of
the umbrella of technical analysis in that it is not driven by economic efficiency. As explained in the sequel, knowing the bid, ask and
rationale. Instead, it is based on extraction of information from stock desired direction of trade, this quantity indicates whether a trader
prices which is useful for prediction or exploitation in a trading can seamlessly enter or exit the market.
context; e.g., see [1] and the seminal paper [2] aimed at demonstrating Given the context above, in this paper, there are two focal points:
the efficacy of technical analysis with trading rules based on price the presentation of a new theoretical model for price trending
crossings of moving averages. behavior and a quantification of the so-called gain-loss function
More generally, the voluminous body of literature on technical associated with the use of an appropriately constructed stock trading
analysis, not only at the transaction level, includes results on “mo- controller. As mentioned previously, we envision this scheme to be
mentum” methods, for example, see [3] and [4], evaluation of most efficacious at the transaction level where bid and ask prices
strategies as in [5], time series analysis methods as in [6], and more play an important role. Accordingly, our trading method is a form of
exotic techniques based on a neural networks as in [7], [8] and [9]. microtrend exploitation.
The seemingly endless list of approaches to price modelling also To accomplish profitable trading in an environment as described
includes the use of machine learning, noise modelling and even chaos above, many control schemes are possible. As illustrated in Figure 1,
and fractals; e.g., see [10], [11] and [12]. the inputs to an investment-level controller can be the prices S(i),
In the work described here, motivation is drawn from the empirical i = 0, 1, 2, 3..., the transactions and other information, such as the
study of Sieczka and Holyst [13] in which the statistical properties of account value V (i). With the ideas above in mind, we consider the
the duration of short term price trends in high frequency stock market special case of feedforward control and relegate the study of more
data are analyzed. These authors find that trend length distributions general feedback structures, such as those which also use V (i), to
future research.
This paper was first submitted to IEEE Transactions on Automatic
Control on February 7, 2020. This work was supported in part by the Central to our new model is a sequence of i.i.d. random vari-
U.S. Department of Homeland Security under Contract HSHQDC-13-C- ables Tk which count the length of price trends. To this end, we
B0060 and Robust Trading Solutions, LLC. define a trend as consecutive price moves S(i) in the same direction,
B. Ross Barmish is a research professor in the ECE Department, “up” or “down,” and measure the length of the k-th trend Tk as
Boston University, Boston, MA 02215 and an emeritus professor, also
in ECE, University of Wisconsin, Madison, WI 53706. beginning after the first move in the direction of the trend and ending
e-mail: bob.barmish@gmail.com. with the first move opposite the trend; see Section II-C and Figure
James A. Primbs is a professor in the Department of Finance, 2 for details. Note that the index k is reserved for the sequence of
California State University Fullerton, Fullerton, CA 92831. trend lengths Tk , while the index i will be used exclusively for the
e-mail: jprimbs@fullerton.edu.
Sean Warnick is a professor in the Department of Computer Science
sequence of prices S(i).
at Brigham Young University, Provo, UT 84602. For a trader, this variable Tk is an important indicator of the
e-mail: sean.warnick@gmail.com. duration of a trend. For processes with “large” Tk , there is an

0018-9286 (c) 2021 IEEE. Personal use is permitted, but republication/redistribution requires IEEE permission. See http://www.ieee.org/publications_standards/publications/rights/index.html for more information.
Authorized licensed use limited to: National University of Singapore. Downloaded on July 05,2021 at 15:54:17 UTC from IEEE Xplore. Restrictions apply.
This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication. Citation information: DOI 10.1109/TAC.2021.3086328, IEEE
Transactions on Automatic Control
2 GENERIC COLORIZED JOURNAL, IEEE TAC, VOL. XX, NO. XX, XXXX 2020

obvious incentive to try and capitalize by buying when the stock is dealing with δi is rather trivial. That is, it is typically the case
trending “up” and selling when it is trending “down.” In the sequel, to these price changes are constant and correspond to the exchange’s
emphasize the central role of these random variables in our analysis, minimum tick size. If there is a degree of imbalance between supply
we refer to the “T-model.” In addition, we often mention “T-intervals” and demand, “walking the book” may come into play.1
when discussing the Tk in a generic way with no specific k-value
in mind. In this regard, we let T denote the random variable with
distribution common to all the Tk . It should also be noted that the B. Probability Distribution for Interval Lengths Tk
number of T-intervals will typically be far fewer than the number Recalling the discussion in Section 1, the interval lengths Tk are
of prices. As seen in the analysis to follow, a high probability of assumed to be independent and identically distributed, and repre-
efficiency pe combined with large expected value E[T ], an indicator sented by a common random variable T . As far as their assumed
of the average time trending in a given direction, characterizes an independence is concerned, motivation for this is derived from the
attractive trading environment for a trend follower who uses the fact that real-world markets tend to be highly non-stationary without
previously mentioned feedforward controller to strategically switch any predictability as to price direction. In view of the discussion in
between long and short positions. The key idea in this paper is that the subsection above, it is also assumed that the Tk are independent
ease of entry into the market, as manifested by pe , in combination of the δi ; see also directions for future research in the conclusion. The
with large Tk , is a recipe for successful trading. common expected value E(T ) of the Tk is an indicator of the average
More specifically, when a reversal in trend direction occurs, the time which the stock price spends trending in one direction or another.
control logic generates a triggering signal indicating that a change in In this regard, our T-interval formulation is distinctly different from
the investment, either short to long or long to short, is desired. In this many classical stock price models which have “directionality” either
regard, it is explained in Section 2 how the current price, bid and ask explicitly or implicitly built in. For example, when a classical
determine whether an efficient price point has been encountered. This binomial lattice, for example see [28], is used to model stock prices,
being the case, a trade goes forward. In our analysis, the parameter pe one begins with the probability that the next move is “up” and its
indicates the a priori likelihood that this desirable situation will occur. complement that it is “down”. Then, for this stationary case, when
When it does not, we abstain from trading until an efficient trade the probability is not 1/2, it would be incorrect to assume that the
becomes possible. Our main result is a formula for the expected value resulting Tk are independent. For example, if the probability of up is
of the so-called gain-loss function in terms of pe and expectations of 0.9, then prices tend to trend upward so that Tk will alternate between
appropriately constructed functions of T and the price changes. This large and small values, indicating longer up trends and smaller down
emphasis on control-theoretic methods is similar to what is seen in trends. However, at least anecdotally, our limited experiments on real
a number of papers; e.g., see [17]- [27] and their bibliographies. historical data suggest that the Tk are not highly correlated; e.g., see
The plan for the remainder of this paper is as follows: In Section 2, the discussion in the conclusion.
we formally describe our new model and illustrate its use via an
example. Then, in Section 3, we provide the analysis of a feedforward
controller and the main result, Theorem 3.2, bearing on performance C. Dynamic Generation of the Tk
quantification. Then, in Section 4, we illustrate use of our new theory
via two examples. The first involves theoretical calculations and the The Tk process is initialized at price S(0) which is assumed,
second involves simulation using high-frequency historical NASDAQ without loss of generality, to be the result of an upward tick.
ITCH data with nanosecond level time stamps. Finally, conclusions Hence the initial interval is designated as “UP” and we wait for
are provided in Section 5 and the lengthy proof of the main result is the first price, call it S(m), which corresponds to a downward tick;
given in the Appendix. i.e., S(m) < S(m − 1). This defines the values of the random
variable T0 = m which represents the fact that there were m (non-
zero) transactions before a change in the price, from the upward to
II. N EW S TOCK P RICE VARIATION M ODEL : T HE D ETAILS
downward direction. Accordingly, the next T-interval is designated as
In this section, we provide the details of our new model which “DOWN” and we can continue inductively.
was described in general terms in the previous section. Underlying Given the alternation of price direction from interval to interval,
the definitions to follow is the sequence of stock prices S(i) which the Tk with k even are UP, and for k odd they are DOWN.
are realized in the market. It is assumed that successive prices S(i) Generalizing on the above, suppose arrival at price S(i) marks the end
and S(i+1) are distinct, and a transaction associated with this change, of the k-th T-interval. Hence Tk is well defined and we wait for the
also called a tick, is said to have occurred. Said another way, sideways first instant when a price change occurs which is opposite in direction
price moves, S(i + 1) = S(i), although not part of our theoretical to the initiating move. According to our UP-DOWN convention, if k
model and having no effect on gains and losses, provide additional is even, we take
opportunities for the practitioner to enter and exit trades efficiently;
see the footnote in Section 4. .
Tk+1 = min{m : S(i + m) < S(i + m − 1), m > 0}

A. Tick Size Distribution and if k is odd,

Associated with the non-zero price changes above is the sequence .


Tk+1 = min{m : S(i + m) > S(i + m − 1), m > 0}.
of random variables
. A graphical depiction of these T-intervals is given in Figure 2.
δi = |S(i + 1) − S(i)|
1 For the reader familiar with the operation of exchanges, this imbalance
which are assumed to be independent and identically distributed. In
the sequel, whenever convenient, we let δ denote a random variable situation is epitomized when “walking” a limit order book occurs. As the
price moves from S to S ′ , there may be a number of intermediate prices
with probability distribution which is identical to those of the δi . along the way with no opportunity for a trader to “jump in.” Accordingly,
For the extreme case of a perfectly liquid stock being traded in a when a distribution for δ is estimated, it is important to lump together all
high-frequency context with adequate supply at the transaction price, transactions having the same time stamp.

0018-9286 (c) 2021 IEEE. Personal use is permitted, but republication/redistribution requires IEEE permission. See http://www.ieee.org/publications_standards/publications/rights/index.html for more information.
Authorized licensed use limited to: National University of Singapore. Downloaded on July 05,2021 at 15:54:17 UTC from IEEE Xplore. Restrictions apply.
This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication. Citation information: DOI 10.1109/TAC.2021.3086328, IEEE
Transactions on Automatic Control
AUTHOR et al.: PREPARATION OF BRIEF PAPERS FOR IEEE TRANSACTIONS AND JOURNALS (FEBRUARY 2017) 3

or not, respectively. Said another way, with probability pe , the trader


can seamlessly transact at price S(i + 1).

III. F EEDFORWARD C ONTROLLER AND M AIN R ESULT


When both the expected value E(T ) and the probability of ef-
ficiency pe are suitably large, since this implies strong trending
behavior and ease of entry into desired trades, one might expect
that appropriately designed stock trading controllers should result in
significant profit. To establish this, in this section we give one such
example in the form of a feedforward controller. Then we provide
analysis which leads to the main result in Theorem 3.2, a formula
for the expected value of the gain-loss function g(k) associated with
the resulting control system. This formula is further simplified for
the steady-state case in Corollary 3.4
Fig. 2. Depiction of the T-interval Model

A. The Control Law and its Analysis


D. Toy Example Illustrating T-intervals The algorithm implemented by the controller involves strategic
Imagine the random variable T ∈ {1, 2, ..., n} with uniform switching between long and short positions. The trader’s goal is to
distribution. Hence, P (T = t) = 1/n for t = 1, 2, ..., n, and capitalize on the trend by holding a long position on UP intervals
a simple calculation leads to E(T ) = (n + 1)/2. Consistent with and a short position on DOWN intervals. However, as previously
common sense, large values of n are associated with strongly trending explained, the trader should only switch between long and short
prices. It is also possible to generate sample paths for the price S(i). positions at efficient price points. More specifically, on each T-
Indeed, assume that the initial price is S(0), and the market is highly interval, for simplicity, the trader is assumed to be either long or
liquid with δ being constant. Recalling further that T0 represents an short one share and the switching rule is described by two cases as
upward price move, then for k ≥ 1, assuming that S(i) occurs at the follows:
start of interval Tk , that is, Case 1: When the k-th interval is UP, and triggered by an upward
k−1
move in the stock, that is, S(i) > S(i − 1), if the trader is already
i=
X
Tj , long or S(i) is not efficient, then no action is taken. Otherwise, if
j=0
an efficient price point is encountered in the interval, using a market
order, the trader repositions so as to be net one share long. Note this
it follows that at the end of interval Tk , the stock price is desired trade may never be realized if all transactions on this interval
S(i + Tk ) = S(i) + (−1)k δ(Tk − 2). are inefficient.
Case 2: When the k-th T-interval is DOWN and triggered at stage i
by a downward move S(i) < S(i − 1), if the trader is already short
E. Trading and Corresponding Probability of Efficiency or S(i) is not efficient, then no action is taken. On the other hand, if
Consistent with classical treatises in finance dealing with friction- an efficient price point is encountered in the interval, using a market
less markets, for example see [16], it is assumed that the trader is not order, the desired repositioning occurs and the trader ends up being
subject to slippage or cost of trading factors such as commissions, one share short.
fees and latency effects.2 In this paper, the only slippage factor under To consolidate, at the start, the feedforward controller is initial-
consideration is how the current price compares to the bid or ask. ized as u(0) = 1 and subsequently, at stage i ≥ 1 has output
Associated with the arrival at price S(i + 1) from S(i), is the notion satisfying u(i) ∈ {−1, 1}. The determination of which of these
of efficiency. In this regard, we call S(i+1) an efficient price point in two values is used by the controller depends on the index k for
the direction of movement if the following conditions are satisfied: If the T-interval under consideration and the previously defined binomial
S(i + 1) > S(i), then a market order to purchase stock is realizable random variable Xe (i), which, we recall, takes values Xe (i) = 1
at price S(i + 1). That is, for an upward price move, efficiency with probability pe and zero otherwise. Using this notation, the
corresponds to S(i + 1) being the so-called ask price and for a controller update, describing the net stock position being held is
downward move S(i + 1) < S(i), efficiency corresponds to S(i + 1)
being the so-called bid price. This condition enables the trader to u(i) = (1 − Xe (i))u(i − 1) + Xe (i)(−1)k .
transact with no “slippage.” Letting g(i) denote the cumulative gains or losses from this trading
To account for these considerations in our model, we include a strategy up to stage i, with initialization g(0) = 0, the dynamics are
parameter 0 < pe < 1, called the probability of efficiency, indicating updated by
the probability that a trader can buy or sell, in the direction of
the trend, without slippage. For convenience, we also define its g(i + 1) = g(i) + (S(i + 1) − S(i))u(i).
.
complement as qe = 1−pe . By working with pe and qe in the sequel,
it is seen that there is no need to deal further with technicalities In the following subsections, we provide a detailed gain-loss
associated with the sequence of bid prices and ask prices. Given the analysis of this feedforward control strategy. We begin with the
price S(i), we define the binomial random variable, call it Xe (i), Markov dynamics that characterize the probability of entering a given
with outcomes 1 and 0, which determine whether S(i+1) is efficient T-interval holding shares corresponding to the correct or incorrect
direction of the trend. Finally, we compute the expected gain-loss of
2 Note that in the US, since 2019, commissions are no longer a concern for the strategy over an arbitrary T-interval, which provides a quantitative
traders as most US brokers have moved to a zero-commission model. measure of favorability of the market to the trend-following strategy.

0018-9286 (c) 2021 IEEE. Personal use is permitted, but republication/redistribution requires IEEE permission. See http://www.ieee.org/publications_standards/publications/rights/index.html for more information.
Authorized licensed use limited to: National University of Singapore. Downloaded on July 05,2021 at 15:54:17 UTC from IEEE Xplore. Restrictions apply.
This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication. Citation information: DOI 10.1109/TAC.2021.3086328, IEEE
Transactions on Automatic Control
4 GENERIC COLORIZED JOURNAL, IEEE TAC, VOL. XX, NO. XX, XXXX 2020

B. Markov Dynamics Lemma 3.1: With initial condition PC (0) = 1, PI (0) = 0, and for k
We begin our analysis by computing the probability of entering a positive, the probability of arrival at the k-th T-interval on the correct
T-interval on the correct side of the trade. That is, we compute the side of the trade is given by
h i
probability that the trader enters an UP interval already holding a E[qeT ] 1 + (−1)k (E[qeT ])k−1
single share of the stock, or enters a DOWN interval already short PC (k) = .
a share of stock. Recalling that the trader begins on the correct side 1 + E[qeT ]
of the trade at k = 0, given k > 0 and Tk = t, the probability Proof: Per discussion in the previous section, the state equation
that a successful switch will occur before a new T-interval begins is for the (PC , PI ) pair is written as
1 − (1 − pe )t . Recalling the previously defined complementary effi-
E[qeT ]
    
ciency probability, qe , it is noted that the probability of a successful PC (k + 1) 0 PC (k)
= .
switch during an interval is 1 − qet . PI (k + 1) 1 1 − E[qeT ] PI (k)
Let Ck be the event that the trader arrives at the beginning of Thus, with initial conditions PC (0) = 1 and PI (0) = 0, the
the k-th T-interval on the correct side of the trade, and let Ik be probabilities of correctness and incorrectness at the k-th T-interval
the event that the trader arrives at k on the incorrect side of the are computed as
trade. Take PC (k) and PI (k) to be the corresponding unconditional k 
E[qeT ]
   
probabilities and recall that we begin with PC (0) = 1, PI (0) = 0. PC (k) 0 1
= T .
Further, note that for all k > 0, it is always the case that PI (k) 1 1 − E[qe ] 0

PC (k) + PI (k) = 1. Now, upon diagonalizing the transition matrix, the k-fold product
above is computed to be
We begin with the basic Markov probability recursion k
E[qeT ]

0
1 1 − E[qeT ]
    
PC (k + 1) P (Ck+1 |Ck ) P (Ck+1 |Ik ) PC (k)
= ,
PI (k + 1) P (Ik+1 |Ck ) P (Ik+1 |Ik ) PI (k)     
1 E[qeT ] 1 1 0 1 1
where P (Ck+1 |Ck ) is the conditional probability of entering into the = , (1)
1 + E[qeT ] 1 −1 0 (−E[qeT ])k 1 −E[qeT ]
(k + 1)-st T-interval on the correct side, given that the k-th T-interval
which, upon substitution into the previous formula, leads directly to
was entered on the correct side of the trade. The other transition
the result for PC (k). 
probabilities are defined similarly.
To calculate all the probabilities in the above transition matrix, we
first note that D. Performance Considerations
Recalling that at k = 0 the trader begins on the correct side of
P (Ck+1 |Ck ) = 0, P (Ik+1 |Ck ) = 1 the trade, we now provide the main theorem of this paper, which is
since a trader who is correct on k-th interval will wait until that the formula for the expected gain-loss for the trading algorithm over
interval has ended before attempting to reposition to be correct on the k-th T-interval. The proof of this theorem, which involves many
the next interval. Thus, being correct on the k-th interval necessarily lengthy and detailed calculations, is provided in the Appendix.
implies starting the (k + 1)-st T-interval on the incorrect side. Theorem 3.2: Beginning with PC (0) = 1, the trader’s expected gain
Moreover, we also have or loss over the k-th T-interval is given by
P (Ik+1 |Ik ) = 1 − P (Ck+1 |Ik ). 2 (1 − E[qeT ])
E[g(k)] = E[δ] E[T ] −
Next, consider a generic interval length Tk = t and, per discussion pe (1 + E[qeT ])
above, we have " #!
T k 1 1 − E[qeT ]
+2(−E[qe ]) −1 . (2)
P (Ck+1 |Ik ∩ (Tk = t)) = (1 − pe )t = qet . pe 1 + E[qeT ]
That is, given that the trader begins interval k on the incorrect side,
attempting to switch at each of the t occasions will only result in E. Steady State Considerations
being on the correct side for interval k + 1 if all of the t previous Lemma 3.3 below provides the steady state description of the
attempts fail. probabilities PC (k) and PI (k) associated with Lemma 3.1. Recalling
Thus, by the law of total probability, we obtain 0 < pe < 1, its proof is readily obtained by and letting k → ∞ in
∞ Equation (1).
X
P (Ck+1 |Ik ) = P (Ck+1 |Ik ∩ (Tk = t))P (Tk = t) Lemma 3.3: The steady state probabilities of starting an interval on
t=1 the correct side, PC , and of starting an interval on the incorrect side

of the trade, PI , are given by
qet P (Tk = t) = E[qeT ].
X
=
t=1 E[qeT ] 1
PC = ; PI = .
These preliminaries, as seen below, now enable us to compute the 1 + E[qeT ] 1 + E[qeT ]
probability of entering the k-th T-interval on the correct or incorrect The following corollary gives the steady state version of the result
side of the trade. in Theorem 3.2. The proof for the simplified steady state formula
below, obtained letting k → ∞ in Equation (2), is omitted.
C. Probability of Correctness
Corollary 3.4: The steady state expected gain or loss, g, over a T-
The following lemma provides a closed-form expression for the interval is given by
probability PC (k) of beginning the k-th T-interval on the correct side " #
of the trade. Note that the probability of beginning on the incorrect 2 (1 − E[qeT ])
E[g] = E[δ] E[T ] − .
side of the trade is readily obtained as PI (k) = 1 − PC (k). pe (1 + E[qeT ])

0018-9286 (c) 2021 IEEE. Personal use is permitted, but republication/redistribution requires IEEE permission. See http://www.ieee.org/publications_standards/publications/rights/index.html for more information.
Authorized licensed use limited to: National University of Singapore. Downloaded on July 05,2021 at 15:54:17 UTC from IEEE Xplore. Restrictions apply.
This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication. Citation information: DOI 10.1109/TAC.2021.3086328, IEEE
Transactions on Automatic Control
AUTHOR et al.: PREPARATION OF BRIEF PAPERS FOR IEEE TRANSACTIONS AND JOURNALS (FEBRUARY 2017) 5

The formula provided in Corollary 3.4 gives a quantification of


the favorability of the simple feedforward trend following strategy
in terms of the expected trend length and probability of efficiency. 1
2
That is, consistent with common sense, longer expected trends E[T ] 3 3
coupled with a high probability of efficiency pe lead to higher 4
expected gain. 5
2 6
7
F. Further Discussion of Steady State 8

E[gain]
9
Analysis of extreme situations give insight into when profitability 1 10
is possible. Beginning with Corollary 3.4, and noting that pe = 1−qe ,
we rewrite the expected gain formula as
" # 0
2 (1 − E[qeT ])
E[g] = E[δ] E[T ] − . (3)
(1 + E[qeT ]) 1 − qe
−1
For T ≡ 1, the formula becomes 0.0 0.2 0.4 0.6 0.8 1.0
  p_e
2
E[g] = E[δ] 1 − . (4)
(1 + qe )
Fig. 3. Expected Gain as a Function of pe for n = 1 . . . 10.
Here we note that E[g] is nonpositive for all values of qe . That is,
it becomes impossible to profit at any probability of inefficiency, qe ,
with the best possible outcome occurring at complete inefficiency,
qe = 1, yielding zero expected gain. 0.40
uniform
Similarly, another interesting observation from Equation (3) is how binomial (p_u = 0.5)
0.35 binomial (p_u = 0.1)
efficiency affects the expected gain. When qe = 0, we see that E[g] =
E[δ] [E[T ] − 2], revealing that E[T ], the average time which the stock 0.30
price spends trending one way or the other, must be greater than 2 in
0.25
order to profit. At the other extreme, when qe → 1, a straightforward
Probability

application of L’Hôpital’s rule reveals that E[g] = 0, confirming the 0.20


idea that expected gains are zero when there are no efficient prices.
Finally, note that the probability generating function of T is given 0.15
G(z) = E[z T ]. This implies that that E[T ] = G′ (1), which suggests
0.10
that the expression for E[g] in Equation (3) is fully characterized
by G(z). This recognition makes it easy to explore the impact of 0.05
different distributions of T on E[g].
0.00
2 4 6 8 10

IV. E XAMPLES AND S IMULATION R ESULTS T-Interval Length

The first part of this section involves revisiting the uniform distribu-
Fig. 4. PMF of T-intervals for Uniform and Binomial Distributions
tion “toy example” described in Section 2, and providing comparisons
with using the binomial distribution to generate the distribution of T-
interval lengths. The second example, involving the use of NASDAQ
generality, we initialized the calculations with an UP interval. Letting
high-frequency ITCH data, demonstrates the potential application of
U be a random variable which denotes the number of up moves in a
the theory in practice.
row prior to the DOWN move that ends an interval, the total interval
length is T = U + 1. Furthermore, assume that U is distributed as
A. Examples: Uniform and Binomial T-Interval Distributions
the binomial distribution with parameters n − 1 and probability of up
Recalling Section 2, we now revisit the random variable move pu ; i.e., this situation can be viewed as n−1 flips of a coin with
T ∈ {1, 2, ..., n − 1, n} with uniformly distributed probability mass pu denoting the probability of heads. This corresponds to interval
function and probability of efficiency 0 < pe < 1. Here, with δ ≡ 1, lengths in the set T ∈ {1, 2, . . . , n}. Figure 4 provides a comparison
we study the steady state expected gain from Corollary 3.4 as a of the Probability Mass Function (PMF) for the uniform distribution
function of the parameters (n, pe ). Under this uniform distribution and the binomial distribution with pu = 0.5 and pu = 0.1 with a
assumption, a straightforward calculation, for example using the maximum trend interval length of n = 10.
probability generating function, results in the expected gain formula To compute the expected gain from Corollary 3.4 for the binomi-
ally generated trend lengths, we note that
h i
n+1
n+1 2 qe − (n + 1)qe + n
E[g] = + h i. 2 (1 − E[qeT ])
2 pe q n+1 + (n − 1)qe − n E[g] = E[T ] −
e
pe (1 + E[qeT ])
Figure 3 shows a plot of E[g] as a function of pe for n ranging from 1 2 (1 − qe E[qeU ])
to 10. Consistent with intuition, we observe that as n increases, longer = E[U ] + 1 − .
pe (1 + qe E[qeU ])
average T-intervals lengths result and the expected gain increases.
In addition the ”uniform” result for the case n = 1 is seen to be Furthermore, observing that E[U ] = (n − 1)pu and using the
consistent with the prediction of Equation (4). probability generating function for the binomial distribution, we
As a comparison with the uniform distribution, we also generated obtain
the interval lengths for this binomial distribution case. Without loss of E[qeU ] = (1 − pu + pu qe )(n−1) .

0018-9286 (c) 2021 IEEE. Personal use is permitted, but republication/redistribution requires IEEE permission. See http://www.ieee.org/publications_standards/publications/rights/index.html for more information.
Authorized licensed use limited to: National University of Singapore. Downloaded on July 05,2021 at 15:54:17 UTC from IEEE Xplore. Restrictions apply.
This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication. Citation information: DOI 10.1109/TAC.2021.3086328, IEEE
Transactions on Automatic Control
6 GENERIC COLORIZED JOURNAL, IEEE TAC, VOL. XX, NO. XX, XXXX 2020

Price of Stock
63.7

3.5 uniform
binomial (p_u = 0.5) 63.6
3.0 binomial (p_u = 0.1)
63.5
2.5

2.0 63.4
E[gain]

1.5 63.3

1.0
63.2

0.5
63.1
0.0
63
0.0 0.2 0.4 0.6 0.8 1.0 0 2000 4000 6000 8000 10000 12000
p_e Transaction Number

Fig. 5. Expected Gain Versus pe for Distributions in Figure 4 Fig. 6. JPM Transaction Prices from 10am to 3:30pm on Jan. 4, 2016

Count
Now, by substituting this quantity into the expression for E[g], we 500

arrive at 450
(n−1)
2 (1 − qe (1 − pu + pu qe ) ) 400
E[g] = (n − 1)pu + 1 − .
pe (1 + qe (1 − pu + pu qe )(n−1) )
350
Figure IV-A provides a comparison of the n = 10 case where
300
once again the T-interval probabilities are all equal and, for the
binomial case, we consider the cases pu = 0.5 and pu = 0.1. For 250

the equiprobability uniform case and the binomial with pu = 0.5 the 200
results are seen to be quite similar across all values of pe . However,
150
with pu = 0.1, the distribution of interval lengths is skewed toward
being very short. Thus, in this case, our formula indicates that the 100
algorithm is expected to lose across the entire range of pe .
50

0
B. Example: JP Morgan Chase Intraday Prices 0 2 4 6 8 10 12 14
T-Interval Length
In this example, we work with historical data, and describe how the
analysis in this paper might be used by a practitioner. Specifically, we Fig. 7. Histogram of Interval Lengths for JPM Data in Figure 6
use transaction prices for JP Morgan (JPM) from 10:00am through
3:30pm extracted from the NASDAQ high-frequency ITCH data
for January 4, 2016. Half hour time periods around the open and prediction E[g(k)] ≈ 0.0025 which we compare with its realized
close were removed to provide a more consistent trading volume average g ≈ 0.0016. Finally, using the feedforward algorithm on the
pattern and transactions with the same nanosecond time stamp were actual data as seen in Figure 6, the overall gain was estimated to be
aggregated. The intraday price path for JPM is shown in Figure 6. $1.90, which is approximately 3% of the mean price of JPM.
To estimate the parameters of our T-interval model, we began with
the 10,112 prices in the price plot and consolidated them into 2996
V. C ONCLUSION
non-zero moves, 1485 up and 1511 down. From this starting point,
we estimated3 E(δ) ≈ 0.0095 and pe ≈ 0.5090 associated with these In this paper, we introduced the so-called T-model as a means for
transactions.4 A histogram of the T-interval lengths is provided in studying and exploiting trending behavior of stock prices. In addition
Figure 5 from which we see many Tk of length 1, the longest of to the Tk entering into the model, the probability of efficiency
length 13, and 10 that are of length 10 or greater. In all, there parameter pe was seen to be important. When pe and E[T ] are
were 1214 T-intervals from which we estimated E(T ) ≈ 2.4679 suitably large, as illustrated in the preceding high frequency example,
and E[qeT ] ≈ 0.2806. it was shown that a profitable stock-trading opportunity presented
Next, we turned our attention to application of the feedforward itself. On the other hand, for the low frequency case, although pe
controller of Section 3. Figure 8 provides a simulation of the may be suitably large, recalling the discussion in Section 2, for
resulting cumulative gain/loss function over time. Then on a per-T- E[T ] < 2 steady state trading is not expected to be profitable. To
interval basis, for the assumed steady state, we calculated the model study this further, we carried out a preliminary experiment using the
adjusted daily closing prices for Facebook for the five-year period
3 For the case of non-zero price changes, δ, when book walking occurred,
starting with 2015. Even for the best-case scenario with qe = 0
the value of δ was computed as the change from the previous transaction corresponding to efficient trades at the close, our estimated model
price to the end of the walk; see footnote in Section 2.
4 Here we allow for the possibility that a practitioner may efficiently enter predicts that trading is not profitable; i.e., E[T ] ≈ 1.9 < 2.
or exit a trade on sideways moves. Accordingly, such moves are included in As far as theory related to trading is concerned, we carried out
the calculation of pe . gain-loss analysis using a feedforward stock-trading controller which

0018-9286 (c) 2021 IEEE. Personal use is permitted, but republication/redistribution requires IEEE permission. See http://www.ieee.org/publications_standards/publications/rights/index.html for more information.
Authorized licensed use limited to: National University of Singapore. Downloaded on July 05,2021 at 15:54:17 UTC from IEEE Xplore. Restrictions apply.
This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication. Citation information: DOI 10.1109/TAC.2021.3086328, IEEE
Transactions on Automatic Control
AUTHOR et al.: PREPARATION OF BRIEF PAPERS FOR IEEE TRANSACTIONS AND JOURNALS (FEBRUARY 2017) 7

Gain-Loss Function g(k)


APPENDIX: P ROOF OF T HEOREM 3.2
2

We begin by noting that conditioning on both the length of the


1.5 interval T and the events of entering the interval on the correct or
incorrect side of the trade leads to the formula

1 X
E[g(k)] = E[g(k)|Ck ∩ Tk = t]P (Ck ∩ (Tk = t))
t=1

0.5
X
+ E[g(k)|Ik ∩ Tk = t]P (Ik ∩ (Tk = t)).
t=1

0
To calculate the first term above, note that by independence we have
P (Ck ∩ (Tk = t)) = PC (k)P (Tk = t). Moreoever, taking into
-0.5
account that the δi are independent of Tk , and that the trader loses
0 2000 4000 6000 8000 10000 12000 on the last move of each Tk interval, we obtain
Transaction Number

X
Fig. 8. Gain from Trading Algorithm for JPM E[g(k)|Ck ∩ Tk = t]P (Ck ∩ (Tk = t))
t=1

X
executes strategic switching between long and short stock positions = E[g(k)|Ck ∩ Tk = t]PC (k)P (Tk = t)
triggered by trend reversals. Based on work to date, we see four t=1

"t−1 #
directions for future work. X X
The first direction involves the independence assumptions which = E δi − δt PC (k)P (Tk = t)
t=1 i=1
were made in this paper. This includes the assumed independence
involving the Tk and the δi . To this end, we conducted some = E[δ] (E[T ] − 2) PC (k). (5)
preliminary calculations and concluded that further study is needed
regarding the extent to which statistically significant correlations may Next, to address the second term in E[g(k)] above, noting that
or may not exist. This would involve extensive use of historical independence implies P (Ik ∩ (Tk = t)) = PI (k)P (Tk = t), we
data and possibly motivate future theoretical research aimed at define event Ek corresponding to one or more efficient prices over
incorporation of correlation into the model. Interestingly, even if our interval Tk and denoting its complement by Ekc , we obtain
independence assumptions are not strongly supported, preliminary

experiments suggest that the controller which we are currently using X
E[g(k)|Ik ∩ Tk = t]P (Ik ∩ (Tk = t))
may still provide strong performance under a weakening of the
t=1
independence assumptions. ∞
X
The second direction for future research involves extending the = E[g(k)|Ik ∩ Tk = t]PI (k)P (Tk = t)
simple Markov formulation in Section III-B to capture more complex t=1
strategies and market behavior typically involving more than two ∞
E[g(k)|Ekc ∩ Ik ∩ Tk = t]P (Ekc )PI (k)P (Tk = t)
X
states. For example, one possibility involves introducing memory = (6)
considerations into the T-interval modelling; e.g., a Markov process t=1

could be used which enables one to relate the consecutive interval X
lengths Tk and Tk+1 . Going even further, one could consider a + E[g(k)|Ek ∩ Ik ∩ Tk = t]P (Ek )PI (k)P (Tk = t). (7)
t=1
regime switching model in which the market moves between a
“volatile” and “trending” state which are then exploited using separate
To compute (6), noting that conditioning on Ekc implies that no
strategies. In such cases, extensions of the analysis in this paper would
efficient point is encountered over interval Tk , the trader loses on
be required.
the first t − 1 ticks and wins on the last tick leading to a total loss
The third direction involves estimation of model parameters prior
of E[δ](2 − t) with probability qet . Thus, (6) becomes
to the commencement of trading. For example, one might consider
reserving the first hour after the market opens as the ”training period.” ∞
E[g(k)|Ekc ∩ Ik ∩ Tk = t]P (Ekc )PI (k)P (Tk = t)
X
Subsequently, if the expected gains are predicted to be attractive, we
enter into trading. t=1
"∞ #
The fourth direction for further work involves study of the T-
qet (2 − t)P (Tk = t) PI (k)
X
model using a larger class of controllers than considered here. In = E[δ]
this regard, the reader is reminded that we restricted attention to h t=1 i
feedforward control. One immediate direction for future work would = E[δ] 2E[qeT ] − E[T qeT ] PI (k). (8)
be to enhance the controller to include a feedback term which depends
on the account value V (k) as seen in Figure 1. Other possibilities Next, we address (7), which corresponds to the case when an efficient
include the use of random or anticipatory switching. transaction is encountered. Letting i be the first transaction at which
efficiency occurs, this happens with probability qei pe . Hence, for the
interval, there are losses for the first i ticks, gains for the next t−1−i
A. Acknowledgment
ticks, followed by a loss on the final tick. This gives a total gain (or
The authors acknowledge the valuable comments of the reviewers. loss) of E[δ](t − 2 − 2i). Thus (7) is calculated as

0018-9286 (c) 2021 IEEE. Personal use is permitted, but republication/redistribution requires IEEE permission. See http://www.ieee.org/publications_standards/publications/rights/index.html for more information.
Authorized licensed use limited to: National University of Singapore. Downloaded on July 05,2021 at 15:54:17 UTC from IEEE Xplore. Restrictions apply.
This article has been accepted for publication in a future issue of this journal, but has not been fully edited. Content may change prior to final publication. Citation information: DOI 10.1109/TAC.2021.3086328, IEEE
Transactions on Automatic Control
8 GENERIC COLORIZED JOURNAL, IEEE TAC, VOL. XX, NO. XX, XXXX 2020


[3] N. Jegadeesh and S. Titman S, “Returns to Buying Winners and Selling
X
(E[g(k)|Ek ∩ Ik ∩ Tk = t]P (Ek )) PI (k)P (Tk = t)
Losers: Implications for Stock Market Efficiency,” The Journal of
t=1 Finance, vol. 48, pp. 65-91, 1990.
" ∞ t−1 #
[4] C. S. Asness, T. J. Moscowitz, and L. H. Pedersen, “Value and Momen-
qei pe (t − 2
XX
= E[δ] − 2i)P (Tk = t) PI (k) tum Everywhere,” Journal of Finance, vol. 68, pp. 929-985, 2013.
t=1 i=0 [5] C. R. Harvey and Y. Liu, “Evaluating Trading Strategies,” Journal of
" ∞ t−1
! Portfolio Management, vol. 45, pp. 108-118, 2014.
[6] R. S. Tsay, Analysis of Financial Time Series, John Wiley and
qei
X X
= E[δ] pe (t − 2) P (Tk = t) (9)
Sons, 2016.
t=1 i=0 [7] A. Kanas, “Neural Network Linear Forecasts for Stock Returns,” Inter-
t−1
∞ X
#
national Journal of Finance and Economics, vol. 6,, pp.245-254, 2001.
iqei P (Tk
X
−2pe = t) PI (k). (10) [8] R. R. Trippi and E. Turban, editors, Neural Networks in Finance
t=1 i=0 and Investing: Using Artificial Intelligence to Improve Real World
Performance, McGraw-Hill, 1992.
Recognizing (9) as a geometric progression, we obtain [9] P. D. McNelis, Neural Networks in Finance: Gaining Predictive Edge
∞ t−1
! in the Market, Elsevier Academic Press, 2005.
X X i [10] M. L. De Prado, Advances in Financial Machine Learning, John Wiley
pe (t − 2) qe P (Tk = t) and Sons, 2018.
t=1 i=0 [11] J. B. De Long, A. Shleifer, L. H. Summers and R. J. Waldmann, “Noise

X 1 − qet Trader Risk in Financial Markets,” Journal of Political Economy, vol. 98,
= pe (t − 2) P (Tk = t) pp. 703-738, 1990.
pe [12] E. E. Peters, Fractal Market Analysis, John Wiley and Sons, 1994.
t=1
[13] P. Sieczka and J. A. Holyst, “Statistical Properties of Short Term
= E[T ] − 2 − E[T qeT ] + 2E[qeT ]. (11) Price Trends in High Frequency Stock Market Data,” Physica A, 387,
pp. 1218-1224, 2008.
Moreover, to compute (10), using the summation formula [14] L. Bachelier, The Random Character of Stock Market Prices, ed. P. H.
t−1
X i (t − 1)xt − txt−1 + 1 Cootner, MIT Press, Cambridge, Massachusetts, pp. 17-78, 1964.
ix = x , [15] P. A. Samuelson, “Proof that Properly Anticipated Prices Fluctuate
(1 − x)2
i=0 Randomly,” Industrial Management Review. vol. 6, pp. 41-49, 1965.
we obtain [16] R. C. Merton, Continuous Time Finance, Wiley-Blackwell, 1992.
∞ t−1 [17] Q. Zhang, “Stock Trading: An Optimal Selling Rule,” SIAM Journal of
iqei P (Tk
X X
−2pe = t) Control and Optimization, vol. 40, pp. 64-87, 2001.
t=1 i=0 [18] G. C. Calafiore, “Multi-Period Portfolio Optimization with Linear Con-
∞ trol Policies.” Automatica, vol. 44, pp. 2463-2473, 2008.
qe X  
[19] G. C. Calafiore, “An Affine Control Method for Optimal Dynamic
= −2 (t − 1)qet − tqet−1 + 1 P (Tk = t) Asset Allocation with Transaction Costs,” SIAM Journal on Control and
pe
t=1 Optimization, vol. 48, pp. 2254-2274, 2009.
 
qe 1 [20] B. R. Barmish and J. A. Primbs, “On a New Paradigm for Stock
= −2 E[T qeT ] − E[qeT ] − E[T qeT ] + 1 . (12) Trading Via a Model-Free Feedback Controller,” IEEE Transactions on
pe 1 − pe
Automatic Control, AC-61, pp. 662-676, 2016.
Substitution of (11) and (12) back into (9) and (10) leads to (7), [21] B. R. Barmish and J. A. Primbs, “Stock Trading Via Feedback Control
which when  added to (8) results in the sum of (6) and Methods,Encyclopedia of Systems and Control, T. Samad and J. Baillieul
 (7) as eds., 2020.
T 2 2  T 
E[δ] 2E[qe ] + E[T ] − + E[qe ] PI (k). (13) [22] C. H. Hsieh and B. R. Barmish, “On Drawdown-Modulated Feedback in
pe pe Stock Trading,” Proceedings of IFAC World Congress, vol. 50, pp. 952-
To complete the proof, noting the expected gain is the sum of (5) 958, Toulouse, 2017.
[23] V. Dombrovskii, T. Obyedko and M. Samorodova, “Model Predictive
and (13), using the formulae for PC (k) and PI (k) in Lemma 3.1 Control of Constrained Markovian Jump Nonlinear Stochastic Systems
and temporary notation and Portfolio Optimization Under Market Frictions” Automatica, vol. 87,
. pp. 61-68, 2018.
γ = (−E[qeT ])k /(1 + E[qeT ]), [24] V. Dombrovskii and T. Obyedko, “Model Predictive Control for Con-
strained Systems with Serially Correlated Stochastic Parameters and
a lengthy but straightforward calculation leads to Portfolio Optimization.” Automatica, vol. 54, pp. 325-331, 2015.
  [25] A. Bemporad, L. Bellucci and T. Gabbriellini, “Dynamic Option Hedg-
2 2  T 
E[g(k)] = E[δ] 2E[qeT ] + E[T ] − + E[qe ] PI (k) ing via Stochastic Model Predictive Control Based on Scenario Simula-
pe pe tion, Quantitative Finance, vol. 14, pp. 1739-1751, 2014.
+E[δ] (E[T ] − 2) PC (k) [26] J. D. O’Brien, M. Burke and K. Burke, “A Generalized Framework
   for Simultaneous Long-Short Feedback Trading,” to appear in IEEE
2 2 T  1
= E[δ] 2E[qeT ]+E[T ]− + E[qe ] −γ Transaction on Automatic Control, 2020.
pe pe 1 + E[qeT ] [27] J. A. Primbs and Y. Yamada, “Pairs Trading Under Transactions Costs
Using Model Predictive Control,” Quantitative Finance, vol. 18:6,
" #
E[qeT ] pp. 885-895, 2018.
+E[δ] (E[T ] − 2) +γ
1 + E[qeT ] [28] D. G. Luenberger, Investment Science, Oxford University Press, 2014.

2 (1 − E[qeT ])
= E[δ] E[T ] − +
pe (1 + E[qeT ])
" #!
T k 1 1 − E[qeT ]
2(−E[qe ]) −1 . 
pe 1 + E[qeT ]

R EFERENCES
[1] S. Achelis, Technical Analysis From A to Z, McGraw-Hill, 2000.
[2] W. Brock, J. Lakonishok, and B. LeBaron, “Simple Technical Trading
Rules and the Stochastic Properties of Stock Returns,” The Journal of
Finance, vol. 47, pp. 1731-1764, 1992.

0018-9286 (c) 2021 IEEE. Personal use is permitted, but republication/redistribution requires IEEE permission. See http://www.ieee.org/publications_standards/publications/rights/index.html for more information.
Authorized licensed use limited to: National University of Singapore. Downloaded on July 05,2021 at 15:54:17 UTC from IEEE Xplore. Restrictions apply.

You might also like