Syve.ai Logo

Syve

How is profit and loss calculated?

In this post, we’ll go over our method for calculating the profit and loss (PNL) of a wallet. More specifically, we’ll go over how each metric returned by our wallet performance endpoints was calculated.

Our wallet performance endpoints are:

EndpointDocs
/wallet-api/latest-total-performancehttps://syve.readme.io/reference/latest-total-performance
/wallet-api/latest-performance-per-tokenhttps://syve.readme.io/reference/latest-performance-per-token
/wallet-api/batch-latest-total-performancehttps://syve.readme.io/reference/batch-latest-total-performance

The method that we use to calculate PNL of a wallet is the same as the method used by DEX Screener, but improved, to better reflect what would happen if you were to copy trade a wallet.

The improvement we made is to ensure a wallet has no negative trading balance. This is explained in more detail here.

The full list of metrics returned by Syve performance endpoints are given in the table below. All metrics are calculated by processing the DEX trades of a wallet.

TermDefinition
pnlpnl = realized_value - total_investment which is the same as total_sell_volume - total_buy_volume.
total_profittotal_profit = realized_profit + unrealized_profit which is the same as
pnl + unrealized_value.
total_valuetotal_value = realized_value + unrealized_value
total_investmenttotal_investment = realized_investment + unrealized_investment
total_returnThe return on total investment expressed as a percentage.

total_return = 100 * (total_profit / total_investment)
realized_profitrealized_profit = realized_value - realized_investment
realized_valuerealized_value = total_sell_amount * avg_sell_price
realized_investmentrealized_investment = total_sell_amount * avg_buy_price
realized_returnrealized_return = 100 * (realized_profit / realized_investment)
unrealized_profitunrealized_profit = unrealized_value - unrealized_investment
unrealized_valueunrealized_value = trading_balance * current_price

The unrealized value is the dollar value of all tokens that were bought but haven’t been sold yet.

For a given token, the unrealized value is calculated by multiplying its current market price by the trading balance of the wallet.

The market price of a token is the approximate price at which a wallet could sell each unit of a token. It does not take into account slippage, nor does it take into account fees.

The trading balance of a token not necessarily equal to the quantity held by a wallet. This is explained more here.
unrealized_investmentunrealized_investment = trading_balance * avg_buy_price
win_rateThe fraction of tokens for which the total profit is positive.

win_rate = total_success_count / total_tokens_traded
avg_sell_priceThe average selling price of a token, calculated by dividing the total dollar revenue from selling the token by the number of tokens sold.

avg_sell_price = total_sell_volume / total_sell_amount
avg_buy_priceThe average purchase price of a token, calculated by dividing the total dollar amount spent on the token by the number of tokens acquired.

avg_buy_price = total_buy_volume / total_buy_amount
total_buy_volumeThe total dollar value of all DEX purchases made by a wallet.
total_sell_volumeThe total dollar value of all DEX sales made by a wallet.

Using DEX trades to calculate profit

DEX trades are trades made using a decentralized exchange (e.g. Uniswap). All our profit & loss calculations are based on DEX trades. CEX trades are not taken into account as they are not visible to us.

Every time a wallet trades a token on a DEX we record the amounts and prices at which one token was traded for another. This information is then used to update their profit & loss.

DEX trades data is available through the Syve API as well. You can read our docs here.

The difference between realized and unrealized profit

Realized profit occurs when you sell an asset and the earnings are recorded based on the difference between the selling and purchase prices. It reflects actual gains or losses from transactions.

Unrealized profit is the estimated profit you can expect if you were to sell your tokens at the current market price. The market price can often significantly differ from the actual price at which you sell tokens, due to slippage and/or fees involves. For tokens with low trading volumes, this can make it difficult to estimate their true value, potentially leading to an inflated total trading profit for a wallet.

Ensuring no negative trading balance

The trading balance of a wallet is defined as the difference between the total amount of tokens sold and the total amount of tokens bought using a DEX.

trading_balance = total_buy_amount - total_sell_amount

The trading_balance of a wallet should not be confused with its actual balance. The actual balance of a wallet can be affected by events that aren’t trading related, such as receiving an airdrop.

For a given token, the trading balance of a wallet is negative if total_sell_amount is larger than total_buy_amount.

To ensure a wallet has no negative trading balance, we adjust the sell_amount of a token each time a sell trade occurs.

total_sell_amount(t) = total_sell_amount(t - 1) + sell_amount_adjusted(t)

The sell_amount is adjusted to ensure it cannot be larger than the total amount bought.

sell_amount_adjusted(t) = min(sell_amount(t), total_buy_amount(t))

Why add this requirement?

When copy trading a wallet, we are strictly interested in tracking its trading performance.

If we allow a wallet to have a negative trading balance, it can significantly inflate its performance metrics. Think of a wallet that only receives airdrops and sells them immediately. Such a wallet would have a win rate of 100%.