Skip to content

Commit

Permalink
fix calculate_implied_rate to exclude the backpaid interest from the …
Browse files Browse the repository at this point in the history
…cost basis (#120)

# Resolved Issues
#119 Implied rate (Short ROI) is negative in some cases where fixed >
variable

# Description
This excludes the short's backpaid interest from implied_rate calc
  • Loading branch information
MazyGio authored Jun 2, 2024
1 parent a5d53b0 commit ac182d3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/hyperdrive-math/src/short/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,22 @@ impl State {
/// &= (1 + APY)^{d} - 1
/// \end{align}
/// $$
///
/// We use the TPY to figure out the base proceeds, and calculate the rate of
/// return based on the short's opening cost. Since shorts must backpay the
/// variable interest accrued since the last checkpoint, we subtract that from
/// the opening cost, as they get it back upon closing the short.
pub fn calculate_implied_rate(
&self,
bond_amount: FixedPoint,
open_vault_share_price: FixedPoint,
variable_apy: FixedPoint,
) -> Result<I256> {
let base_paid = self.calculate_open_short(bond_amount, open_vault_share_price)?;
let full_base_paid = self.calculate_open_short(bond_amount, open_vault_share_price)?;
let backpaid_interest = bond_amount
.mul_div_down(self.vault_share_price(), open_vault_share_price)
- bond_amount;
let base_paid = full_base_paid - backpaid_interest;
let tpy =
(fixed!(1e18) + variable_apy).pow(self.annualized_position_duration())? - fixed!(1e18);
let base_proceeds = bond_amount * tpy;
Expand Down

0 comments on commit ac182d3

Please sign in to comment.