Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Towards a Formal Modelling of Orders in Stock Trading Systems using Workflow Nets

Towards a Formal Modelling of Orders in Stock Trading Systems using Workflow Nets

MACSPro'2019 - Modeling and Analysis of Complex Systems and Processes, Vienna
21 - 23 March 2019

Julio Cesar Carrasquel, Irina Lomazova

Conference website http://macspro.club/

Website https://exactpro.com/
Linkedin https://www.linkedin.com/company/exactpro-systems-llc
Instagram https://www.instagram.com/exactpro/
Twitter https://twitter.com/exactpro
Facebook https://www.facebook.com/exactpro/
Youtube Channel https://www.youtube.com/c/exactprosystems

Exactpro
PRO

March 22, 2019
Tweet

More Decks by Exactpro

Other Decks in Research

Transcript

  1. Towards a Formal Modelling of Order-driven
    Trading Systems using Petri Nets:
    A Multi-Agent Approach
    Julio C. Carrasquel Irina A. Lomazova
    National Research University Higher School of Economics
    Laboratory of Process-Aware Information Systems (PAIS)

    View Slide

  2. Outline
    ● Order-driven Trading Systems
    ● Multi-Agent System (MAS) model

    Agents and Petri Nets

    Nested Petri Net model

    Coloured Petri Net model
    ● Research Directions

    View Slide

  3. Order
    ● An order o is a client instruction to trade a financial instrument.
    ● Some attributes:
    ○ side s ∈ { buy, sell }
    ○ price per stock p
    ○ quantity of stocks q
    ● …we may consider other attributes such as:
    ○ time of arrival
    ○ validity
    ○ display restrictions, quantity restrictions, ...

    View Slide

  4. Order-driven Trading Systems
    ● Order routing systems
    ● Order books
    ● Rule-based matching systems
    ○ Order precedence rules
    ○ Order matching
    ● Order presentation systems and market data systems

    View Slide

  5. Order-driven Trading Systems
    ● Order routing systems
    ● Order books
    ● Rule-based matching systems
    ○ Order precedence rules
    ○ Order matching
    ● Order presentation systems and market data systems

    View Slide

  6. Order Precedence Rules - Arrival of orders
    time trader size price
    10:01 Bea 3 20
    10:08 Ben 2 20
    10:15 Bif 4 market
    10:18 Bob 2 20.1
    10:29 Bud 7 19.8
    time trader size price
    10:05 Sam 2 20.1
    10:08 Sol 1 19.8
    10:10 Stu 5 20.1
    10:20 Bob 2 20.1
    Buy side arrivals Sell side arrivals

    View Slide

  7. Order Precedence Rules - Ranking (Price-time policy)
    buyer size price price seller
    Bif 4 market
    20.1 5 Stu
    Bob 2 20.1 2 Sam
    Bea 3 20.0
    Ben 2 20.0
    20.0 6 Sue
    Bud 7 19.8 1 Sol
    Order book

    View Slide

  8. Matching Procedure
    buyer size price price seller
    Bif 4 → 3 market
    20.1 5 Stu
    Bob 2 20.1 2 Sam
    Bea 3 20.0
    Ben 2 20.0
    20.0 6 Sue
    Bud 7 19.8 1 → 0 Sol
    Order book

    View Slide

  9. Matching Procedure
    buyer size price price seller
    Bif 3 → 0 market
    20.1 5 Stu
    Bob 2 20.1 2 Sam
    Bea 3 20.0
    Ben 2 20.0
    20.0 6 → 3 Sue
    Bud 7 19.8
    Order book

    View Slide

  10. Matching Procedure
    buyer size price price seller
    20.1 5 Stu
    Bob 2 → 0 20.1 2 Sam
    Bea 3 20.0
    Ben 2 20.0
    20.0 3 → 1 Sue
    Bud 7 19.8
    Order book

    View Slide

  11. Matching Procedure
    buyer size price price seller
    20.1 5 Stu
    20.1 2 Sam
    Bea 3 → 2 20.0
    Ben 2 20.0
    20.0 1 → 0 Sue
    Bud 7 19.8
    Order book

    View Slide

  12. Matching Procedure
    buyer size price price seller
    20.1 5 Stu
    20.1 2 Sam
    Bea 2 20.0
    Ben 2 20.0
    Bud 7 19.8
    Order book final state

    View Slide

  13. Outline
    ● Order-driven Trading Systems
    ● Multi-Agent System (MAS) model

    Agents and Petri Nets

    Nested Petri Net model

    Coloured Petri Net model
    ● Research Directions

    View Slide

  14. Multi-Agent System (MAS) model
    ● Processes of the trading system → types of agents

    (x) Request handler → Arrival of orders

    (y) Order book handler → Ranking and matching

    (z) Trade handler
    ● An agent

    Created upon request

    Executes internal activities (either by initiative or reactivity)

    Sends and receives messages from other agents (social behavior)

    Terminated upon completion of its tasks

    View Slide

  15. Agents and Petri Nets
    verify
    order
    receive
    order
    a
    1
    a
    2
    a
    3
    a
    4
    reject
    order
    place in
    book
    Agent x
    1
    o
    1
    = (Bif ,market ,4,buy)

    View Slide

  16. Agents and Petri Nets
    verify
    order
    receive
    order
    a
    1
    a
    2
    a
    3
    a
    4
    reject
    order
    place in
    book
    Agent x
    1
    o
    1
    = (Bif ,market ,4,buy)
    a
    4
    rank
    sell order
    receive
    buy order
    receive
    sell order
    rank
    buy order
    notify
    match
    replace
    cancel
    expire notify order
    filled
    notify order
    partially
    filled
    b
    1
    b
    2
    b
    3
    b
    4
    b
    5
    b
    6
    b
    7
    b
    8
    b
    9
    b
    10
    Agent y
    1

    View Slide

  17. Agents and Petri Nets
    rank
    sell order
    receive
    buy order
    receive
    sell order
    rank
    buy order
    notify
    match
    replace
    cancel
    expire notify order
    filled
    notify order
    partially
    filled
    b
    1
    b
    2
    b
    3
    b
    4
    b
    5
    b
    6
    b
    7
    b
    8
    b
    9
    b
    10
    Agent y
    1
    handling a buy order o
    1
    rank
    sell order
    receive
    buy order
    receive
    sell order
    rank
    buy order
    notify
    match
    replace
    cancel
    expire
    notify order
    filled
    notify order
    partially
    filled
    b
    1
    b
    2
    b
    3
    b
    4
    b
    5
    b
    6
    b
    7
    b
    8
    b
    9
    b
    10
    c
    1
    both
    orders
    filled
    c
    2
    c
    3
    order
    filled
    and
    other
    one
    partially
    filled
    c
    5
    notify
    trade
    c
    4
    Agent z
    1
    handling(o
    1,
    o
    2
    ) Agent y
    2
    handling a sell order o
    2

    View Slide

  18. Nested Petri Net model
    ● Tokens can be Petri Net themselves
    ● System net - an environment describing
    ○ Creation and termination of system processes (agents)
    ○ Communication interfaces (via vertical synchronization steps)
    ○ Shared execution constraints between multiple agents, I.e, matching process.
    ● Focus on the control-flow perspective and communication interfaces

    View Slide

  19. Nested Petri Net model – system net (fragment)
    Invoke
    request
    handler
    reject
    order
    t
    2
    o
    o
    request
    handlers
    (x ,o) (y ,o)
    order book
    handlers
    place
    in book
    t
    1
    receive
    order
    a
    3
    request handlers
    serving orders
    order book handlers
    serving orders
    a
    4
    (x ,o)
    received
    orders
    (x ,o)
    verify
    order
    receive
    order
    a
    1
    a
    2
    a
    3
    a
    4
    reject
    order
    place in
    book
    Pair (x
    1,
    o
    1
    )
    indicating that agent x
    1
    handles o
    1
    agent net x
    1
    vertical synchronization labels
    System net (fragment)

    View Slide

  20. Nested Petri Net model – system net (fragment)
    cancel
    (y ,o)
    expire
    order book
    handlers
    replace
    (y ,o)
    (y ,o)
    (y ,o)
    place
    in book
    (y ,o)
    notify
    match
    (y ,o)
    t
    7
    2
    2
    (y ,o)
    notify order filled
    notify
    order partially
    filled
    (y ,o) (y ,o)
    order book
    handlers
    serving orders
    enable next
    matching
    a
    4
    b
    5
    b
    6
    b
    7
    b
    8
    b
    9
    b
    10
    t
    3
    orders
    matched
    pending
    Pair (y
    1,
    o
    1
    )
    Pair (y
    2,
    o
    2
    )

    View Slide

  21. Nested Petri Net model – system net (fragment)
    (z,2⋅o)
    invoke
    matching
    handler
    trade
    handlers
    2⋅(y ,o) c
    4
    notify
    trade
    (z,2⋅o)
    2⋅o
    send
    trade
    to client
    2⋅o
    terminate
    matching
    handler
    z
    c
    3
    c
    2
    both orders fulfilled
    order fulfilled
    and other one
    partially
    fulfilled
    2⋅o
    o
    o
    o
    o
    o
    notify order filled
    notify
    order partially
    filled
    (y ,o)
    b
    9
    b
    10
    c
    5
    t
    4
    t
    5
    trade
    handlers
    running
    orders
    matched
    pending
    2⋅o

    View Slide

  22. Nested Petri Net model – system net (complete)
    Invoke
    request
    handler cancel
    reject
    order
    t
    2
    o
    o
    (x ,o) (y ,o)
    expire
    order book
    handlers
    replace
    o
    (y ,o)
    (y ,o)
    (y ,o)
    place
    in book
    (y ,o)
    notify
    match
    (y ,o)
    t
    7
    (z,2⋅o)
    invoke
    matching
    handler
    trade
    handlers
    2⋅(y ,o) c
    4
    notify
    trade
    (z,2⋅o)
    2⋅o
    send
    trade
    to client
    2⋅o
    terminate
    matching
    handler
    z
    c
    3
    c
    2
    both orders fulfilled
    order fulfilled
    and other one
    partially
    fulfilled
    2⋅o
    o
    o
    o
    o
    o
    2
    2
    t
    1
    (y ,o)
    notify order fulfilled
    notify
    order partially
    fulfilled
    (y ,o) (y ,o)
    receive
    order
    request handlers
    serving orders
    order book handlers
    serving orders
    enable next
    matching
    a
    4
    (x ,o)
    b
    5
    b
    6
    b
    7
    b
    8
    b
    9
    b
    10
    c
    5
    t
    3
    t
    4
    t
    5
    trade
    handlers
    running
    orders
    matched
    pending
    received
    orders
    (x ,o)
    2⋅o
    request
    handlers
    a
    3

    View Slide

  23. Coloured Petri Net (CPN) model
    ● Tokens have data types (colors) associated.
    colset SIDE = with buy | sell
    colset ORDER = product STRING * INT * INT * SIDE
    colset ORDER_PAIR = product ORDER * ORDER
    colset ORDER_BOOK = list ORDER
    ● An order book is modeled as two tokens (of type ORDER_BOOK)

    Representing the buy side and the sell side.

    View Slide

  24. Coloured Petri Net (CPN) model – modelling MAS
    ● CPN may not be a convenient representation of Multi-Agent Systems
    ● Conceived approach → hierarchical CPN with sub-pages

    System net (environment) → Model top page

    Each sub-page → structure of a kind of agent (process)

    Current point of execution of an agent → a variable in the sub-page

    We loss the notion of mobility

    View Slide

  25. Coloured Petri Net (CPN) model – system net
    Sub-page describing
    the behavior of an
    agent encapsulated
    on a substitution
    transition

    View Slide

  26. Coloured Petri Net (CPN) model – order book handler example
    agent y
    1
    handling o
    BEN
    agent y
    3
    handling o
    BIF
    agent y
    4
    handling o
    SAM

    View Slide

  27. Coloured Petri Net (CPN) model – order book handler example
    rank
    sell order
    receive
    buy order
    receive
    sell order
    rank
    buy order
    notify
    match
    replace
    cancel
    expire
    notify order
    filled
    notify order
    partially
    filled
    b
    1
    b
    2
    b
    3
    b
    4
    b
    5
    b
    6
    b
    7
    b
    8
    b
    9
    b
    10
    rank
    sell order
    receive
    buy order
    receive
    sell order
    rank
    buy order
    notify
    match
    replace
    cancel
    expire
    notify order
    filled
    notify order
    partially
    filled
    b
    1
    b
    2
    b
    3
    b
    4
    b
    5
    b
    6
    b
    7
    b
    8
    b
    9
    b
    10
    rank
    sell order
    receive
    buy order
    receive
    sell order
    rank
    buy order
    notify
    match
    replace
    cancel
    expire
    notify order
    filled
    notify order
    partially
    filled
    b
    1
    b
    2
    b
    3
    b
    4
    b
    5
    b
    6
    b
    7
    b
    8
    b
    9
    b
    10
    agent y
    1
    handling o
    BEN
    agent y
    3
    handling o
    BIF
    agent y
    4
    handling o
    SAM

    View Slide

  28. Coloured Petri Net (CPN) model – Order precedence rules
    fun buy_rank (i, p, q, s) [ ] = [(i, p, q, s)] // o = (i, p, q, s)
    |
    buy_rank (i, p, q, s) ( (i2, p2, q2, s2)::list ) =
    if p > p2 then // ranking according to price
    (i, p, q, s) :: (i, p2, q2, s2) :: list
    else
    (i2, p2, q2, s2) :: (buy_rank (i, p, q, s) list)
    ● Use of a CPN ML function on the input arc of the place for orders to manipulate
    conveniently the list when inserting a new order.

    View Slide

  29. Coloured Petri Net (CPN) model – Guards
    ● Use of a boolean function as an additional constraint for a transition to be enabled.
    ● Thus, it imposes an additional condition for an activity execution based on the data.
    Guard function for enabling
    matching

    View Slide

  30. Outline
    ● Order-driven Trading Systems
    ● Multi-Agent System (MAS) model

    Agents and Petri Nets

    Nested Petri Net model

    Coloured Petri Net model
    ● Research Directions

    View Slide

  31. Research Directions
    MODELLING stock trading
    software
    systems
    simulation
    event
    logs
    record events.
    i.e. messages,
    orders,
    transactions,
    etc.
    CONFORMANCE
    CHECKING
    verification of
    behavioral properties
    PERFORMANCE
    ANALYSIS
    a
    b
    c d
    system net (agent society)
    stock
    exchange
    “world”
    brokers, orders,
    trades,...
    supports/controls
    a c d
    a
    b
    c d
    a
    b
    c d
    Petri-net-based models
    Multi-agent system (MAS) approach
    processes
    (agents)

    View Slide

  32. Research Directions – A possible simulation environment

    View Slide