Author [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [EN] [ZH] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] Topic: Pricefeeds - how does the client calculate the median?  (Read 308 times)

0 Members and 1 Guest are viewing this topic.

Offline mindphlux

  • Sr. Member
  • ****
  • Posts: 233
    • View Profile
Pricefeeds - how does the client calculate the median?
« 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
« 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.

Offline santaclause102

  • Hero Member
  • *****
  • Posts: 2487
    • View Profile
Re: Pricefeeds - how does the client calculate the median?
« Reply #1 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)?
« Last Edit: September 14, 2014, 07:20:10 AM by delulo »

Offline santaclause102

  • Hero Member
  • *****
  • Posts: 2487
    • View Profile
Re: Pricefeeds - how does the client calculate the median?
« Reply #2 on: September 02, 2014, 05:04:59 PM »
Anyone?

Offline bytemaster

Re: Pricefeeds - how does the client calculate the median?
« Reply #3 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]


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: 233
    • View Profile
Re: Pricefeeds - how does the client calculate the median?
« Reply #4 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
« 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

Re: Pricefeeds - how does the client calculate the median?
« Reply #5 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).
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.

 

Google+