DEFI FINANCIAL MATHEMATICS AND MODELING

Building DeFi Profit Models A Practical Guide to Interest and Borrowing Dynamics

10 min read
#Yield Farming #Liquidity Provision #Protocol Economics #Borrowing Mechanics #Interest Dynamics
Building DeFi Profit Models A Practical Guide to Interest and Borrowing Dynamics

Introduction

Decentralized finance has turned the old principles of interest, borrowing, and the time value of money into a new, programmable playground. When you lend a stablecoin on a protocol or borrow an asset to amplify a position, the same financial equations that governed banks in the 19th century still apply – but the inputs and the dynamics are different. Building a profit model that takes those differences into account requires a disciplined approach: identify the relevant variables, translate them into mathematical form, and test the model against real protocol behaviour.

The goal of this guide is to give you a practical toolkit for constructing a robust DeFi profit model. We’ll walk through the core concepts of interest dynamics, the time value of money in a blockchain context, borrowing mechanics, and how to combine them into a cohesive framework that can be used to forecast returns, evaluate risk, and automate strategy execution.


Fundamentals of DeFi Interest

Simple vs. Compound Rates

In conventional finance, simple interest is calculated once per period on the initial principal. Compound interest, however, accrues on the accumulated balance, leading to exponential growth over time. DeFi protocols usually adopt a continuously compounded or discretely compounded interest model, depending on how often the rate is applied.

For a liquidity pool that updates every block, the effective annualized rate can be expressed as:

A = P * (1 + r/n)^(n*t)

where
P = principal,
r = nominal annual rate,
n = number of compounding periods per year,
t = time in years.

Because block times vary, n is derived from the average block time of the underlying chain.

Dynamic Rate Curves

Unlike a fixed interest rate set by a central authority, DeFi lending platforms use algorithmic curves that adjust rates based on pool utilization. Utilization (U) is defined as:

U = Total Borrowed / (Total Borrowed + Total Lender Deposits)

The rate r(U) is often modelled as a piecewise function: a base rate that increases linearly up to a critical utilization threshold, then steeply thereafter. This dynamic rate curve is a key concept in DeFi borrowing strategies, as explored in The DeFi Finance Playbook.

Example: Aave’s Rate Model

Aave’s model has a base rate (e.g., 2 %) and a slope that doubles once utilization passes 80 %. Graphically this looks like a gentle rise followed by a sharp jump. Understanding the shape of this curve is essential for predicting how your borrowing cost will evolve as market conditions change.

Impermanent Loss and Liquidity Providers

When providing liquidity to an automated market maker (AMM), you expose yourself to impermanent loss (IL). The net return for a liquidity provider is the sum of earned interest and IL:

Net Return = Interest Earned – Impermanent Loss

IL depends on the relative price movements of the paired assets. In a strategy that relies on steady interest income, you must model IL as a function of price volatility and liquidity depth.


The Time Value of Money in DeFi

Time value of money (TVM) remains the backbone of any profit model. In a blockchain environment, we must adjust the classic formula to account for several unique factors:

  1. Blockchain Speed – Block times determine compounding frequency.
  2. Token Impermanence – Volatility and liquidity can change the value of the returned asset.
  3. Smart‑Contract Risk – Bugs or exploits can erase funds.

Present Value Calculation

The present value (PV) of a future cash flow (FV) discounted at rate r over t periods is:

PV = FV / (1 + r)^t

In DeFi, the discount rate r often incorporates expected return on the asset plus a risk premium that reflects smart‑contract risk and market liquidity.

Discounting Across Multiple Assets

When a strategy earns different tokens (e.g., stablecoin rewards, governance tokens), you need a common valuation basis. Convert each token’s future value to a base asset (often ETH or USD) using expected future spot prices. Then discount each individually before summing.

Reinvestment and Cash Flow Timing

Some protocols allow auto-compounding of rewards, which changes the timing of cash flows. If rewards are re‑deposited immediately, you treat the reward as part of the principal for the next period. If rewards are withdrawn, you compute PV based on the withdrawal date. Modelling these flows accurately is vital for realistic profit forecasts.


Borrowing Mechanics in DeFi

Collateralization Ratio

Every borrowing operation is backed by collateral. The collateralization ratio (CR) is the ratio of the value of collateral to the borrowed amount:

CR = Collateral Value / Borrowed Value

Protocols enforce a minimum CR to protect lenders. If market prices drop, the CR can fall below the threshold, triggering liquidation.

Liquidation Penalty

Upon liquidation, the protocol seizes collateral and pays back the debt plus a penalty. The penalty is typically a percentage of the collateral value. Understanding these mechanics is central to mastering interest rates and borrowing strategies, as detailed in DeFi Yield Secrets.

Leverage and Margin Trading

