Docstoc

Abstract

Document Sample
Abstract Powered By Docstoc
					Computer Science Honors                                                      Renegade: Market Surveillance Replay



Contents
Introduction ......................................................................................................................... 2
Project Domain ................................................................................................................... 3
   Electronic Stock Exchanges ............................................................................................ 3
   Regulation of the Market System ................................................................................... 3
   Trade Through Violations ............................................................................................... 5
   The Order Protection Rule .............................................................................................. 5
   The Access Rule ............................................................................................................. 6
   Project Objectives ........................................................................................................... 6
   Extended Goals ............................................................................................................... 6
Analysis............................................................................................................................... 7
   Basic Requirements ........................................................................................................ 7
   Inputs Analysis................................................................................................................ 7
   Outputs Analysis ........................................................................................................... 10
   Data flow in the system................................................................................................. 11
   Overview of the System – “Renegade” .....................Error! Bookmark not defined.11
   Detection Methodology ................................................................................................ 14
Design ............................................................................................................................... 15
   Data Structures an Database Design ............................................................................. 15
   Operational & Processing Logic ................................................................................... 15
   Application Structure – Threads & Processes .............................................................. 16
   Entity Classes in the system .......................................................................................... 18
   Boundary Classes of the System ................................................................................... 19
   Control Classes of the System ...................................................................................... 20
   Testing Classes.............................................................................................................. 21
   Class Organization & Packages .................................................................................... 21
   Class Communication Structure ................................................................................... 22
   System State Changes ................................................................................................... 23
   User Interface Design ................................................................................................... 23
   Test Plan........................................................................................................................ 25
Implementation ................................................................................................................. 26
   Class Implementations .................................................................................................. 26
   User Interfaces .............................................................................................................. 26
Maintenance ...................................................................................................................... 29
   Improvements to the System ......................................................................................... 29
Glossary ............................................................................................................................ 31
References ......................................................................................................................... 32




2006 - 2007                                                                                                                            1
Computer Science Honors                                  Renegade: Market Surveillance Replay


Introduction

In the past, securities trading was conducted in separate markets with thousands of
brokers and traders gathering at the floor each trading day for the opening bell and
shouting out their bids and asks to fulfill their orders. However, this led to trading
fragmentation and poor customer executions resulting from trading of securities in
separate, unconnected markets. In 1975, congress directed the SEC to facilitate the
development of a national market system (NMS).1

Through time, the operation of capital markets has progressively been moving towards
interconnectivity, computerization and automation. The development of communication
networks and computer technology has enabled fast and effective dissemination of
financial information. Financial markets have incorporated these advances to aid the
recording and synchronization of trading information across markets over a vast
geographical area. Networks have facilitated the worldwide integration of markets
enabling the transmitting information within milliseconds to reflect trades and price
changes as they occur. This resulted in the birth of Alternative trading systems (ATS).

One type of ATS is an Electronic Communications Network, or ECN. An ECN, as
defined by the SEC, is a trading system that automatically matches buy and sell orders at
specified prices.2 Today, ECNs account for approximately 40% of total dollar volume of
Nasdaq traded securities.3 Some of the ECNs operating today are Instinet, Island,
Archipelago and NexTrade.

The Inter-market Trading System (ITS) facilitates the communication of financial data
across ten markets including the American Stock Exchange, Boston Stock Exchange,
NYSE and Philadelphia Stock Exchange. ITS is a computer network that enables the
transmission of trades and quotes between exchanges allowing trades to take place
between them. The orders are usually routed to the various exchanges to obtain the best
possible prices.

Although automation and computerization has enhanced the securities trading industry,
increased accuracy of information and the speed of execution, it has also created new
opportunities for traders to take unfair advantage to make profit.

In order to extend the regulations enforced on trading practices and increase fairness in
the markets, the SEC released a document known as the RegNMS (Regulation of the
National Market System) which describes new directives electronic trading centers are
obligated to abide by.

This project aims to develop a method allows the monitoring of trades and quotes in an
exchange to verify that the RegNMS requirements are adhered to.

1
    http://www.sec.gov/divisions/marketreg/mrecn.shtml
2
    http://www.sec.gov/divisions/marketreg/mrecn.shtml
3
    http://www.sec.gov/news/studies/ecnafter.htm#pt2i



2006 - 2007                                                                                2
Computer Science Honors                                                  Renegade: Market Surveillance Replay



Project Domain
Electronic Stock Exchanges

Electronic Communication networks (ECN) operate by attempting match bids and offers
that are via a computer system. But this is usually done outside of exchanges. Initially,
broker-dealers provide internal matching using crossing networks; if an order is unable to
match internally, it will route the order to other exchanges via the ITS to obtain the best
possible prices. Most electronic exchanges display their best bid and offer publicly to
other exchanges. Complex computer software carries out the routing, matching, and
reporting orders.

