Mathematical Approach
Evolution of our liquidity optimization: a journey through algorithmic approaches
Last updated
Evolution of our liquidity optimization: a journey through algorithmic approaches
Last updated
Our pursuit of the most effective liquidity optimization algorithm has been a journey of exploration, experimentation, and refinement. Here’s how we evolved from simple simulations to advanced Particle Swarm Optimization (PSO), incorporating valuable lessons from intermediate approaches like Bayesian Optimization and gradient descent.
The very first idea was straightforward: given that different protocols' APRs react differently to added liquidity, we would simulate the changes to profit rates and build an optimal distribution of capital dynamically. This approach relied on evaluating APR(L) — the relationship between liquidity and annual percentage rate — at different points and iterating to find the best allocation.
The frist version of our model used a liquidity sensitivity function f(L) , where L is the total liquidity deposited in a given protocol.
The APY is a function of available liquidity:
where k is a sensitivity coefficient that varies per protocol.
Our algorithm was planned to predict the marginal impact of additional liquidity by differentiating:
However, we quickly realized the limitations of this method:
• Scalability Issues: Simulating every possible allocation quickly became computationally expensive as the number of protocols increased.
• No Unified Formula: The absence of a single formula for APR(L) across protocols made this approach cumbersome and less adaptable to dynamic conditions.
In some cases, when dealing with just two or three protocols, exhaustive search provided accurate results. However, as the number of providers grew, the time required to compute optimal distributions increased exponentially, making this approach unfeasible for scaling.
Recognizing these challenges, we pivoted to a more advanced and scalable solution: Particle Swarm Optimization (PSO).
To address these challenges, we explored more sophisticated approaches:
Gradient Descent. Algorithms like SLSQP and L-BFGS-B showed promise for optimizing APR(L). However, they required precise gradient information, which was unavailable due to the diverse and opaque formulas used by different protocols. Without this information, these methods became impractical. While there are gradient-free versions, such as numerical gradient estimation, their implementations in JavaScript were insufficiently robust for our needs.
Bayesian Optimization. This method initially seemed like the ideal solution. By modeling the relationship between inputs (liquidity allocations) and outputs (APYs) as a probabilistic distribution, Bayesian Optimization could effectively explore the solution space. Unfortunately the results were less accurate than expected. For smaller-scale scenarios, simple brute force outperformed Bayesian Optimization in both speed and precision.
Through these experiments, we concluded that the choice of algorithm should depend on the scale of the problem:
• For 2-3 providers, exhaustive search remained the most effective.
• For 10 or more providers, Bayesian Optimization or similar methods might be more appropriate, though further fine-tuning of parameters would be required to achieve optimal performance.
After recognizing the limitations of the previous approaches, we pivoted to Particle Swarm Optimization (PSO), which offered a balance of scalability, efficiency, and adaptability. PSO is particularly suited for our needs because:
• No Formula Dependency: It does not require explicit gradients or formulas for APR(L), relying instead on direct evaluations at different points.
• Dynamic Exploration: Particles (representing liquidity allocations) iteratively explore the solution space, moving toward optimal configurations based on local and global feedback.
• Scalability: PSO scales well with an increasing number of protocols, making it a robust solution for large-scale liquidity management.
In PSO, each particle adjusts its position based on:
Its own best-known position (personal best).
The best-known position of the entire swarm (global best).
A degree of randomness to avoid local optima.
This iterative process allows us to efficiently identify liquidity allocations that maximize APYs while minimizing impact on protocol profitability.
Our journey from simple simulations to PSO highlights the iterative nature of developing a robust liquidity optimization framework. While earlier approaches like Bayesian Optimization and gradient descent provided valuable insights, PSO emerged as the most practical and effective method for our needs. It allows us to:
• Dynamically adapt to changing market conditions.
• Optimize across a large number of protocols without requiring explicit formulas.
• Scale efficiently as our ecosystem grows.
By continuously refining our approach and leveraging advanced algorithms like PSO, we’ve built a system that ensures optimal liquidity distribution, supports ecosystem growth, and maximizes returns for users. This evolution reflects our commitment to pushing the boundaries of DeFi innovation while maintaining practical, scalable solutions.
• In PSO, each “particle” represents a potential liquidity distribution across protocols.
• Each particle evaluates its local performance (APY achieved with its allocation) and compares it with the global best allocation found so far.
• Particles are then adjusted to move toward the global best allocation, while still exploring new possibilities to avoid getting stuck in suboptimal solutions.
The result is a dynamic optimization process that quickly converges on the best allocation of liquidity across protocols, even as APYs fluctuate in real time.
• As new deposits enter, the model simulates different distributions in real-time and finds the allocation where additional liquidity minimally impacts the APY while maximizing returns.
• This avoids over-saturation in any single protocol and ensures efficient capital deployment.
Transition to PSO represents a major step forward in how we manage liquidity. By leveraging advanced optimization techniques, we’re not just reacting to market changes — we’re anticipating and optimizing for them in real time.
In summary, we started with simulations to approximate optimal liquidity distributions, but PSO allowed us to scale the process, improve accuracy, and dynamically respond to changing market conditions.
The update rule for each particle involves three components:
Inertia : Keeps the particle moving in the same direction, promoting exploration.
Personal Best Attraction : Draws the particle toward its own historically best allocation.
Global Best Attraction : Pulls the particle toward the best allocation discovered across all particles.