# Itô Protocol
## Core Concept
A **Stochastic AMM** combines the usual automated market-making mechanisms with **stochastic modeling of price dynamics**, meaning the pool's pricing formula incorporates randomness typically simulating asset prices with a **Geometric Brownian Motion (GBM)**.
## Stochastic Pricing Model
Asset Prices will be modelled using a Geometric Brownian Motion (GBM) because of its simplicity and common use in finance. The GBM equation is:
$$
dS_t = \mu S_t \, dt + \sigma S_t \, dW_t
$$
Where:
- S<sub>t</sub> = asset price at time t
- μ = drift (expected return)
- σ = volatility
- dW<sub>t</sub> = Wiener process (random walk)
In Discrete terms of the Implementation resolves to:
$$
S_t = S_0 \exp\left( \left(\mu - \frac{\sigma^2}{2}\right)t + \sigma \sqrt{t} Z\right)
$$
where Z is a standard normal random variable (which we will get from Chainlink Functions) Z-> `[0,1)`.
However, note that we are not simulating the entire path but sampling a price at the time of swap. So we can use:
$$
\text{EffectivePrice} = P_{\text{market}} \times \exp\left(\underbrace{-\frac{\sigma^2 \Delta t}{2}}_{\text{Convexity Adjustment}} + \underbrace{\sigma \sqrt{\Delta t} Z_0}_{\text{Random Shock}}\right)
$$
### Component Overview
1. **Drift Adjustment Term** (-σ²/2):
- Compensates for Jensen's Inequality in lognormal distributions
- Ensures E[S_t] = S₀e^{μt} (martingale property)
- Without this, prices would artificially drift upward
2. **Volatility Scaling** (σ√Δt):
- Annualized volatility scaled to time period
- Square root law comes from variance scaling in Brownian motion
- Ensures consistency across timeframes
3. **Random Shock** (Z):
- Standard normal variable (μ=0, σ=1)
- Captures unpredictable market movements
However, it's not perfect. Alternatives include:
- **Ornstein-Uhlenbeck (OU) Process**: For stablecoins (mean-reverting).
- **Jump-Diffusion Models**: To account for sudden market crashes.
---
## Liquidity
$$
Token B/Token A = (σ * currentRatio + (1 - σ) * oracleRatio)
$$
$$
Current Ratio = reserveA / reserveB
$$
$$
Oracle Ratio = 1 / Price
$$
---
## Volatility Estimation
We need the volatility σ. We can get this from historical price data. We can use Chainlink data feeds to compute the volatility over a recent period (e.g., last 30 days).
#### Why 30-day volatility?
- **Statistical Significance**: 30 days provides a more stable and reliable measure of volatility. 24h volatility can be extremely noisy and may overreact to short-term events (e.g., news, market manipulation).
- **Industry Standard**: In traditional finance, 30-day (or 1-month) volatility is widely used for options pricing and risk management.
- **Mean-Reverting Properties**: Volatility itself is mean-reverting. Using a longer time frame helps capture the "typical" volatility level rather than transient spikes.
However, for highly volatile assets or during market crises, shorter time frames (like 24h) might be more responsive. The choice depends on the asset and risk tolerance.
#### Why not use 24h?
- **Overfitting to Noise**: 24h volatility can be misleading. A single day of high volatility might not represent the asset's true risk profile.
- **Manipulation Risk**: Short-term volatility is easier to manipulate with large trades.
- **Inconsistency**: If we update the volatility too frequently (e.g., every block), it might lead to erratic fee changes and pricing.
### Fee Calculation
$$
\text{Fee} = \text{Base} + \sigma \times \text{VolMultiplier} + \frac{\text{TradeSize}}{\text{Reserves}} \times \text{DepthFactor}
$$
- Increases during high volatility
- Scales with trade size relative to pool depth
- Compensates LPs for increased risk.
### User Flow & Sequence Diagram
```mermaid
sequenceDiagram
participant User
participant SAMM
participant DataFeed
participant VRF
participant LiquidityPool
User->>SAMM: swap(1 ETH)
activate SAMM
SAMM->>DataFeed: Request volatility data
activate DataFeed
DataFeed-->>SAMM: Response (price, vol)
deactivate DataFeed
SAMM->>VRF: Request randomness
activate VRF
VRF-->>SAMM: Random number
deactivate VRF
SAMM->>SAMM: Compute Inverse CDF with Randomness
SAMM->>SAMM: Calculate stochastic price
SAMM->>LiquidityPool: Update Liquidity Pool
SAMM->>User: Transfer output tokens
deactivate SAMM
```
### Impermanent Loss Comparision

## References
- [Ito's Lemma Applied to Stock Trading](https://www.interactivebrokers.com/campus/ibkr-quant-news/itos-lemma-applied-to-stock-trading/)