A typical trading system consists of a central server that carries out the process of
matching bids and asks based on predefined rules. The matching server is generally
responsible for maintaining an order book by temporarily storing orders that are not
executed. Client terminal software communicates with the matching server allowing a
trader to submit trades into the system. Once an execution occurs, a matching server
forwards the match data to another system that is responsible for clearing the trade and
distributing trading information to other clients.

Regulation of the Market System

As ECNs become more widespread, greater control is required to ensure integrity and
fairness. Therefore, the Securities and Exchange Commission constructed a set of rulings
known as Regulation NMS or RegNMS which describes four main rules to maintain fair
trading practices: (1) Order Protection rule or Trade Through rule (2) Access rule (3)
Sub-Penny rule and (4) Market Data rule.

Guided by this, electronic exchanges are now required to have advanced surveillance
capabilities to allow exchanges to monitor trades and prove to the SEC that the
exchange’s trading practices are in accord to these rulings. This ruling also extends to all
market participants, including the crossing networks used for internalization. Many
exchanges and trading participants are developing additional software to aid in these
tasks.4

In light of the automation of trading services and advances of technology, the European
Union is also taking steps to regulate and standardize the operations through a set of
rulings similar to RegNMS, known as MiFID5 (Markets in Financial Instruments
Directive). MiFID also defines a rule known as the “Best Execution Rule”, equivalent to
the RegNMS Order Protection Rule, to ensure a trader achieves the best possible price.



4
    Mike Coughlin, Boston Stock Exchange
5
    http://www.fsa.gov.uk/Pages/About/What/International/EU/fsap/mifid/index.shtml



2006 - 2007                                                                                                3
Computer Science Honors                                Renegade: Market Surveillance Replay


This project will focus primarily on the Order Protection rule or Trade Through rule
defined in the RegNMS. This rule was initially introduced in 1970, but now is refined
and extended towards electronic trading systems. My project will attempt to identify
possible violations of this rule and provide notification to surveillance administrators who
wish to justify the use of fair trading practices.

As quoted by Colin Clark of Kaskad Technology6, the effects of the RegNMS “Order
Protection rule” or the MiFID “Best Execution rule” can be described as follows:

            “If one wanted to purchase a new washer/dryer from a hardware store,
            under the old market system, the price one would pay is the price that
            is listed at the store for that item. However, according to the new
            regulations, the price that the customer would have to pay would be
            the best price that is offered by every store that sells washers/dryers.
            Therefore the store would be obligated to provide the item to the
            customer at this price.”

Therefore, under the new rulings, when an exchange received an order, if it does not have
the best bid or offer among all the exchanges, the exchange is obligated to route that
order to another market center for execution.

However, this rule also brings in new complications. One is that, when an order is routed
to another market center, due to lag in networks and differences in processing speeds of
market centers and participants, the order may risk not being executed at the advertised
price or even not being executed at all. Therefore it is a trade off between achieving the
best execution or the quickest execution. In order to mitigate the consequences, the SEC
also introduced specific conditions that exempt trades from this rule. These conditions are
stated under the “Order Protection Rule” section.

In order to attempt to determine the best price at a given time, it is essential to have
information on the consolidated quotes made by the entire NMS and trades made by an
exchange in order to. This information can currently be accessed via two primary
information servicing organizations known as Securities Industry Automation
Corporation (SIAC) for NYSE listed equities and Securities Information Processor (SIP)
for NASDAQ listed securities.

Using the best bid and offer information, an exchange is able to construct a price range
within a time frame from its trade and prove to regulating authorities that the trade was
conducted at a price within that range, and therefore it is in accord with the regulations. It
is important to use a short time frame before the trade to allow for delays caused in
information dissemination and order routing as described above.




6
    http://www.mifidpodcast.com/



2006 - 2007                                                                                 4
Computer Science Honors                                Renegade: Market Surveillance Replay


Trade Through Violations

 “A trade through occurs when one trading center executes an order at a price that is
inferior to the price of a protected quotation, often representing a limit order 7, displayed
by another trading center.”8

Example: The following diagram describes a Level II quotation system. A level II
quotation describes the bids and offers for a particular security quoted by all exchanges
trading that security at a given time. As illustrated below, NYSE (New York Stock
Exchange) contains a Bid for 100 @ $98.80 and PCX (Pacific Stock Exchange) contains
an Ask for 200 @ $99.00 at the top of the order book. Supposing that PCX prints a trade
for 100 at $98.50 executed internally; we can see that, this price is inferior to the bid that
is made by NYSE for 98.80. Therefore, the trader that made the offer at PCX did not
receive the better price of 98.80, as he rightfully should have. Therefore, he incurs a loss
of, 98.80-98.50 = $0.30 per share.

                         Bid                                       Offer
