Skip to content

Commit de7005e

Browse files
committed
imf.py: fix initial margin imf plot in calculator
1 parent bbdcab7 commit de7005e

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

tabs/imf.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,15 @@ async def imf_page(clearing_house: DriftClient):
204204

205205
# Calculate effective weight
206206
base_weight = init_weight
207-
if imf != 0:
208-
base_weight = base_weight * 0.8 # Discount when IMF active
209-
210-
ddsize = np.sqrt(np.abs(base))
211-
effective_weight = max(init_weight, base_weight + imf * ddsize)
207+
if weight_type == "Liability (Borrow)":
208+
if imf != 0:
209+
base_weight = base_weight * 0.8 # Discount when IMF active
210+
211+
ddsize = np.sqrt(np.abs(base))
212+
effective_weight = max(init_weight, base_weight + imf * ddsize)
213+
else:
214+
ddsize = np.sqrt(np.abs(base))
215+
effective_weight = min(init_weight, (1.1) - imf * ddsize)
212216

213217
if weight_type == "Asset (Collateral)":
214218
st.write(f"Base Asset Weight: {init_weight:.3f}")
@@ -233,11 +237,17 @@ async def imf_page(clearing_house: DriftClient):
233237

234238
def calc_effective_weight(weight, imf, size, is_liability=True):
235239
base_weight = weight
236-
if imf != 0:
237-
base_weight = weight * 0.8
238-
dd = np.sqrt(np.abs(size))
239-
effective = max(weight, base_weight + imf * dd)
240-
return 1/effective if is_liability else effective
240+
241+
if is_liability:
242+
if imf != 0:
243+
base_weight = weight * 0.8
244+
dd = np.sqrt(np.abs(size))
245+
effective = max(weight, base_weight + imf * dd)
246+
return 1/effective if is_liability else effective
247+
else:
248+
dd = np.sqrt(np.abs(size))
249+
effective = min(weight, (1.1) - imf * dd)
250+
return effective
241251

242252
is_liability = weight_type == "Liability (Borrow)"
243253
df = pd.Series([calc_effective_weight(init_weight, imf, x, is_liability) for x in index])

0 commit comments

Comments
 (0)