# Hyperdrive Examples
## Disclaimer
The language used in this code is for coding convenience only, and is not
intended to, and does not, have any particular legal or regulatory significance.
Also note that this was prepared in consultation with and for discussion purposes with legal counsel in connection with counsel's regulatory and legal analysis. The document is privileged and confidential.
## Notation
Ike - Initial LP
Larry - Long
Sally - Short
## Concepts
### Who sets the fixed rate?
Trading activity changes the ratio of shares and bonds. The spot rate for newly
minted PTs is defined as follows:
```
t = term_length / 365
p = ((bond_reserves + lp_total_supply) / (initial_share_price * share_reserves)) ^ -(t / time_stretch)
```
The spot rate can be defined in terms of the spot price as:
```
r = (1 - p) / (p * t)
```
## Example 1: Long is opened and closed at maturity
1. Ike will instantiate the market. Ike will provide $1000 to the pool, and he
will specify a target rate, say 4%. The term length is 1 year.
2. Larry purchases 1000 PTs for $960.
3. 1 year passes, and the share price went from 1 to 1.03.
Larry's PnL = $1000 - $960 = $40
Ike's PnL = $960 - $1000 + 0.03 * $960 = -$11.2
## Example 2: Short is opened and closed at maturity
Sally says, I want to short 1000 bonds. Ike says, okay, I'll commit to paying
you $960 for those bonds sometime in the next year. Sally's responsibilty is to
purchase 1000 bonds at a later date and sell those to Ike at the agreed upon
price.
1. Ike will instantiate the market. Ike will provide $1000 to the pool, and he
will specify a target rate, say 4%. The term length is 1 year.
2. Sally shorts 1000 PTs for an execution price of $960. Sally only puts up
$40 because that's the maximum amount of money that she can lose on this
trade.
3. 1 year passes, and the share price went from 1 to 1.05.
Sally's PnL = $960 - $1000 + (1.05 - 1) * ($960 + $40) = $10
Ike's PnL = $1000 - $960 = $40
## Example 3: Hyperdrive + External Lending Market - Fixed Rate Borrow
1. Sally takes out a $1000 loan from the lending market. She will be obligated to
pay a variable interest rate as long as the loan is open. When she takes
this loan out the variable interest rate is 1%.
2. Sally doesn't want variable rate exposure, so she shorts 1000 bonds on
Hyperdrive. Let's say that the execution price is $960, so she has to put up
$40. This effectively gives her a fixed rate borrow.
3. Immediately after she opens her loan and short, the variable rate jumps to
10%.
4. 1 year passes.
Sally's PnL = short pnl + loan pnl
= $960 - $1000 + 0.1 * $1000 - 0.1 * $1000
= -$40
* This is not a perfect hedge because we haven't assumed that the lending market knows about this short, so
she could still be liquidated for non-payment of interest.
## Example 4: Hyperdrive + External Lending Market - Spread Borrow
Assume that a lending market has a program where they give ptDAI 97% borrowing power
relative to DAI. So from a collateral perspective, 1 ptDAI = 0.97 DAI. Let's say
that DAI has a borrowing power of 98% if we're borrowing DAI. So from this, we
can say that 1 ptDAI allows you to borrow 0.97 * 0.98 DAI = 0.9506 DAI.
1. The fixed rate on Hyperdrive is 6% and the variable rate on the lending market is 1%.
Larry, being the smart trader that he is, decides to purchase 1000 PTs for
1000 * (1 / (1 + 0.06)) = ~943.396226415 DAI.
2. Larry deposits 1000 PTs as collateral into the lending market and borrows the maximum
amount of DAI, so he gets 950.6 DAI.
3. The variable rate stays where it is, and 1 year passes. In the interim, Larry
was able to make 5% APY with his 950.6 DAI degenerately yield farming. He
takes out 950.6 DAI and pays off loan to receive 1000 ptDAI at maturity
(worth 1000 DAI).
Larry's PnL = collateral pnl + interest pnl
= (1000 - 950.6) + ((1 + 0.05) - (1 + 0.01)) * 950.6
= 87.424 DAI