Leverage Modifier
The leverage_modifier_bps is set on the Position on initialization and affects both max_size and affects how much leverage a Position can take before it is liquidated.
To calculate it, the following is done. The algo follows a x^2 power law where the more off-kilter you are from the center, the more you are penalized/incentivized. Here's the code, with some built in examples to help you visualize.
let side_count = if side == Side::Long { longed } else { shorted };
let opposing_side_count = if side == Side::Long { shorted } else { longed };
let sum = safe_addition(longed, shorted)?;
if side_count > 0 && opposing_side_count > 0 {
// Ex 1: 10 longed, 5 short, this becomes 25
// Ex 2: 8 longed, 7 short, this becomes 1
// Ex 3: 13 longed, 2 short, this becomes 121
let difference = if side_count > opposing_side_count {
(side_count - opposing_side_count).pow(2)
} else {
(opposing_side_count - side_count).pow(2)
};
// Ex 1: with 15 total sum between longed + short, if you're longing this becomes 225-25=200
// if you re shorting this becomes 225+25=250.
// Ex 2: with 15 total sum between longed + short, if you're longing this becomes 225-1=224
// if you re shorting this becomes 225+1=226.
// Ex 3: with 15 total sum between longed + short, if you're longing this becomes 225-121=104
// if you re shorting this becomes 225+121=346.
let numerator = if side_count > opposing_side_count {
sum.pow(2) - difference
} else {
sum.pow(2) + difference
};
// Ex 1: if you're longing, we multiply by 200/225, if you're shorting we multiply by 250/225,
// meaning you can leverage 8.8% more if you're shorting, 11.1% less if you're longing for this example,
// for a 20% mismatch between longs and shorts (10 vs 5).
// Ex 2: if you're longing, we multiply by 224/225, if you're shorting we multiply by 226/225,
// meaning you can basically leverage the same amounts on both sides.
// Ex 3: if you're longing, we multiply by 104/225, if you're shorting we multiply by 346/225,
// meaning you can leverage 46.2% more if you're shorting, 53.7% less if you're longing for this example,
// for a ~100% mismatch between longs and shorts (13 vs 2).
Ok(numerator*10000/sum.pow(2));
} else {
Ok(10000)
}
Once set, this number multiplies the base max_leverage (from Pool Limits) allowed for a Position during every liquidation check and every update_position call, effectively incentivizing those making contrarian bets to take larger bets because they can remove more collateral and forcing those taking easier bets to leave more collateral on the table to cover them, engineering a Custody's long/short ratio further into balance.
The other mechanism, alluded to at the top of the article, is that it directly multiplies the base max_size from the Pool and Custody to create a modified max_size for the Position on initialization that can be larger or smaller to incentivize balancing of the long/short ratio.
Last updated