DEFI FINANCIAL MATHEMATICS AND MODELING

Calculating Sharpe and Sortino Ratios in DeFi Vaults

8 min read
#Yield Farming #Sharpe Ratio #Sortino Ratio #Risk Metrics #Crypto Analytics
Calculating Sharpe and Sortino Ratios in DeFi Vaults

When my friend Maria sent me a screenshot of her new DeFi vault – a 13‑year‑old YFI‑based yield aggregator – she asked the same thing I get across the board: “How do I know if this vault is actually worth the risk?”
She had read the total return, she had watched the TV‑style dashboards that tick over the daily APY, and yet behind the glittering numbers she felt a familiar knot of uncertainty gnawing at her curiosity.

The puzzle of “return”

We all talk about returns, but the money‑talk puzzle is that returns come alongside risk. In traditional finance we have the Sharpe ratio to remind us that a higher return is not an automatically better investment if it’s paired with higher volatility. In DeFi, that relationship is messier: returns are driven by automated compounding, impermanent loss, liquidity mining incentives, and the whims of gas fees. But the core idea still applies – you want a return that compensates you for tolerating the risk you’re willing to take.

Sharpe: total reward vs total risk

The Sharpe ratio is a simple formula:

Sharpe = (R‑rf) / σ

Where R is the average return of the asset, rf is a risk‑free return (often a stable‑coin deposit or treasury yield), and σ is the standard deviation of the asset’s returns. It tells us how many units of excess return we get per unit of total volatility.

When we translate this to a DeFi vault, the “risk‑free” baseline isn’t a bond, it’s something as simple as the APY of a high‑yield stable‑coin savings account – say, 0.5 % annualized. We can estimate daily returns by pulling transaction data from the vault’s smart contract or from a DeFi analytics API. After we compute daily excess returns, we take the standard deviation of those excess returns (over a 30‑day window is common; longer windows smooth out flash crashes but blur recent performance).

Sortino: penalising only downside

The Sortino ratio is a cousin of Sharpe, but it replaces σ with downside deviation:

Sortino = (R‑rf) / σ↓

Downside deviation is the standard deviation of only those days where the return falls below a target, usually the risk‑free rate. In practice, for a DeFi vault we count days that bring the vault’s yield below the 0.5 % baseline. Because DeFi can have occasional wipeouts (think of the sandwich attacks on DEXs), we usually want a metric that is sensitive to those negative dips but not penalised for happy high‑return days. Sortino is particularly useful when you’re more worried about losses than volatility per se.

How the numbers look in reality – an example

Let’s walk through a concrete example with Yearn’s yDAI vault, a 1‑year, 3‑quarter snapshot of its daily returns over March 2023. I pulled data from Covalent API, calculated daily percentages, and then:

  1. Subtracted the risk‑free 0.5 % annualised → 0.0013 % daily.
  2. Calculated mean excess return ≈ 0.004 % per day.
  3. Computed standard deviation of all daily returns → 0.01 % per day.
  4. Calculated downside deviation by considering only days where the return was below 0.0013 % daily.
Metric Value
Average daily excess return 0.004 %
Standard deviation 0.01 %
Downside deviation 0.0065 %

Plugging into formulas:

  • Sharpe ≈ 0.004 / 0.01 = 0.4 (annualised would multiply by √252 ≈ 6.3).
  • Sortino ≈ 0.004 / 0.0065 = 0.615 (annualised ≈ 9.5).

What does that mean? The vault delivers about 0.4 units of excess return per unit of total volatility, or roughly 6.3 on an annual basis. Its downside sensitivity is a little lower, giving a Sortino around 0.6, or 9.5 annualised. In plain language: for every 10 % of volatility, you get about 6 % of excess return, but if you only look at negative days you get roughly 9 % of excess return per 10 % of downside volatility. The higher Sortino indicates that the vault is better at dampening losses than it is at amplifying upside risk.

Visualising the volatility

It helps to see how often those dips happen. In the month of March, the vault had 5 days below the risk‑free threshold. Each of those days dropped the vault’s APY by about 2‑3 %. I’ve drawn a simple line chart of daily returns to illustrate:

Notice how most days cluster around a positive band, with the occasional large red dip. The line gives a quick visual cue that while volatility exists, extreme negative events are rare.