BSE                     100              $ 98.80   $ 99.00         200              PCX
NYSE                    100              $ 98.75   $ 99.50         100              M

A trade through prevents the limit orders of investors from being filled as they are
bypassed by inferior orders. Trade throughs are currently quite significant in both Nasdaq
and exchange traded stocks. Approximately 1 of every 40 trades in both Nasdaq and
NYSE stocks represents a trade through of a displayed quotation. 9 The Trade-Through
Rule was introduced to protect investors against this scenario.

The Order Protection Rule
The Order Protection rule establishes intermarket protection against trade-throughs for all
NMS stocks10. It aims to protect limit orders and promote fairness and orderly trading.

Briefly, this rule states that (1) An exchange must design its procedures and systems to
enforce and maintain policies to prevent a trade through and (2) A trading center must
surveil its activities regularly to ascertain the effectiveness of these policies.

However, this rule only applies under two primary conditions. Trades that do not meet
these conditions are exempt from this rule.
    (1) The trade through rule only applies to protected quotations.
    (2) The rule only protects automated quotations.



7
    See Glossary.
8
    Page 12, REG NMS document 34-50870
9
  Page 16, REG NMS document 34-50870
10
   See Glossary



2006 - 2007                                                                                 5
Computer Science Honors                             Renegade: Market Surveillance Replay


The SEC believes that intermarket price protection would benefit investors and
strengthen the NMS.

The Access Rule
In tandem with the Order Protection Rule is the Access rule. This rule requires

       “All US equity markets to provide real-time access to the best
       quotation and most recent trades throughout the day.”

This ensures that all market centers are synchronized and prevents them from executing
orders at a price inferior to one displayed at another market place. This rule is facilitated
by:
(1) Using a private linkage to allow access to quotes and
(2) Regulating the fees charged by an exchange for incoming orders executing against
their quotes implement this rule.

Project Objectives
The primary goals of this project is to develop a system that can:
    Scan through a set of trades and quotes to filter out possible trade through
       violations.
    Display the violation with a warning message to the user.

Extended Goals
The proposed system may contain the following additional functions. They are however
are not required for the achievement of its goals.
     Display statistics such as the number of violations that occur per exchange.
     Suggest which exchanges are better for specific equities.




2006 - 2007                                                                                6
Computer Science Honors                                   Renegade: Market Surveillance Replay



Analysis
Basic Requirements
    Replay quotes and trades over a time period.
    Allow the user to specify the time period over which the quotes are replayed.
    Scan quotes and trades to find possible trade through violations.
    Display results to the user.

Inputs Analysis
        In order to find a trade through violation, it is necessary to have quotations from
all exchanges at any given time. This is crucial in determining the national best bid and
offer (NBBO) at any time. This involves obtaining the “consolidated” quotations from a
market data distributors such as SIAC11 and SIP12.
        However, the costs of connecting to such distributors and obtaining real-time (or
delayed information) are high. Therefore, Kaskad Technologies13, Boston MA has agreed
to provide me with access to a database containing delayed SIP/SIAC quotes and trades
for the consolidated market system.
        Kaskad Technologies is a producer of surveillance tools for the capital markets
industry. They specialize in using Event Stream Processing14 technology to analyze and
detect violations to the regulatory policies enforced by the SEC and assist Boston Stock
Exchange in maintaining a fair position in the market. Kaskad Technologies currently
owns a system for finding trade through violations.
        Due to the high costs obtaining real-time information, and avoiding redundant
systems, this project direction was changed to developing a system for replaying and
recreating trade through scenarios on delayed information.

Trade Inputs:
Based on the SIAC messaging formats and the structure of the Kaskad database holding
the trade information, a trade message contains the following field specifications:

Field Name                         Data Type         Length     Comments
DATA_STREAM_ID                     VARCHAR         20           Internal Primary Key
DATA_STREAM_TIMESTAMP              VARCHAR         20           Internal Primary Key
PARTICIPANT_ID                     CHAR            1
TRADE_TIMESTAMP                    TIMESTAMP
SEC_SYMBOL                         VARCHAR         11
SELL_SALE_DAYS                     INTEGER
SALE_COND                          CHAR            6
TRD_PRICE                          DOUBLE          2 Decimals
TRD_SIZE                           INTEGER


11
   Securities Industry Automation Corp.
12
   Securities Investment Planning
13
   Website: ww.kaskadtech.com
14
   http://en.wikipedia.org/wiki/Event_Stream_Processing


2006 - 2007                                                                                 7
Computer Science Honors                         Renegade: Market Surveillance Replay


