pegnet / pegnetd

The pegnet daemon to track txs, conversions, etc
Other
13 stars 14 forks source link

Potential problem with price average calculation algorithm #116

Closed menkaur closed 4 years ago

menkaur commented 4 years ago

Hey. I'd like to make sure that you guys are aware of potential problem with calculating average prices the easy way.

Basically, what can happen is that miners may submit prices which differ from the average price by orders of magnitude. Let's say, we have 5 miners submitting rate of BTC/USD: [8800,8900,9000,9100,90000000000000000000000000000000]

If you calculate average the normal way, it will be way off. This problem is not offset by increasing number of miners, since the orders of magnitude price deviation 9e30 will offset calculations even if thousands of miners report correct price.

Does PegNet use average calculation algorithm which is sensitive to deviations like that?

Emyrk commented 4 years ago

@menkaur The process for determining the final price uses PoW for the top 50 records.

Then we do a process where we take the average of the 50 records, toss the record farthest from the average. With the remaining 49, we calculate the average, toss the farthest.

This means our algorithm is very close to using a median, vs an average. And therefore resistant to outliers.

Emyrk commented 4 years ago

Here is the summary:

1. Take the top 50 entries with the best proof of work
2. Calculate the average of each of the 30 assets
3. Calculate the grade for each OPR, where the grade is the sum of the quadratic distances
to the average of each asset. If an asset is within `band`% of the average, that asset's
grade is 0.  The band is set to 1%
4. Throw out the OPR with the highest grade
5. Repeat 3-4 until there are only 25 OPRs left
6. Repeat 3 but this time don't apply the band and don't throw out OPRs, just reorder them
until you are left with one
menkaur commented 4 years ago

Ah. This is much better than I imagined!