The caveats we can't ignore

  1. Data windows and timing – Short windows make the numbers volatile; long windows obscure recent changes. Pick a duration that matches your investment horizon, but remember that volatility can spike suddenly.
  2. Gas fees and slippage – The Sharpe or Sortino calculation assumes pure returns, neglecting transaction costs. In high‑frequency vault operations the gas spend can eat a notable fraction of the yield, especially on crowded networks.
  3. Impermanent loss – For liquidity‑pool vaults the risk of loss due to price divergence is baked into the daily return but is not reflected by volatility alone. That’s why comparing vault types (e.g., single‑token vs. balanced‑pool) matters.
  4. Compound vs. simple returns – The Sharpe ratio was originally designed for simple returns. We’ve adapted it to DeFi’s compounding, but the interpretation changes slightly. A higher Sharpe does not guarantee the best compounded annual yield.
  5. Strategic vs. tactical – If you plan to enter or exit a vault based on its metrics, keep in mind that the metric itself can create self‑fulfilling dynamics: if everyone buys when Sortino spikes, the vault’s yield trajectory could shift.

How to integrate these metrics into your portfolio

Think of the Sharpe and Sortino as two leaves on the same branch. On a daily basis you can monitor them as part of a routine, just like you might check your health or your savings goal progression. Here’s a lightweight workflow:

  • Pull: Pull historical daily returns every week from an API (Python, pandas).
  • Compute: Update Sharpe, Sortino, and a simple VaR (value at risk) metric.
  • Decide: If Sharpe dips below a threshold and the Sortino remains low, consider rebalancing or reducing exposure to that vault. Conversely, a high Sortino with a moderate Sharpe may indicate a vault that protects against loss but doesn’t offer a strong upside reward, which could complement a risk‑seeking part of your portfolio.
  • Educate: Share the numbers with your community or portfolio notes so that when decisions appear to be driven by hype, you can point to the metrics.

A short code sketch

Below is a concise Python snippet that does the heavy lifting. You’ll need a list of daily returns and the daily risk‑free rate:

import pandas as pd
import numpy as np

# Dummy data: replace with your API pulls
returns = pd.Series([0.0025, 0.0010, -0.0030, 0.0045, ...])  # daily
rf_daily = 0.000013  # 0.5% APR ≈ 0.000013 daily

excess = returns - rf_daily
sharpe_std = excess.std()
sharpe = excess.mean() / sharpe_std
sharpe_annual = sharpe * np.sqrt(252)

downside = excess[excess < 0]
downside_std = downside.std()
sortino = excess.mean() / downside_std
sortino_annual = sortino * np.sqrt(252)

print(f"Sharpe: {sharpe_annual:.2f}, Sortino: {sortino_annual:.2f}")

Feel free to tweak the window lengths, add a rolling window, or incorporate fees for a more accurate picture.

Let’s zoom out – why does this matter to you?

We often over‑emphasise raw APYs because they’re easy to see and feel exciting. But a vault with 10 % APY could be more precarious than one offering 6 % if it’s chasing performance through risky flash loans. The Sharpe ratio is a reminder that risk can be priced out of a portfolio just as easily as reward.

The Sortino ratio is especially useful in a world where market crashes happen faster than any prediction model. If you’re leaning toward a vault, you want to know: When it goes wrong, how badly does it go wrong? And the Sortino gives you a quick number that translates that question into a percentage.

I’m not saying a low Sharpe or Sortino means you should walk away forever. It means you should ask your own set of follow‑up questions: Is this risk acceptable for my overall portfolio? Does my emotional tolerance align with the downside volatility? Do I understand the smart‑contract mechanisms that could affect the vault’s behaviour?

One grounded, actionable takeaway

Pull your vault’s daily return data, calculate the Sharpe and Sortino ratios, and add them to your weekly health check. Treat them as part of your risk assessment toolbox. When a vault’s Sharpe goes below 1.0 (annualised) or its Sortino drops below 0.5, pause and review. This isn’t a rule, but a compass that keeps you from drifting into noise and lets you stay anchored to disciplined, data‑backed decisions.

In short, let the numbers guide you, but keep the conversation human. The markets will test your patience before rewarding it. When you see a vault that consistently delivers a good trade‑off between return and risk, you’ll feel more confident that your portfolio is not just chasing glitter, but building a steady, resilient garden.


Emma Varela
Written by

Emma Varela

Emma is a financial engineer and blockchain researcher specializing in decentralized market models. With years of experience in DeFi protocol design, she writes about token economics, governance systems, and the evolving dynamics of on-chain liquidity.

Contents