27writeup
TRANSCRIPT
-
7/29/2019 27writeup
1/12
The Penn-LehmanAutomated Trading
Project
Participants
Lawrence [email protected]
Hahn [email protected]
Faculty Advisor
Michael [email protected]
-
7/29/2019 27writeup
2/12
ABSTRACT
Billions of dollars change hands throughout the course of every business day on
Wall Street. At the basic foundation of this elaborate system of financial institutions are
traders, whose strategies can determine the profitability of their respective firms. Prior to
implementation, these strategies must be tested on simulated exchanges in order to
evaluate potential success for obvious reasons of capital and risk exposure that would be
necessary to conduct such experiments on actual exchanges. The Penn-Lehman
Automated Trading (PLAT) Project provides a framework called the Penn Exchange
Simulator (PXS) that realistically simulates an exchange by combining real-time
market data with automated client orders. All major Wall Street broker-dealers currently
maintain backtesting environments in which trading strategies can be tested based
primarily on price information. The uniqueness of PXS stems from the fact that it is
based primarily on order books, which keep track of current limit order data. This adds a
new level of realism to the automated trading platform and increases the accuracy of the
associated algorithms and strategies.
The PLAT project is structured in a way that multiple pools of automated trading
teams, or clients, compete against one another in the PXS market. The clients develop
automated trading strategies that maximize their returns by taking both long and short
positions while maintaining a balance between risk and return. Automated trading
strategy performance is measured on the basis of profitability, robustness, and good
trading practices. As PLAT competitions have been simulated in past years, the clients
must execute their strategies under the imposed limits: a single security may be traded
over the course of ten business days within a window of 100,000 shares. Our objective
-
7/29/2019 27writeup
3/12
is to develop an automated trading strategy that will maximize such performance
statistics given any number of market conditions. In developing such a strategy, we will
examine the assumptions underlying the various strategies of the past and determine the
necessary conditions for their success and a way to consistently outperform such
strategies.
RELATED WORK
A series of market trading strategies are based on price movement trend
prediction. These strategies each calculate their own threshold where if the current price
of the stock increases past this threshold then the strategy dictates to buy, and to sell if the
price decreases past the threshold. The motivation behind these actions is that when the
price of the stock crosses the strategy-determined threshold, it is perceived as an indicator
that the price will follow a trend moving in that direction. Therefore, if the price is
determined to be increasing, these strategies will buy, and sell if the price is determined
to be decreasing. These strategies use the stock price to predict price movement. The
Moving Average strategy uses the moving average statistic as its threshold, which is the
average price of the stock over an interval of time. The Channel Breakouts strategy
records the highest price and lowest price over an interval of time, and so whenever the
price increases beyond the interval high it will buy shares predicting an upward price
movement trend. The Momentum strategy looks at the general movement of the stock
price by comparing the current price with the price of the stock at a certain amount of
time before. A higher current price expresses upward movement, and a lower current
price expresses downward movement. The technical analysis statistics that these
-
7/29/2019 27writeup
4/12
strategies use to determine their thresholds are known to be useful to the stock trader, but
their simple derived trading strategies prove to be weak compared to other strategies
when simulated on PXS.
A reverse strategy has proven to be strong in PXS simulations. It does the
opposite of the price movement prediction strategies in that when it predicts an upward
trend in price, it sells instead of buys. The reason why the reverse strategy fares better
than the trend prediction strategies is that the market rarely follows trends uniformly. It
seems that trend prediction based on price alone is very weak in the short-term, and that
price volatility and order book data are much more pervasive factors in the scope of the
PLAT project.
The Relative Strength Index, a value between zero and one hundred, is an
indicator of strength of the stock compared to its past performance. A higher RSI means
that the average of upward price change is greater than the average of downward price
change, and speculates that the market has topped off. The RSI-based strategy will
therefore sell when the RSI value decreases past a certain high value, as this indicates that
the price will decrease. RSI predicts price movement without considering general price
trends, but still performs poorly in PXS simulations against other standard strategies.
The Market Making Agent takes a volatility-based approach rather than the
typical predictive pricing approach. Rather than attempting to predict the future direction
of the stock price movement, the Market Making Agent exploits the fluctuations of up
and down movements by simultaneously placing buy and sell orders of equal volume, the
buy order below the current price by some amount and the sell order above by some
amount. Intuitively, this makes sense since, in a sufficiently volatile price environment,
-
7/29/2019 27writeup
5/12
when the buy price is matched the agent buys in and when the sell price is matched the
agent neutralizes the buy order volume, in an attempt to achieve market neutral arbitrage.
Each time the pair is matched, the agent earns the associated spread. In order to adjust
for large one-way trends, the Market Making Agent incorporates both price and volume
controls, adjusting those values to alleviate such asymmetric scenarios.
The Static Order Book Imbalance Agent is a relatively simple algorithm based on
the buy and sell order book data from the Island ECN. It analyzes the disparity between
the limit order distributions, quantified by the volume weighted average price from the
respective books. The agent compares the spread between the volume weighted average
price of the limit order books and the current price, with respect to the buy and sell order
books. Based on a parameter, theta, if buy spreads are relatively higher than sell spreads,
a sell order is placed. If sell spreads are relatively higher, then a buy order is placed.
This makes sense because tighter spreads indicate lower demand and if the order books
exhibit relatively tighter sell spreads, for example, there is a higher probability that these
trades will be matched and thus the price would decrease. This agent would take
advantage of this probability and sell accordingly.
TECHNICAL APPROACH
Our technical approach is straightforward and has been outlined by the Penn-
Lehman Automated Trading Project. We will be implementing an automated trading
client strategy in the Unix environment. The PLAT Project provides us with a client API
which consists of those functions necessary to track applicable trading data as well as the
overall market state and to execute all trading functions in real-time, as the PXS is
-
7/29/2019 27writeup
6/12
continuously updated. Our client program will monitor the market data and send API
commands, such as buyOrder(), sellOrder(), and withdraw(), to the server at appropriate
times by way of our strategy.
The primary objective of the PLAT Project is to design and implement an
automated trading agent based on a strategy that outperforms both the market and all
other such strategies. In order to research the ideal strategy, we first established for
ourselves a background in finance as relevant to trading strategy.
With this foundation in place, we examined the provided five basic trading agents:
Moving Average, Channel Breakouts, Momentum, Relative Strength Index, and Market
Making. Using a variety of normal distributions for price environments, we ran all the
possible permutations of pairs in direct competition with one another, along with a set of
self-competing agents. Upon thorough
examination of all the strategy pairs, we came
to the conclusion that the Market Making
Agent was the dominant strategy in this
strategy pool.
MM (vs MA) Distribution 2
From this foundation, we expanded to the analysis of the most pertinent examples:
last years participant strategies. Since we have access to the results of actual simulation,
it is relatively apparent to see which strategies dominated the competition. As it turns out,
the strategies based on Static Order Book Imbalance seemed to perform the best and it
seems accurate that this is the case. The SOBI methodology makes the fullest use of the
available limit order books, the unique characteristic of the project. It also seemed like
the most logical predictor of price trends, taking into account actual limit orders, rather
-
7/29/2019 27writeup
7/12
MM (vs. MyTrader) 12/01/04 MyTrader (vs. MM) 12/01/04
than simply past price movements. After
experimenting with a number of variations of
both the Market Making Agent and the SOBI
Agent, as well as various combinations with the
basic strategies, we decided to focus on the
SOBI approach. The original algorithm based its decisions on the spread between the last
price and the volume weighted average price for both the buy and sell order books. We
decided to focus specifically on the total matched buy volume and total matched sell
volume at each instant of comparison. The basic theory behind this design is founded on
the assumption that a higher matched buy volume relative to sell volume indicates a
relatively higher demand for the stock and thus a likely indicator of a subsequent price
increase. Conversely, a higher matched sell volume relative to buy volume indicates a
relatively lower demand for the stock and thus a likely indicator of a subsequent price
decrease. If the matched buy volume equals the matched sell volume, we decided to
institute the market making strategy. Our previous strategy did not account for this
scenario. The relevant source code is shown below:
SOBI (vs. MyTrader) 12/01/04
i ntupdat eAgent Or der ( Cl i ent St ate *cSt ate, Market Stat e *mStat e,
Mar ket St at i sti cs *pxsSt at , Mar ket St at i sti cs *i St at ,Str ategy *mySt r at egy)
-
7/29/2019 27writeup
8/12
{
i nt cur r ent Shar e = 0;f l oat cur r ent Val ue = getSi mPresent Val ue(cStat e);f l oat cur r ent Pr i ce = get Si mLast Pri ce( mSt ate);f l oat qval ue = 0;f l oat * cur r ent Bi d = NULL;f l oat * cur r ent Ask = NULL;
i nt* Or der Ref = NULL;i nt j = 0;i nt NumbOf Or der = 0;
f l oat l as tPr i ce;si mTi me_t cur r ent Ti me = 0;i nt NumbOf BuyOr der = 0;i nt NumbOf Sel l Or der = 0;i nt* BuyOr der Share = NULL;i nt * Sel l Or derShare = NULL;i nt Tot al BuyShare = 0;i nt Tot al Sel l Share = 0;
i nt f l ag = 0; / / SET t hi s var i abl e at some poi nt dur i ng t he execut i on of t he aut omatedst r ategy bel ow t o 1 I F an order i s pl aced; other wi se SET i t t o 0
f l oat Si , Bi , Si 2, Bi 2;
curr ent Ti me = si mTi me( mStat e, NULL) ;
l ast Pri ce = get Si mLast Pr i ce( mSt ate);
i f ( curr ent Ti me mySt r at egy- >t het a){
/ * i f *buy- si de* vol ume l arger t han *sel l - si de* vol ume by more
t han t het a *// * pl ace a *buy* order f or order Vol ume shares at order Pri cedol l ars *bel ow* l astPri ce */buyOr der( l ast Pri ce- mySt r ategy- >orderPr i ce, mySt r ategy- >orderVol ume,
cSt ate, mSt ate) ;pr i nt f ( "buyOr der pl aced at [ %. 4f ] \ n", l ast Pri ce- mySt r ategy->or der Pr i ce) ;/ * i f hedgi ng, al so pl ace a *sel l * order f or order Vol ume shares athegdeOr derPri ce dol l ars *above* l astPr i ce */i f ( mySt r ategy- >hedgeFl ag){sel l Or der ( l ast Pri ce+mySt r ategy- >hedgeOr der Pri ce,
mySt r at egy- >order Vol ume, cStat e, mStat e) ;pr i nt f ( "hedgi ng sel l Or der pl aced at [ %. 4f ] \ n", l ast Pr i ce+mySt r at egy-
>hedgeOr der Pr i ce) ;}/ * set f l ag t o si gnal an order has been pl aced */f l ag = 1;
}el se i f ( ( Si - Bi ) > mySt rategy- >t het a){
/ * i f *sel l - si de* di f f er ence l ar ger t han *buy-si de* di f f er ence by mor et han t het a dol l ar s *// * pl ace a *sel l * order f or order Vol ume shares at order Pri cedol l ars *above* l ast Pri ce */i f ( l as tPr i ce > 0){
sel l Or der ( l ast Pri ce+mySt r ategy- >orderPr i ce, mySt r ategy- >orderVol ume, cSt ate,mStat e) ;
pr i nt f ( "sel l Or der pl aced at [ %. 4f ] \ n", l ast Pr i ce+mySt r at egy->order Pri ce) ;
-
7/29/2019 27writeup
9/12
/ * i f hedgi ng, al so pl ace a *buy* order f or or derVol ume shares athegdeOr derPr i ce dol l ars *bel ow* l astPr i ce */i f ( mySt r ategy- >hedgeFl ag) {buyOr der( l ast Pri ce - mySt r ategy- >hedgeOr derPr i ce,
mySt r at egy- >order Vol ume, cStat e, mStat e) ;pr i nt f ( "hedgi ng buyOr der pl aced at [ %. 4f ] \ n",
l ast Pri ce- mySt r ategy- >hedgeOr derPr i ce);}
/ * set f l ag t o si gnal an order has been pl aced */f l ag = 1;}
}el se i f (Bi == Si ){/ * set di f f erence between cur r ent pri ce and vol ume wei ght ed pr i ce
f or quart i l e * /Bi 2 = l ast Pri ce - get BuyQuart i l e( mSt at e, pxsSt at , mySt r at egy->quar t i l e) ;/ * set di f f erence bet ween cur r ent pr i ce and vol ume wei ght ed pr i ce
f or quart i l e * /Si 2 = getSel l Quart i l e( mSt at e, pxsSt at, mySt r at egy->quar t i l e) - l ast Pri ce;
pr i ntf (" Bi : %f Si : %f \ n", Bi 2, Si 2);
i f ( ( Si 2 - Bi 2) > mySt r at egy->t heta2){
/ * i f *sel l - si de* di f f er ence l ar ger t han *buy-si de* di f f erence by moret han t het a dol l ar s *// * pl ace a *buy* or der f or order Vol ume shar es at orderPr i ce
dol l ar s *bel ow* l astPri ce */buyOr der( l ast Pri ce- mySt r ategy- >orderPr i ce, mySt r ategy- >orderVol ume,
cSt ate, mSt ate) ;pr i nt f ( "buyOr der pl aced at [ %. 4f ] \ n", l ast Pri ce- mySt r ategy->or der Pr i ce) ;/ * i f hedgi ng, al so pl ace a *sel l * order f or order Vol ume shares at
hegdeOr derPr i ce dol l ars *above* l astPr i ce */i f ( mySt r ategy- >hedgeFl ag)
{sel l Or der( l ast Pri ce+mySt r ategy- >hedgeOr derPr i ce,
mySt r at egy- >order Vol ume, cStat e, mStat e) ;pr i nt f ( "hedgi ng sel l Or der pl aced at [ %. 4f ] \ n", l ast Pri ce+mySt r ategy-
>hedgeOr der Pr i ce) ;}
/ * set f l ag t o si gnal an order has been pl aced */
f l ag = 1;}
el se i f ( ( Bi 2 - Si 2) > mySt r at egy->t heta2){/ * i f *buy-si de* di f f er ence l ar ger t han *sel l - si de* di f f er ence by mor et han t het a dol l ar s *// * pl ace a *sel l * order f or order Vol ume shares at order Pri cedol l ars *above* l ast Pri ce */i f ( l as tPr i ce > 0){
sel l Or der( l ast Pri ce+mySt r ategy- >orderPr i ce, mySt r ategy- >orderVol ume, cSt ate,mStat e) ;
pr i nt f ( "sel l Or der pl aced at [ %. 4f ] \ n", l ast Pr i ce+mySt r at egy->orderPri ce) ;/ * i f hedgi ng, al so pl ace a *buy* order f or or derVol ume shares at
hegdeOr derPr i ce dol l ars *bel ow* l astPr i ce */i f ( mySt r ategy- >hedgeFl ag) {
buyOr der( l ast Pri ce - mySt r ategy- >hedgeOr derPr i ce,
mySt r at egy- >order Vol ume, cStat e, mStat e) ;pr i nt f ( "hedgi ng buyOr der pl aced at [ %. 4f ] \ n",
l ast Pri ce- mySt r ategy- >hedgeOr derPr i ce);}/ * set f l ag t o si gnal an order has been pl aced */f l ag = 1;
}}
}}
-
7/29/2019 27writeup
10/12
RESOURCES REQUIRED
Since this project is strictly code-based, we will need to connect to a remote Unix
server to implement our strategy. The provided PXS API documentation is all that is
needed to write all our source code. Designing our strategy, however, will prove to
require a considerable amount of research. We will need to gain a fundamental
understanding of market microstructure, as well as many algorithms, including basic
models and those algorithms used currently and in the past. Analysis of past PLAT
competitions and research articles will be the bulk of our research. The Wharton School
will also prove to be a valuable resource since it is an epicenter of financial research of
education. There is a tremendous amount of resources available to us, from the
Lippincott library to professors with similar research interests. Other sources of
information will be evinced as we delve deeper into the research process.
A great deal of the available literature on equity trading strategy is based on
valuation. While this is a valuable concept, it is not as useful to the PLAT Project, as the
competitions involve transactions of a single preset stock. In fact, much of the research
on stock price forecasting and trading strategy is not directly applicable to automated
trading strategy. However, the basic concepts put forth contribute valuable background
on fundamental financial principles and, albeit indirectly, contribute to both the
understanding of current trading agents as well as the formulation of a new strategy. For
example, the Static Order Book Imbalance strategy is explained in a high-level fashion on
the website dedicated to it (http://www.cis.upenn.edu/~mkearns/projects/sobi.html), but
some of the literature dedicates an entire chapter to the theory (Lo and MacKinlay 378)
-
7/29/2019 27writeup
11/12
TIMETABLE
Completed?September November
Project orientation
Account setup
Initial research fundamental finance concepts
Further research algorithmic approaches
Begin Implementation
Strategy testing
December
Initial prototype finalized
First Competition
Analysis of results
J anuary March
Further research using result analysis
Revision of strategy
Re-implementation
April
Complete final version of client
Final competition
CONCLUSION
In formulating our strategy, we made the assumption that the objective of the
project was to develop an algorithm that could feasibly be used regularly as a trading
strategy by an investment bank. While we considered strategies that would distort this
microcosm of a market (not a difficult task), we decided this would be against the spirit
of the project. Ultimately, another group exploited this fact and thereby won out. In
addition, some of the strategy we added in an attempt to repair former problems seem to
have caused other problems, one of which was not testing for artificial excess volatility.
-
7/29/2019 27writeup
12/12
Though we are now graduating, we plan to informally continue our project and to
research more on optimal equity trading strategy. While we may not have found that
strategy just yet, we feel that we have learned a great deal this year not only about the
technical aspects of Wall Street but also the about the underlying financial theory.
REFERENCES
Blau, William. Momentum, Direction, and Divergence. New York City, NY. JohnWiley & Sons, Inc. 1995.
Cragg, John G. and Malkiel, Burton G. Expectations and the Structure of Share Prices.Chicago, IL. The University of Chicago Press, 1982.
Feng, Y i, Yu Ronggang, and Stone, Peter. Two Stock-Trading Agents: Market Makingand Technical Analysis. 2003.
Grossman, Sanford J. The Informational Role of Prices. Cambridge, MA.
Massachusetts Institute of Technology Press. 1989.
Kearns, Michael and Ortiz, Luis. The Penn-Lehman Automated Trading Project. IEEEIntelligent Systems. November/December 2003.
Kearns, Michael and Ortiz, Luis. The Penn-Lehman Automated Trading Project(Extended Version). 2003.
Kearns, Michael and Ortiz, Luis. The Penn-Lehman Automated Trading Project: 2004-
05. Levy, Robert A. The Relative Strength Concept of Common Stock Price Forecasting.
Larchmont, NY. Investors Intelligence, Inc., 1968.
Lo, Andrew W. and MacKinlay, Craig A. A Non-Random Walk Down Wall Street.
Princeton, NJ. Princeton University Press, 1999.
Rossi, Peter E. Modeling Stock Market Volatility. San Diego, CA. Academic Press,Inc., 1996.
Shiller, Robert J . Market Volatility. Cambridge, MA. Massachusetts Institute ofTechnology Press. 1989.