Some platforms allow borrowing for the purpose of increasing exposure. Leverage amplifies both gains and losses. The effective leverage L is:

L = (Borrowed Value + Lender Deposits) / Lender Deposits

The profit function for a leveraged position must incorporate the cost of borrowing (interest) and the risk of liquidation.


Building a Profit Model: Step‑by‑Step

  1. Define the Strategy Scope

    • Identify the protocol(s) and assets involved.
    • List all sources of income: interest, rewards, trading fees.
    • Outline the borrowing and collateral components.
  2. Gather Historical Data

    • Retrieve time‑series data for utilization rates, interest rates, token prices, and liquidation thresholds.
    • Use APIs from the protocol (e.g., Aave’s subgraph) or on‑chain data via The Graph.
  3. Choose a Discount Rate

    • Base the rate on the expected return of a comparable safe asset (e.g., USDC savings rate).
    • Add a smart‑contract risk premium (e.g., 2 % annually).
    • The time‑value‑of‑money concept is further explored in Time Value of Money in DeFi.
  4. Model Interest Dynamics

    • Encode the rate curve r(U).
    • Simulate how utilization changes over time (e.g., based on historical trends or Monte‑Carlo simulations).
    • Compute future interest cash flows.
  5. Simulate Borrowing Costs

    • For each period, calculate the cost of borrowing given the current interest rate and borrowed amount.
    • Include the effect of compounding and potential auto‑compound mechanisms.
  6. Incorporate Liquidation Risk

    • Use a stochastic model for collateral price movements (e.g., geometric Brownian motion).
    • Determine the probability of liquidation for each time step.
    • Adjust expected returns by subtracting expected loss from liquidation.
  7. Account for Impermanent Loss

    • If liquidity provision is part of the strategy, model IL as a function of asset volatility and pool depth.
    • Combine IL with earned interest to get net liquidity returns.
  8. Calculate Net Cash Flows

    • Sum all income streams and subtract all costs (interest, gas fees, liquidation loss, IL).
    • Convert each cash flow to a common valuation metric (e.g., USD) using expected future prices.
  9. Discount to Present Value

    • Apply the discount rate to each future cash flow.
    • Sum to obtain the Net Present Value (NPV).
  10. Perform Sensitivity Analysis

    • Vary key parameters: utilization growth, volatility, liquidation penalty.
    • Observe how NPV responds to changes, identifying the most critical drivers.
  11. Validate with Back‑Testing

    • Run the model on historical periods to compare predicted returns against actual performance.
    • Refine parameters as needed.
  12. Deploy Automation

    • Translate the model into a smart‑contract or script that monitors real‑time data, rebalances positions, and triggers actions when thresholds are met.

Illustrative Example: Yield Farming on a Liquidity Pool

Let’s walk through a simplified example using a hypothetical pool that offers 6 % APY on stablecoin deposits and allows borrowing of a volatile token at a dynamic rate.

Parameters

  • Deposit: 10,000 USDC
  • Borrowed amount: 5,000 ETH
  • Collateralization ratio: 150 % (initially 15,000 USDC collateral)
  • Utilization curve:
    • Base rate: 3 %
    • Slope up to 70 % utilization: 0.5 % per 10 % utilization
    • Above 70 %: 1 % per 10 % utilization
  • Liquidation penalty: 12 %
  • Volatility of ETH: 30 % annualized
  • Discount rate: 4 % (safe asset rate) + 2 % smart‑contract risk premium = 6 %

Step 1: Interest Earnings

Assuming utilization stays at 60 % for the next year, the borrowing rate is:

r = 3% + (0.5% * (60/10)) = 6.5%

Borrowed ETH accrues interest of 5,000 ETH * 6.5 % = 325 ETH over a year.

Deposited USDC earns 10,000 * 6 % = 600 USDC.

Step 2: Liquidation Risk

Model ETH price as a geometric Brownian motion with drift μ = 0 and σ = 30 %. Simulate daily price paths for 365 days. For each day, compute CR:

CR = (Collateral Value) / (Borrowed Value + Interest)

If CR falls below 110 % (protocol minimum), liquidation occurs. Calculate the expected probability of liquidation (e.g., 5 % over the year).

Expected loss from liquidation = Probability * (Collateral Value * Penalty).

Step 3: Impermanent Loss

Assume the pool contains USDC and a volatile token that appreciates 10 % over the year. Impermanent loss for a 50/50 pool can be approximated by:

IL = 1 - 2 * sqrt(price ratio) / (1 + price ratio)

Plugging in the numbers gives an IL of about 4 %.

Step 4: Net Cash Flow

  • Income: 600 USDC + (325 ETH * expected price at year end)
  • Costs: 325 ETH interest + expected liquidation loss + IL

Assume ETH price ends at $2,500, so 325 ETH = 812,500 USDC.

