---
# System prepended metadata

title: rebalancing

---

# rebalancing


Purpose: A rough framework for how we can rebalancing to document ideas discussed on last call, there is more than one solution but we can use this as a scaffold to get to a working answer (ie its more like notes from the last call)

Function to compute deltas

glp_alloc_copy = glp_allocations.copy()

    # sum of all glp allocations that have been removed to keep track of how much we need to hedge externally
    # in iterations going forward
    sum_pi = []
    
So we have variable tracks the glp we need to hedge

first we need a Function  that transforms this into hedgres  we need to execute, its basically going to be F(glp_allocations, vault_adjusted_hedge amount ) , the rebalancing framework can be as simple as


Rebalacing 

1- T0 we record or glp_allocations, vault_adjusted_hedge amount and sum of glp owned per vault and vault usd tvls, and out internal hedge notionals, (can also jsut record all of this and the delta positions we computed )

2-T+1 we compute a mark to market ie assign pnl to perp hedges for each vaults  internal hedges using the price returns we can calulate from the gmx spot oracle
ie (usd notional of hedge)*(1-eth(T)/eth(T-1)) 

3we also other re compute deltas or called saved deltas and on a pro rata basis can assign realised funding costs (its a small drain on tvl for the next calibration)

4We also need to remark the glp and the hedges to get new vault tvl with an at latest price 



5- so we have a mtm in usd notional for internal hedges and we just adjust vault tvls for the next fit

6- we also take in deposits and process withdrawals that also add or subtract from tvl


7- sub point is to think about buffers (ie when do we want deposits to sit in buffer and when do we fit), how much float is allowed in the buffer (Essentially we feed tvl post buffer to the delta model), i would suggest we use buffers to top up tvl until threshold of x to keep positions ie tvl pos buffer goes from 95>90 we use 5 from the buffer to keep the positions intact and not ahve to change anything and have a threshold on this

8- Similar point for topping up margin on hedges (do we want to do that now?)- it probly makes sense to top up margin after rebalancing (so you top up the correct set of exposures )

9- We compute a new fit from the vaultFactory (ie the delta fit) and this gives
a new F(glp_allocations, vault_adjusted_hedge amount )

10- We compare the difference of the function output at time T - function output at T-1 ie the change in various hedges, we also comparte the sum of Glp at Time T comapared to T-1, we do this on a per vault basis

11 To get what we need to sum on chain we sum the difference over vaults

12- to assign fees for whats trades we can use the combination of the sum accross vault and the vault sum
usdc vault sells 50 glp
btc vault +25 glp
eth vault +100 glp

net ubying of 75 where eth vault needs to pay for 80% of the opening fee 100/125 (ie pro rata)

Execution Logic (seperate not but some thing in rebalancing could also be done in execution logic  )