*More detailed information of the message format, values and field descriptions can be
found in the SIAC Consolidated Tape System specification document.

Quotation Inputs:

Based on the SIAC messaging formats and the structure of the Kaskad database holding
the consolidated quote information, a quotation message contains the following field
specifications:

Field Name                              Data Type     Length   Comments
DATA_STREAM_ID                          VARCHAR                Internal Primary Key
DATA_STREAM_TIMESTAMP                   VARCHAR                Internal Primary Key
PARTICIPANT_ID                           CHAR         1
QUOTE_TIMESTAMP                          TIMESTAMP
SEC_SYMBOL                               CHAR         11
BID_PRICE                                DOUBLE
BID_SIZE                                 INTEGER
OFFER_PRICE                              DOUBLE
OFFER_SIZE                               INT
NASD_MKT_MAKER_ID                        CHAR         6
NASD_MKT_MAKER_GEO_LOC                   CHAR         6
NASD_MKT_MAKER_DSK_LOC                   CHAR         6
NAT_BBO_IND                              INTEGER
NASD_BBO_IND                             INTEGER
BBID_PART_ID                            INTEGER       LONG
BBID_PRICE                               DOUBLE
BBID_SIZE                                INTEGER
BBID_NASD_MKT_MKR_ID                     CHAR         6
BBID_NASD_MKT_MKR_GEO_LOC                CHAR         6
BBID_NASD_MKT_MKR_DSK_LOC                CHAR         6
BOFFER_PART_ID                          INTEGER       LONG
BOFFER_PRICE                             DOUBLE
BOFFER_SIZE                              INTEGER
BOFFER_NASD_MKT_MKR_ID                   CHAR         6
BOFFER_NASD_MKT_MKR_GEO_LOC              CHAR         6
BOFFER_NASD_MKT_MKR_DSK_LOC              CHAR         6
NASD_BBID_PRICE                          DOUBLE
NASD_BBID_SIZE                           INTEGER
NASD_BBID_NASD_MKT_MKR_ID                CHAR         6
NASD_BBID_NASD_MKT_MKR_GEO_LOC           CHAR         6
NASD_BBID_NASD_MKT_MKR_DSK_LOC           CHAR         6
NASD_BOFFER_PRICE                        DOUBLE
NASD_BOFFER_SIZE                         INTEGER
NASD_BOFFER_NASD_MKT_MKR_ID              CHAR         6
NASD_BOFFER_NASD_MKT_MKR_GEO             CHAR         6
NASD_BOFFER_NASD_MKT_MKR_DSK             CHAR         6

*More detailed information of the message format, values and field descriptions can be
found in the SIAC Consolidated Tape System specification document.

User Inputs & Operational Parameters:


2006 - 2007                                                                           8
Computer Science Honors                             Renegade: Market Surveillance Replay



In addition to the information that is necessary for detecting a trade through, the system
would require the following inputs from the user.
     Starting Date/Time for replay
     Ending Date/Time for replay
     SEC Symbol to which to scan for trade through violations.
     Base participant/exchange that is looking for violations.

Re-creating the National Best Bid/Offer (NBBO)

As explained previously, in order to detect a trade through violation, it is necessary to
know the best bid and offer quoted by the entire national market system at each point in
time. In addition, we would also need to know which participant is responsible for this
NBBO. It is also important to note that two different participants may quote the best bid
and offer. Therefore, in order to detect a trade through violation, the following
information needs to be encapsulated with the NBBO.

                       Field                               Description
         BestBid_DATA_STREAM_ID           Unique Identifier of quote representing NBBO
         BestBid_QUOTE_TIMESTAMP          Time NBBO was made
         BestBid_PRICE
         BestBid_SIZE
         BestBid_PARTICIPANT_ID           Participant quoting NBBO
         BestOffer_DATA_STREAM_ID         Unique Identifier of quote representing NBBO
         BestOffer _QUOTE_TIMESTAMP       Time NBBO was made
         BestOffer _PRICE
         BestOffer _SIZE
         BestOffer _PARTICIPANT_ID        Participant quoting NBBO

Data Volume and Hardware Requirements

Currently, quotes and trade messages are produced at a rate of about 150 million –
200,million messages per day on equity alone. Therefore, in a single day, several
gigabytes of data are produced. However, the proposed system does not need to store this
volume of information at any one time. It will stream a set of this information, keeping it
in memory as it is analyzed for violations. Therefore, a sufficient amount of RAM will
be required to process a data set in a given time span. The data can be warehoused on a
separate high-capacity data management system and transmitted to the violation-
processing engine via a TCP connection.

Since the system is used to replay violation scenarios, and does not operate real-time, the
processing speed is flexible, and should provide results in a reasonable amount of time.
10-30 minutes for an average dataset consisting of a single day’s quotes and trades is
acceptable. The system can be run in batch on a delayed set of data to prove the existence
of violations.