Net cash flow ≈ 600 + 812,500 – (325 ETH interest cost) – liquidation loss – IL.

Step 5: Discount

Discount the net cash flow back to present value using the 6 % rate.

NPV ≈ Present value of 813,100 USDC ≈ 813,100 / (1.06) ≈ 767,500 USDC.

Sensitivity

If utilization jumps to 80 %, the borrowing rate rises to 9 %. Re‑run the model: interest cost increases, liquidation probability spikes, NPV drops.

This example illustrates how dynamic rate curves and borrowing strategies from The DeFi Finance Playbook can be applied.


Risk Adjustments and Real‑World Considerations

Gas Fees

Smart‑contract interactions incur gas costs, which fluctuate with network congestion. Include an estimated gas fee per operation (e.g., 0.01 ETH) and model it as a variable cost that can grow during peak periods.

Protocol Upgrades and Governance

DeFi protocols evolve quickly. A governance vote might change interest curves or liquidation penalties. Incorporate scenario analysis that tests model resilience under potential protocol changes.

Regulatory Impact

While regulatory uncertainty currently has limited direct impact on on‑chain protocols, future changes could affect user behavior (e.g., withdrawal restrictions). Monitor relevant news feeds and adjust risk premiums accordingly.

Liquidity Risk

Borrowing large amounts may drain a protocol’s liquidity, pushing rates higher. Model the impact of your own position on pool depth. Use a liquidity elasticity function that raises rates as total borrowed approaches the pool’s liquidity.


Automation Blueprint

  1. Data Feed Layer

    • Use Chainlink oracles for price data.
    • Pull utilization and rate curves via subgraph queries.
  2. Model Engine

    • Implement the profit model in a high‑level language (Python, Rust).
    • Schedule daily runs to update projections.
  3. Execution Layer

    • Trigger smart‑contract calls when the projected NPV falls below a threshold.
    • Rebalance collateral, repay debt, or harvest rewards automatically.
  4. Alert System

    • Send notifications if liquidation probability exceeds a set limit or if gas fees rise sharply.
  5. Logging and Auditing

    • Store historical model outputs and actual performance for continuous improvement.

Conclusion

Interest, borrowing dynamics, and the time value of money form the core of any DeFi profit model. By translating these classic financial concepts into the language of smart contracts and on‑chain data, you can build a model that is both rigorous and adaptable. The steps outlined above provide a concrete framework: start with a clear strategy definition, feed in real protocol data, encode the rate and liquidation mechanics, simulate future cash flows, discount them appropriately, and iterate.

With a well‑structured model in place, you can make informed decisions about which protocols to engage with, how much leverage to take, and when to exit a position. You can also automate the entire process, turning a complex, data‑heavy analysis into a set of on‑chain actions that run in real time.

The DeFi space continues to innovate at a rapid pace, but the underlying financial mathematics remains stable. Mastering these principles gives you a powerful toolset that will serve you across protocols, tokens, and market regimes.

JoshCryptoNomad
Written by

JoshCryptoNomad

CryptoNomad is a pseudonymous researcher traveling across blockchains and protocols. He uncovers the stories behind DeFi innovation, exploring cross-chain ecosystems, emerging DAOs, and the philosophical side of decentralized finance.

Discussion (8)

DE
defi_dude 2 months ago
I think the section on dynamic rate curves is spot on because it shows how utilization directly feeds into the interest rate. In particular, the gentle rise until 80 % and the sharp jump after that feel very intuitive, and I have used this shape when modeling Aave liquidity pools. So if you want to forecast returns, start by plugging in the real utilization data and watch the curve shift. I also appreciate the note that the base rate is a minimum floor, which means even in idle periods you still earn a small yield.
SK
skeptic_sam 2 months ago
I’m still not convinced that this profit model holds up when market volatility spikes because liquidity can evaporate, and the utilization curve can jump unpredictably, the projected returns might be overly optimistic. Honestly, I’ve seen a flash loan attack cut interest rates in half within seconds, which undermines the assumption that rates are smooth.
NU
num101 2 months ago
You’re right that volatility can push rates, but the model accounts for that by using a stochastic process for utilization. I run a daily scenario analysis that shows the standard deviation of projected APR stays below 0.5 % during market swings, so while the curve can jump, the average return is still reliable.
NU
num101 2 months ago
Actually, the Aave model isn’t a simple linear piecewise function; the precise equation is r(U) = base + slope1*U for U<0.8, and base + slope1*0.8 + slope2*(U-0.8) for U≥0.8. I’ve written this in Python to feed into a Monte‑Carlo simulation, and the results match on‑chain reports within 0.1 %. So if you’re using a crude approximation, you’ll end up with a 2‑3 % error margin.
NE
newbie_nina 2 months ago
I don’t really get the difference between simple and compound interest in DeFi because I’m just starting out. Is the compounding daily or hourly? And how do the smart contracts handle that? I’m really hoping for a quick clarification.
DE
defi_dude 2 months ago
In most DeFi protocols the compounding period is the block timestamp, so effectively it’s continuous. Smart contracts add interest to the principal every block or every few minutes, so you get an exponential growth over time. If you’re only looking at daily snapshots, you’ll under‑report the true yield by about 2–3 %.
PR
prof_rob 2 months ago
I built a small model last week that feeds real‑time utilization and collateral ratios from Aave into a spreadsheet, then calculates expected APR after factoring in impermanent loss. I set a 2× leverage threshold and stopped the position when the IL hit 5 %. That tiny tweak saved me about 12 % over the month, so I think the guide is useful.
QU
quick_comment 2 months ago
WOWWW!!! I can’t believe the numbers!!! 10x!!
ME
meme_master 2 months ago
Haha, 10x sounds unreal! What’s the underlying token and strategy? Anyone wanna share details before the hype spreads?
PR
profit_guru 2 months ago
I just closed a 5× leveraged position on Curve and made a 37 % profit in less than 24 hours. That’s the kind of yield you only get if you’re not listening to the blog.
DE
defi_dude 2 months ago
Congrats on the profit, but remember that 5× leverage on Curve is highly risky, especially with volatility spikes. Also, you should consider the protocol fee and the impermanent loss, which can eat a chunk of the yield.
IL
il_fool 2 months ago
Impermanent loss only happens with AMMs, so if you’re just lending on Aave, you don’t need to worry about it.
NU
num101 2 months ago
Actually, impermanent loss is relevant when you provide liquidity to a pool, not when you simply deposit a stablecoin in Aave. Lending protocols don’t expose you to price slippage, so the risk is minimal. I’m not sure why you thought otherwise.

Join the Discussion

Contents

il_fool Impermanent loss only happens with AMMs, so if you’re just lending on Aave, you don’t need to worry about it. on Building DeFi Profit Models A Practical... Aug 21, 2025 |
profit_guru I just closed a 5× leveraged position on Curve and made a 37 % profit in less than 24 hours. That’s the kind of yield yo... on Building DeFi Profit Models A Practical... Aug 21, 2025 |
quick_comment WOWWW!!! I can’t believe the numbers!!! 10x!! on Building DeFi Profit Models A Practical... Aug 20, 2025 |
prof_rob I built a small model last week that feeds real‑time utilization and collateral ratios from Aave into a spreadsheet, the... on Building DeFi Profit Models A Practical... Aug 19, 2025 |
newbie_nina I don’t really get the difference between simple and compound interest in DeFi because I’m just starting out. Is the com... on Building DeFi Profit Models A Practical... Aug 18, 2025 |
num101 Actually, the Aave model isn’t a simple linear piecewise function; the precise equation is r(U) = base + slope1*U for U<... on Building DeFi Profit Models A Practical... Aug 17, 2025 |
skeptic_sam I’m still not convinced that this profit model holds up when market volatility spikes because liquidity can evaporate, a... on Building DeFi Profit Models A Practical... Aug 16, 2025 |
defi_dude I think the section on dynamic rate curves is spot on because it shows how utilization directly feeds into the interest... on Building DeFi Profit Models A Practical... Aug 15, 2025 |
il_fool Impermanent loss only happens with AMMs, so if you’re just lending on Aave, you don’t need to worry about it. on Building DeFi Profit Models A Practical... Aug 21, 2025 |
profit_guru I just closed a 5× leveraged position on Curve and made a 37 % profit in less than 24 hours. That’s the kind of yield yo... on Building DeFi Profit Models A Practical... Aug 21, 2025 |
quick_comment WOWWW!!! I can’t believe the numbers!!! 10x!! on Building DeFi Profit Models A Practical... Aug 20, 2025 |
prof_rob I built a small model last week that feeds real‑time utilization and collateral ratios from Aave into a spreadsheet, the... on Building DeFi Profit Models A Practical... Aug 19, 2025 |
newbie_nina I don’t really get the difference between simple and compound interest in DeFi because I’m just starting out. Is the com... on Building DeFi Profit Models A Practical... Aug 18, 2025 |
num101 Actually, the Aave model isn’t a simple linear piecewise function; the precise equation is r(U) = base + slope1*U for U<... on Building DeFi Profit Models A Practical... Aug 17, 2025 |
skeptic_sam I’m still not convinced that this profit model holds up when market volatility spikes because liquidity can evaporate, a... on Building DeFi Profit Models A Practical... Aug 16, 2025 |
defi_dude I think the section on dynamic rate curves is spot on because it shows how utilization directly feeds into the interest... on Building DeFi Profit Models A Practical... Aug 15, 2025 |