Skip to content

Commit c7bc2c3

Browse files
Add price aggregation documentation for Pyth Pro (Lazer)
Co-Authored-By: Ali <[email protected]>
1 parent eb8a18b commit c7bc2c3

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

pages/price-feeds/pro/_meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,6 @@
3535
"type": "separator"
3636
},
3737

38-
"how-lazer-works": "How Pyth Pro Works"
38+
"how-lazer-works": "How Pyth Pro Works",
39+
"price-aggregation": "Price Aggregation"
3940
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Price Aggregation
2+
3+
Pyth Pro (formerly Lazer) aggregates price data from multiple publishers to produce reliable aggregate prices with confidence intervals and best bid/ask spreads. This page explains how the aggregation algorithm works.
4+
5+
## Publisher Data Submission
6+
7+
Publishers send three different optional prices to Pyth Pro:
8+
9+
- **Best Bid**: The highest price at which the publisher is willing to buy the asset
10+
- **Price**: The publisher's view of the fair market price
11+
- **Best Ask**: The lowest price at which the publisher is willing to sell the asset
12+
13+
Publishers may submit any combination of these three values. The aggregation algorithm is designed to handle cases where some publishers only provide certain price types.
14+
15+
## Aggregation Algorithm
16+
17+
Pyth Pro calculates the following properties from the submitted publisher data:
18+
19+
### Aggregate Price
20+
21+
The **aggregate price** is computed as the **median of all the prices combined** from all publishers. This approach provides robustness against outliers while still reflecting the consensus view of the market.
22+
23+
The median calculation considers only the "price" values submitted by publishers. By using the median rather than the mean, the algorithm ensures that a single publisher submitting an extreme price cannot significantly skew the aggregate price.
24+
25+
### Aggregate Best Bid Price
26+
27+
The **aggregate best bid price** is the **maximum best bid price that is lower than the aggregate price**. This represents the highest price at which market participants are willing to buy, while ensuring it remains below the fair market price.
28+
29+
This calculation:
30+
1. Filters all submitted best bid prices to only include those below the aggregate price
31+
2. Selects the maximum value from this filtered set
32+
33+
If no best bid prices are below the aggregate price, this value may be undefined.
34+
35+
### Aggregate Best Ask Price
36+
37+
The **aggregate best ask price** is the **minimum best ask price that is higher than the aggregate price**. This represents the lowest price at which market participants are willing to sell, while ensuring it remains above the fair market price.
38+
39+
This calculation:
40+
1. Filters all submitted best ask prices to only include those above the aggregate price
41+
2. Selects the minimum value from this filtered set
42+
43+
If no best ask prices are above the aggregate price, this value may be undefined.
44+
45+
### Confidence Interval
46+
47+
The **confidence interval** represents the uncertainty in the aggregate price and is calculated as the **maximum distance between the 25th and 75th percentile of all the prices combined to the median**.
48+
49+
Specifically:
50+
1. Calculate the 25th percentile of all submitted prices
51+
2. Calculate the 75th percentile of all submitted prices
52+
3. Compute the distance from the median (aggregate price) to the 25th percentile
53+
4. Compute the distance from the median (aggregate price) to the 75th percentile
54+
5. Take the maximum of these two distances as the confidence interval
55+
56+
This approach ensures that the confidence interval reflects both the dispersion of publisher prices and any asymmetry in their distribution. When publishers agree closely, the confidence interval will be small. When there is significant disagreement or variation between publishers, the confidence interval widens to reflect this uncertainty.
57+
58+
## Design Properties
59+
60+
The Pyth Pro aggregation algorithm achieves several important properties:
61+
62+
**Robustness to Outliers**: By using the median for the aggregate price, the algorithm is resistant to manipulation by individual publishers submitting extreme prices. The aggregate price will always lie between the 25th and 75th percentiles of publisher prices.
63+
64+
**Reflects Market Consensus**: The median-based approach ensures that the aggregate price represents the consensus view of the majority of publishers, rather than being skewed by outliers.
65+
66+
**Appropriate Bid-Ask Spread**: By selecting the best bid below the aggregate price and the best ask above it, the algorithm ensures a realistic spread that reflects actual market liquidity while maintaining consistency with the fair price.
67+
68+
**Uncertainty Quantification**: The confidence interval based on the interquartile range provides a robust measure of price uncertainty that reflects the level of agreement between publishers. This helps consumers understand the reliability of the aggregate price.
69+
70+
## Example Scenario
71+
72+
Consider a scenario with five publishers submitting the following data for BTC/USD:
73+
74+
- Publisher 1: Price = $50,000, Best Bid = $49,950, Best Ask = $50,050
75+
- Publisher 2: Price = $50,010, Best Bid = $49,980, Best Ask = $50,040
76+
- Publisher 3: Price = $49,995, Best Bid = $49,960, Best Ask = $50,030
77+
- Publisher 4: Price = $50,005, Best Bid = $49,990, Best Ask = $50,060
78+
- Publisher 5: Price = $50,020, Best Bid = $50,000, Best Ask = $50,070
79+
80+
The aggregation algorithm would compute:
81+
82+
1. **Aggregate Price**: Median of [$50,000, $50,010, $49,995, $50,005, $50,020] = $50,005
83+
2. **Aggregate Best Bid**: Maximum of bids below $50,005 = max([$49,950, $49,980, $49,960, $49,990, $50,000]) = $50,000
84+
3. **Aggregate Best Ask**: Minimum of asks above $50,005 = min([$50,050, $50,040, $50,030, $50,060, $50,070]) = $50,030
85+
4. **Confidence Interval**:
86+
- 25th percentile = $49,995
87+
- 75th percentile = $50,010
88+
- Distance to 25th: $50,005 - $49,995 = $10
89+
- Distance to 75th: $50,010 - $50,005 = $5
90+
- Confidence = max($10, $5) = $10
91+
92+
The final aggregate result would be: Price = $50,005 ± $10, with Best Bid = $50,000 and Best Ask = $50,030.

0 commit comments

Comments
 (0)