2006 - 2007                                                                              9
Computer Science Honors                            Renegade: Market Surveillance Replay



Data Storage & Access

The quotes and trades data needs to be stored on the system so it may be accessed, sorted
and filtered quickly to extract the necessary information. In addition, information on
violations that were discovered needs to be stored in a systematic manner so the user may
view it. In order to perform such operations, a database management system is the most
suitable. The Boston Stock Exchange currently uses an Oracle Database for the storage of
SIP/SIC quotes/trades data.

Outputs Analysis
A user will require the system to produce information on violations. This information
would include:
    Details of the trade that violated the policy.
    Details of the conditions that were violated, in the case of the order protection
       rule, details of the quotes and bid/offer prices that were violated.
    Monetary value that was lost from the violation (price difference x number of
       shares).
    Statistical data including the number of quotes and trades scanned and violations
       detected.

The structure of the information produced and stored is described in more detail here.

Violation Information:

Field Name             Data Type               Length               Comments
EXCEPTION_ID           INTEGER                                      Auto increment
TRADE_ID               STRING
TRADE_PRICE            DOUBLE                  2 decimals
TRADE_SIZE             INTEGER
TRADE_TIME             TIMESTAMP
TRD_PART_ID            CHAR                    1
QUOTE_ID               STRING
BO_PRICE               DOUBLE                  2 decimals
BO_SIZE                INTEGER
BO_TIME                TIMESTAMP
BO_PART_ID             STRING
VALUE_LOST             DOUBLE                  2 decimals

Statistical Information:
     Total number of trades scanned.
     Total number of quotes scanned.
     Total number of violations found.




2006 - 2007                                                                              10
Computer Science Honors                                    Renegade: Market Surveillance Replay


Data flow in the system



       Quotes                                     Violation/Stats
                     Quotes
      Database                                                             User
                                    Detection
                                     System           Violation
                                                      Data
       Trades          Trades
      Database                                                Violations
                                                              Database


System Overview




                                                  System




                 Figure: Four primary steps in the detection process illustrated above.


   Retrieve data from the database that stores the quotes and trades.
   Parse this data and create a stream of NBBOs.
   Compare the trades to the NBBOs at a time window before the trade.
   If a violation is detected, record the necessary information.
   Display the results to the user.

Each use case of the detection process is broken down to produce a detailed outline of the
processing required at each stage.

1. Retrieve data use case




2006 - 2007                                                                                 11
Computer Science Honors                         Renegade: Market Surveillance Replay




Steps:
    Connect to data source – database
    Login to database
    Retrieve quotes/trades data set from database using query.

2. Parse data use case




Steps:
     Read quotes retrieved from previous use case.
     Extract values from fields
     Find NBBO at the time of the quote.
    Read prices.
    Check NBBO indicator.


2006 - 2007                                                                      12
Computer Science Honors                         Renegade: Market Surveillance Replay


   Create NBBO object.
    Add NBBO to sequential stream of NBBOs.
   Acquire lock for stream.
   Insert NBBO object.
   Release lock on stream.

3. Analyze data use case




Steps:
     Find NBBO at trade time.
    Read NBBO stream.
    Compare NBBO and trade time.
     Read trades.
     Detect for violations.
    Check for exemptions.
    Check violating conditions.
    Alert user.
    Generate and store violation information.




2006 - 2007                                                                      13
Computer Science Honors                             Renegade: Market Surveillance Replay


4. Display results use case




Detection Methodology

 Read a trade from the database.
 Traverse stream of NBBOs until an NBBO within a fixed frame period before the
  trade is found (see diagram below).
 Check that trade for exempting conditions. There are two exempting conditions.
      1) If the trade is not made by the running exchange, in this case, BSE, the trade
          is exempt. This is because we are only checking the running exchanges
          compliance with RegNMS.
      2) If a trade has a sale condition of “L” (Sold last) or “Z” (Sold out of sequence),
          the trade is exempt.
 Verify if a trade occurred at a price greater than or equal to National Best Bid or less
  than or equal to National Best Offer.
 If the trade is a violation, record necessary information (described above in Output
  Analysis).
 Otherwise continue to compare the subsequent NBBOs that fall within the time frame
  up until the time of the trade.
 Now, move onto the next trade and repeat steps.


                   (trade_time – fixed_period)   trade_time
                                                                  NBBO
                                                                  stream
                                    Time Frame




2006 - 2007                                                                            14
Computer Science Honors                            Renegade: Market Surveillance Replay



Design
Data Structures an Database Design

The database is to be designed based on the previous field specifications provided in the
Input and Output Analysis sections.

