Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix calculate_implied_rate to exclude the backpaid interest from the cost basis #120

Merged
merged 2 commits into from
Jun 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading