> For the complete documentation index, see [llms.txt](https://docs.pearprotocol.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pearprotocol.io/api-integration/important-terms/weighted-price-ratio.md).

# Weighted Price Ratio

While a simple price ratio works for **one long vs. one short**, traders often use **baskets** of assets: multiple longs and multiple shorts with different weightings. The **Weighted Ratio** generalizes the idea of the price ratio into a combined performance measure for the entire strategy.

$$
\text{Weighted Ratio} = \prod\_{i=1}^{n} \text{Price}\_i^{w\_i}
$$

#### **How It Works**

Each asset price is raised to the power of its allocation weight:

* **Long positions have positive weights**
* **Short positions have negative weights**

So, for the example portfolio:

* 50% Long $HYPE
* 25% Short $ASTER
* 25% Short $XPL (Plasma)

The weighted ratio becomes:

$$
\text{Weighted Ratio} = \text{HYPEUSD}^{0.5} \cdot \text{ASTERUSD}^{-0.25} \cdot \text{XPLUSD}^{-0.25}
$$

This is effectively the geometric return of the portfolio — a mathematically clean way to encode long/short performance.

#### **What It Tells You**

The **absolute value** of the ratio at any moment isn’t very important. What *is* important is **how it changes over time**:

* If the weighted ratio **trends upward**, your basket is performing well:
  * longs are winning
  * shorts are losing
  * or both
* If it **trends downward**, the basket is underperforming.

This makes the weighted ratio a direct measure of **strategy PnL momentum**.

#### Reading the Chart

The absolute number doesn't matter much. What matters is direction:

* **Rising** — longs are outperforming shorts. The trade is working.
* **Falling** — shorts are outperforming longs. The trade is losing.

Using the example above: if the ratio is trending up, HYPE is outperforming the ASTER+XPL basket. Flipping the structure (long ASTER+XPL / short HYPE) would show a downtrend — same information, opposite perspective.

You don't need to track each asset individually. The ratio chart shows the combined P\&L path of the entire strategy in one line.

#### Where the Weights Come From

For open positions, the weights are derived from the weights set when the position was opened. Otherwise, the weights come from what the user specifies.

### Code Example

```typescript
type Token = { symbol: string; weight: number };
type TokenPriceMap = Map<string, { markPrice: number }>;

function computeWeightedRatio(
  longTokens: Token[],
  shortTokens: Token[],
  prices: TokenPriceMap,
): number {
  let ratio = 1;
  for (const t of longTokens) {
    const price = prices.get(t.symbol)?.markPrice ?? 0;
    ratio *= Math.pow(price, t.weight);
  }
  for (const t of shortTokens) {
    const price = prices.get(t.symbol)?.markPrice ?? 0;
    ratio *= Math.pow(price, -t.weight);
  }
  return ratio;
}
```