The renegade system will use one data structure, a queue. It is used to produce the
stream of NBBO quotations to be used by the analyzing processes. The data structure will
be implemented as a linked list.

    NBBO@Time0             NBBO@Time1             NBBO@Time2             NBBO@Time3




Both streaming and analyzing operations will share this data structure. The shared
operation is described in more detail below. The streamer is to be built to allow for
additional queues of data if necessary in the future.

Operational & Processing Logic

Finding the NBBO

   o Set the first quote read as the initial NBBO.
   o On each subsequent quote, check the National BBO indicator field
     (NAT_BBO_IND) for its value. The SIAC specification describes the effect of
     the value of this field on the NBBO. Therefore, change the NBBO as follows.

        NAT_BBO_IND value                         Effect on NBBO
               0                  No change, previous NBBO remains.
               1                  Current quote is the new NBBO.
               2                  No change, previous NBBO remains.
               4                  Either Bid or Offer is the new NBBO. Change
                                  accordingly. (If bid is greater than current best
                                  bid, update NBBO bid, if offer is less than the
                                  current best offer, update NBBO offer).
                   6              Same as 4.

Finding the value lost in a violation

   o If the trade_price < best_bid_price, then value_differential = best_bid_price –
     trade_price
   o If the trade_price > best_offer_price, then value_differential=trade_price –
     best_offer_price.



2006 - 2007                                                                             15
Computer Science Honors                             Renegade: Market Surveillance Replay


   o If trade_size < best_bid/offer_size, then share_size = trade_size. Otherwise,
     share_size = best_bid/offer_size.
   o Value lost = value_differential x share_size x 100 (Shares multiplier).

Accessing the shared NBBO queue

The NBBO queue is to be shared be both the streamer and analyzer mechanisms.
Therefore, it is necessary to create a locking mechanism to avoid deadlock or lost update
situations. Three simple steps will be followed in order to make the queue operations
atomic.

Three primary queue operations which lead to modifications in the queue structure will
use this locking mechanism: (1) enqueue (2) dequeue (2) peek.

   o   Acquire lock for queue object.
   o   Carry out operation – enqueue, dequeue, peek
   o   Release lock for queue object.
   o   Return

Application Structure – Threads & Processes


                                           Main
                                        <<Process>>


            GUI Window                  Streamer                   Analyzer
            <<Thread>>                 <<Thread>>                 <<Thread>>




                                               NBBO Queue
                                               (Shared data)


NBBO Queue operation

As illustrated by the diagram above, the Streamer and Analyzer threads access a shared
data queue in memory. This may lead to a deadlock or lost update scenario if both
processes attempt to modify the queue at the same time. Therefore, a locking mechanism
will be used that will allow a thread to lock the NBBO queue when it is operating on it.
[Refer previous section for a description of this mechanism.]

Inter-thread Communication




2006 - 2007                                                                              16
Computer Science Honors                              Renegade: Market Surveillance Replay


The analyzer thread, the streamer thread and the gui thread will need to communicate
with each other in order to verify the operating states of each thread and synchronize their
operation. This inter-thread communication will be established by passing a reference of
each thread object to the others. Hence, any thread may control the others by calling a
public method of a thread. This method will modify public variables within each thread
and thereby control the thread’s operation.

System Startup, Execution and Ending Sequence

Initially, when the user runs the system, the GUI thread would start up. This provides the
console window and allows the user to control the system. Upon initialization of the
system, the shared data queue will be created in memory along with the streamer and
analyzer and other related objects. Then, once the user initiates the detection processes,
the streamer process would start first. This ensures the presence of the NBBO stream in
memory with the necessary data. Next, the analyzer thread would start. This thread would
then access the data from the queue and use it to do the necessary analysis operations.

If the streamer is completed processing quotes before the analyzer is completed, the
streamer thread will end. However, the NBBO queue and the analyzer will remain
operating until it is completed its operation. If the analyzer finishes inspecting the trades
before the streamer is completed processing quotes, the analyzer will end the streamer
thread prior to ending itself. It is unnecessary to process any further quotes if there are
not trades to analyze.

Logging Mechanism

The streamer and analyzer threads will be associated with the LogHandler class that will
create a separate log file for the operations carried out by each of these threads. The name
is this log file can be provided through the calling objects and is appended with the
current date. A new log file is created for each day. The log file names will be of the
format filename_date.log, where the date is in mm_dd_yy format.
(eg. “streamer_12_24_06.log”)

If no filename is specified by the calling class, the logs will automatically be written to a
file named default_<date>.log.

Log files will log messages of queries are being executed (including fields and values),
the start and end of key processes (stream and analyze), data of volumes processed and
any error messages generated by the system.

