BitShares Forum

Main => Technical Support => Topic started by: mindphlux on September 01, 2014, 04:43:54 pm

Title: Pricefeeds - how does the client calculate the median?
Post by: mindphlux on September 01, 2014, 04:43:54 pm
Hello,

I am currently trying to understand the technical details of the bitshares implementation.. I understand that shorts that are over the median of the pricefeed are not being executed, however, I'm not sure how this median value is calculated exactly. Does it just take all available price feeds, no matter how old, or is there some more advanced filtering?

I found this:
https://github.com/dacsunlimited/bitsharesx/commit/5a1a01f5931be51166f37e688cfb7eefd0ae6c4b

However, I cannot locate the function get_median_delegate_price() anywhere.

If you can point me to the right file with the function and/or answer my question, I'd be greatful.

Thank you

Best regards
mindphlux
Title: Re: Pricefeeds - how does the client calculate the median?
Post by: santaclause102 on September 01, 2014, 04:52:01 pm
I'd add:
- Isn't the accuracy the price (feed) a problem for calculating the median? Or is the median just calculated from the first x digits?
- In case of big price swings is it enough that delegates update the price feeds every 24 hours (24 hours was requirement I read)?
Title: Re: Pricefeeds - how does the client calculate the median?
Post by: santaclause102 on September 02, 2014, 05:04:59 pm
Anyone?
Title: Re: Pricefeeds - how does the client calculate the median?
Post by: bytemaster on September 02, 2014, 05:16:39 pm
Code: [Select]
vector<price> feed_list

for all feeds
  if published by active delegate in last 24 hours
      feed_list.push( feed.price )

if feed_list.size >= 51
  std::nth_element( feed_list.begin(), feed_list.begin() + feed_list.size(), feed_list.end() )
  return feed_list[feed_list.size()/2]


Title: Re: Pricefeeds - how does the client calculate the median?
Post by: mindphlux on September 02, 2014, 06:15:03 pm
Thank you.

I don't get quite get the std::nth_element call though, seems to be some sort of sorting,

Is the median calculated outside of this snippet? Why are you returning half of the size of the vector?

Thanks

--mindphlux
Title: Re: Pricefeeds - how does the client calculate the median?
Post by: bytemaster on September 02, 2014, 06:38:36 pm
Thank you.

I don't get quite get the std::nth_element call though, seems to be some sort of sorting,

Is the median calculated outside of this snippet? Why are you returning half of the size of the vector?

Thanks

--mindphlux

nth_element does a partial sort because I only care that the first 50% of the items are in sorted order. 
I return the item in the middle (median).