barteloma
barteloma

Reputation: 6875

How is the asset price calculated from the order books in the stock exchange?

I want to create a stock exchange simulation using C# programming language. But I couldn't decide on how to specify the price of an asset.

For example, the following table is an order book for an asset:

Buy                                 Sell             
-----------------------------       ----------------------------
ID   Time       Size    Price       ID  Price   Size    Time    
4    8:00:04    250     100         1   101     750     8:00:01 
6    8:00:10    500     100         5   101     500     8:00:05 
2    8:00:01    750     97          8   101     750     8:00:30 
7    8:00:10    150     96          3   102     250     8:00:02 

The simplest order book matching algorithm is a price-time-priority algorithm. That means that the matching priority firstly is price and then time. The participants are rewarded for offering the best price and coming early.

Every asset has a current price in stock exchanges. But how can I calculate the price of this asset? Is there any algorithm for this?

Upvotes: 2

Views: 1692

Answers (1)

Capn Sparrow
Capn Sparrow

Reputation: 2070

An exchange will usually show the 'top of the book', showing best bid (the highest number someone is willing to buy at) and ask (the lowest price someone is willing to sell at).

Where you see an exchange offering a single price, it is derived in one of two ways:

  • if there have been recent (valid) trades, then it is the last traded price
  • otherwise, it is the reference price

What is a Reference Price?

Most equity and derivatives exchanges maintain a reference price for each book. This is used to prevent acceptance of orders which would be too far from the reference price - aka 'extreme trading range'.

Usually the reference price is set to the last traded price during the day, but how is it set in the first place before any trading happens?

The reference price is usually determined after each trading reset (e.g. start of day, start of week or start of a new book) as one of the following in order of precedence:

  1. price discovered during an initial auction period (usually only in equity markets)
  2. if no auction, then last traded (or settled, depending on the market) price
  3. use a price from another market operator running the same book
  4. or the market operator can use it's own 'reasonable' method to determine a reference price, e.g. for an initial listing of a new security

How to apply this?

So if you want to set a new 'current price' in BTC but you don't yet have any trades on your book, then because BTC is already widely traded you can:

  1. use the last price traded on binance for the pair you're running
  2. take a mean or median of last prices from multiple BTC books run by others
  3. manually set some other price you think will attract both buyers and sellers

Upvotes: 4

Related Questions