There will be two types of log messages: (1) notification messages (2) error messages.
Notification messages store general operational activities while error messages store
information on errors which are encountered. Each log message will store information on
the class name of the calling object, method//function name generating the log and any
message that is to be printed.




2006 - 2007                                                                                 17
Computer Science Honors                      Renegade: Market Surveillance Replay


The format of a log message is as follows:

NOTIFY|ERROR : CLASS_NAME : METHOD_NAME | MESSAGE


     <<instance>>                                                <<instance>>
     streamer_log                                                 analyze_log


                         <<instance>>         <<instance>>
                          LogHandler           LogHandler




                         <<instance>>         <<instance>>
                           Streamer             Analyzer




Entity Classes in the system




2006 - 2007                                                                     18
Computer Science Honors          Renegade: Market Surveillance Replay


Boundary Classes of the System




2006 - 2007                                                       19
Computer Science Honors         Renegade: Market Surveillance Replay


Control Classes of the System




2006 - 2007                                                      20
Computer Science Honors                           Renegade: Market Surveillance Replay



Testing Classes

                                                          Unit testing:
                                                          QueueTester, LogTester,
                                                          DatabaseTester and
                                                          StreamTester classes are
                                                          to be used to unit test each
                                                          entity and control class.

                                                          Integration testing:
                                                          SystemTester class will be
                                                          used to test the entire
                                                          system.




Class Organization & Packages
The classes are organized into five primary packages: GUI, Main, Rules, Utils and
Testing. The contents of each package are as follows:

GUI Package                    Main Package

   <<Boundary Class>>                 <<Control Class>>
     ConsoleWindow                        Streamer


   <<Boundary Class>>                 <<Control Class>>
    ViolationsWindow                      Analyzer




Utils Package

     <<Boundary Class>>             <<Entity Class>>              <<Control Class>>
       DatabaseHandler                NBBOQueue                        Lock


     <<Boundary Class>>             <<Entity Class>>
        LogHandler                    QueueItem




2006 - 2007                                                                              21
Computer Science Honors                               Renegade: Market Surveillance Replay


Testing Package

       <<Testing Class>>              <<Testing Class>>                         <<Testing Class>>
          LogTester                   DatabaseTester                             QueueTester

       <<Testing Class>>              <<Testing Class>>
         StreamTester                   SystemTester




Class Communication Structure



   View                                      Create
   Results                                   NBBOs
                                                                   Read
                                        NBBO Queue                 quotes
                  Open     Initiate
                           Streamer           Read
                  Window
                                              NBBOs                                     Query quotes
   Initiate
   processes                                              Read                          Query trades
                                                          trades                     Insert
                           Initiate                                                  Violations
                           Analyzer
                                              Violation
                                              Info
                                                               Store
                                                               Violation Info




2006 - 2007                                                                                            22
Computer Science Honors                            Renegade: Market Surveillance Replay


System State Changes




User Interface Design

The user interface needs to be simple and informative, notifying the user of the progress
and of any significant events that occur.

There will be two graphical user interfaces that allow the user to control and view the
operation of the system: (1) Console Window (2) Violations Window. The classes
representing these windows were described previously in the “boundary classes” section.

The Console Window will allow the user to control the system, which involves, starting
and stopping the processes, passing in input parameters that are required and quitting the
system. This window will also link the user to the violations window. The console
window design is presented below.




2006 - 2007                                                                             23
Computer Science Honors                                                Renegade: Market Surveillance Replay




                          Title: Renegade Equity Surveillance Replay


    Buttons

                  Start                Stop               Violations              Exit


              ------------------------------------ Progress bar -------------------------------------
              --
              Output console:
              <msg>
              <msg>
              <msg>




When a user clicks on start, the system will generate another window – Input window-
that will allow the user to enter the necessary input parameters (Start/End date, Base
exchange, SEC symbol). The user will be prompted to enter the two date/time values
formatted as mm-dd-yy HH:mm:ss:fff (24 hour format). The Base Exchange input
would be selection box where a user may select the desired exchange from a list of
possible exchanges. The possible values are:

                                Symbol                    Exchange
                                A              American Stock Exchange
                                N              NYSE
                                P              Pacific Stock Exchange
                                B              Boston Stock Exchange
                                C              Cincinnati Stock Exchange
                                M              Chicago Stock Exchange
                                T              Nasdaq Stock Exchange
                                X              Philadelphia Stock Exchange
                                W              Chicago Options Exchange

This input window will be designed as follows.




2006 - 2007                                                                                             24
Computer Science Honors                                      Renegade: Market Surveillance Replay


                Start                                End
                Date/Time                            Date/Time


                Base
                Exchange


                SEC
                Symbol                                                Cancel        OK



