-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add default Yield Multiplier to PoolRow and OpenShortForm (#1511)
* Adds yield multiplier to pool row * replace variably apy with multiplier * check for loading * Skeleton loading * adds commend for multiplier calc * switch to parseFixed * Move calc into separate function
- Loading branch information
1 parent
10f9450
commit 5d70cd7
Showing
4 changed files
with
58 additions
and
12 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
apps/hyperdrive-trading/src/hyperdrive/calculateMarketYieldMultiplier.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { parseFixed } from "@delvtech/fixed-point-wasm"; | ||
/** | ||
* Calculates the yield multiplier for a Hyperdrive market based on the long price. | ||
* | ||
* The yield multiplier represents how much the underlying yield is amplified for short positions. | ||
* It is inversely proportional to the long price, increasing as the long price approaches 1. | ||
* | ||
* Yield Multiplier calculation: | ||
* Yield Multiplier = 1 / (1 - longPrice) | ||
* | ||
* Examples: | ||
* - If longPrice = 0.9: | ||
* Yield Multiplier = 1 / (1 - 0.9) = 1 / 0.1 = 10x | ||
* The short position amplifies the underlying yield by 10 times. | ||
* | ||
* - If longPrice = 0.96: | ||
* Yield Multiplier = 1 / (1 - 0.96) = 1 / 0.04 = 25x | ||
* The short position amplifies the underlying yield by 25 times. | ||
* | ||
* @param longPrice The current price of a long position, represented as a bigint. | ||
* @returns The calculated yield multiplier as a string, formatted to 2 decimal places. | ||
*/ | ||
|
||
export function calculateMarketYieldMultiplier(longPrice: bigint): string { | ||
return parseFixed(1) | ||
.div(parseFixed(1).sub(longPrice)) | ||
.format({ decimals: 2, rounding: "trunc" }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters