Author Topic: Pricefeeds - how does the client calculate the median?  (Read 1773 times)

0 Members and 1 Guest are viewing this topic.

Offline bytemaster

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).
For the latest updates checkout my blog: http://bytemaster.bitshares.org
Anything said on these forums does not constitute an intent to create a legal obligation or contract between myself and anyone else.   These are merely my opinions and I reserve the right to change them at any time.

Offline mindphlux

  • Sr. Member
  • ****
  • Posts: 232
    • View Profile
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
« Last Edit: September 02, 2014, 06:16:45 pm by mindphlux »
Please consider voting for my witness mindphlux.witness and my committee user mindphlux. I will not vote for changes that affect witness pay.

Offline bytemaster

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]


For the latest updates checkout my blog: http://bytemaster.bitshares.org
Anything said on these forums does not constitute an intent to create a legal obligation or contract between myself and anyone else.   These are merely my opinions and I reserve the right to change them at any time.


Offline santaclause102

  • Hero Member
  • *****
  • Posts: 2486
    • View Profile
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)?
« Last Edit: September 14, 2014, 07:20:10 am by delulo »

Offline mindphlux

  • Sr. Member
  • ****
  • Posts: 232
    • View Profile
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
« Last Edit: September 01, 2014, 04:52:19 pm by mindphlux »
Please consider voting for my witness mindphlux.witness and my committee user mindphlux. I will not vote for changes that affect witness pay.