The violations window will display information about the violations that were found
during processing. It will provide a basic overview of the list of violations and statistical
information what resulted from the execution.


               Title: Renegade Equity                              Base Exchange:
                                                                   Symbol:
               Surveillance Replay                                 Start:
                                                                   End:
                                                                   # Trades:
               Trade Through Violations Listing                    # quotes:
                                                                   # Violations:



              TRD_id     TRD_price   TRD_size   TRD_time     Quote_time   Quote_price   Val_lost




                                                  <footer>




Test Plan
The testing is broken down into 8 separate sets of test cases. Five sets will be used to unit
test the database handler, NBBO queue, log handler streamer and analyzer. Another
test case set will be used to test the GUI functionality. And the final test case set will be
used for integration testing, to ensure the desired operation of the entire system is
achieved.




2006 - 2007                                                                                        25
Computer Science Honors                             Renegade: Market Surveillance Replay



Implementation

Class Implementations

Streamer Class


User Interfaces

Console Window

Below is a screenshot of the implemented console window. This window provides central
control to the Renegade application. This screenshot illustrates the initial, non-operational
state.




Once the user clicks on the “Start Processes” button, a window will be displayed
allowing the user to enter the run parameters. A screenshot of this window is below.




2006 - 2007                                                                               26
Computer Science Honors                           Renegade: Market Surveillance Replay




The following screenshot also explains the console window, but in an operational state.




2006 - 2007                                                                               27
Computer Science Honors                           Renegade: Market Surveillance Replay


Below, is the window that displays the results once the Renegade system is executed.




2006 - 2007                                                                            28
Computer Science Honors                              Renegade: Market Surveillance Replay



Maintenance
Improvements to the System

o Addition of multiple simultaneous data streams and breaking down the data analysis
  into separate “rule modules/classes” each responsible for processing the data streams
  for a specific violation. This enables simultaneous analysis of data for multiple
  violations. A few of these violations include:
  Wash sales
  Locked market
  Crossed market
  Front running
  Post close
  Mark the close

                                         NBBO
       <<Thread>>
        Streamer                        All Prices

                                       BSE Quotes


                                                            <<Thread>>
                                                             Analyzer



                                             <<Module>>       <<Module>>       <<Module>>
                                                Trade          Wash Sales         Front
                                               Through                           Running



   The streamer and analyzer were designed to allow for the inclusion of additional data
   streams and detection modules.

o Advanced configuration capability to simplify configuration of system parameters.
    Many system parameters such as maximum NBBO capacity, thread sleep times and
violation time window length should be modifyable. An interface to simplify this
configuration would make the system more adaptable to the operating hardware.
o Refine program code to optimize usage of resources (memory, CPU). Speed of
    execution could be increased through 64-bit compilation.
o Refine extraction of quotes and trades from database to optimize memory usage -
        The current system reads all data from the database at once and stores it in
        memory until each quote/trade is processed. This could be refined to retrieve one
        quote/trade at a time, process it and then retrieve the next. This would reduce the



2006 - 2007                                                                               29
Computer Science Honors                         Renegade: Market Surveillance Replay


      amount of data stored in memory at a given time. Retrieving a single record at a
      time from the database is also known to be faster than retrieving a set.
o Integrated and improved GUI interface – to display and monitor queue, processes and
  provide real-time feedback of the analysis operations to the user.
      The results window can be integrated directly into the application without using
      an external web interface. This would improve security as well. Addition of
      shortcut keys would be useful.




2006 - 2007                                                                         30
Computer Science Honors                           Renegade: Market Surveillance Replay



Glossary

OTC: Over-the-counter market that allows trading**

Consolidated trades and quotes: Trades and quotes from all market centers trading the
stock.

Market center:

Trade data:

Quote data:

Exchange:

Capital Market:

RegNMS: Regulation of the National Market System, a document created by the SEC
describing regulations that are to apply to electronic trading.

Automated Quotation: A quotation that has no human intervention after the time an
order is received to determine the action taken with respect to the quotation.15

ATS:

ECN:

Limit order:

NMS Stock: A security, other than an option, for which transaction reports are collected,
processed and made available pursuant to an effective national market system plan.16




15
     Page 79, REG NMS document 34-50870
16
     Page 78, REG NMS document 34-50870



2006 - 2007                                                                            31
Computer Science Honors                     Renegade: Market Surveillance Replay



References

   http://www.sec.gov/divisions/marketreg/mrecn.shtml
   http://www.sec.gov/news/studies/ecnafter.htm
   http://www.itsplan.com/
   http://www.sec.gov/spotlight/regnms.htm
   http://sec.gov/rules/final/34-42212.htm
   http://www.ntu.org/main/press_commentaries.php?PressID=642&org_name=NTU
   http://www.investopedia.com




2006 - 2007                                                                   32

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:6
posted:8/21/2011
language:English
pages:32