This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StronglyConnectedComponentsAlgo { | |
type GraphAdjList = Vector[Set[Int]] | |
type SubGraphAdjList = Map[Int, Set[Int]] | |
def compute(adjacencyList: GraphAdjList): Vector[SubGraphAdjList] = { | |
def strongConnect(v: Int, state: State): State = { | |
if (!state.visited(v).isDefined) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: Computing strongly connected components of a graph using Tarjan's algorithm | |
Scenario: Simple chain with no loops | |
Given the following edges of a graph with "3" vertices: | |
| Start | End | | |
| 1 | 2 | | |
| 2 | 3 | | |
When I compute strongly connected components of this graph using Tarjan's algorithm | |
Then there is a connected component of the graph: | |
| Node | Successors | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Scenario: Matching incoming Buy market order against Sell market order when another - limit - Sell order present | |
Given the following orders are submitted in this order: | |
| Broker | Side | Qty | Price | | |
| A | Sell | 100 | MO | | |
| B | Sell | 100 | 10.5 | | |
Then market order book looks like: | |
| Broker | Qty | Price | Price | Qty | Broker | | |
| | | | MO | 100 | A | | |
| | | | 10.5 | 100 | B | | |
When the following orders are submitted in this order: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Matching using a reference price | |
Scenario: Matching incoming Buy market order against Sell market order when no best limit price is available | |
Given the reference price is set to "10" | |
Given the following orders are submitted in this order: | |
| Broker | Side | Qty | Price | | |
| A | Sell | 100 | MO | | |
| B | Buy | 100 | MO | | |
Then the following trades are generated: | |
| Buying broker | Selling broker | Qty | Price | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: Maintaining reference price as trades occur | |
Scenario: Updating reference price as it is set at the opening and trades occur | |
Given the reference price is set to "10" | |
When the following orders are submitted in this order: | |
| Broker | Side | Qty | Price | | |
| A | Buy | 100 | 11 | | |
| B | Sell | 100 | 11 | | |
Then the following trades are generated: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderBookSteps extends ShouldMatchers { | |
val orderTypes = OrderType.all(buyBook, sellBook) | |
val buyBook: OrderBook = new OrderBook(Buy, orderTypes) | |
val sellBook: OrderBook = new OrderBook(Sell, orderTypes) | |
var actualRejected = Vector.empty[Order] | |
events { | |
case RejectedOrder(order) => actualRejected = actualRejected :+ order |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait OrderBookEvent | |
case class Trade(buyingBroker: String, sellingBroker: String, | |
price: Double, qty: Double) extends OrderBookEvent | |
case class RejectedOrder(order: Order) extends OrderBookEvent | |
case class CancelledOrder(order: Order) extends OrderBookEvent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait PriceLevel | |
case object MarketPrice extends PriceLevel | |
case class LimitPrice(limit: Double) extends PriceLevel | |
case object PegPrice extends PriceLevel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.euronextclone; | |
import com.euronextclone.ordertypes.Limit; | |
import com.google.common.base.Function; | |
import com.google.common.base.Optional; | |
import com.google.common.base.Predicate; | |
import com.google.common.collect.FluentIterable; | |
import com.google.common.collect.Lists; | |
import hu.akarnokd.reactive4java.reactive.DefaultObservable; | |
import hu.akarnokd.reactive4java.reactive.Observable; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OrderBook(side: Side, orderTypes: (Order => OrderType)) | |
extends mutable.Publisher[OrderBookEvent] { | |
private case class OrdersAtLimit(limit: Double, orders: FastList[Order]) | |
private case class OrderLocation(list: FastList.Entry[OrdersAtLimit], entry: FastList.Entry[Order]) | |
private val marketBook: FastList[Order] = FastList() | |
private val limitBook = FastList[OrdersAtLimit]() | |
private val priceOrdering = if (side == Sell) Ordering[Double] else Ordering[Double].reverse |