Calculation Definitions (v1)
This page defines business meaning of key portfolio numbers. Formulas are aligned with current factory/service behavior.
Quote system
Most values are tracked in multiple quotes:
EURBTCETHUSD
Unless stated otherwise, formulas apply per quote.
Position calculations
1) Average price
Average price is the weighted acquisition cost per unit for a position.
Conceptually:
new_avg_price = (old_cost + new_order_cost) / new_total_quantity
2) Cost basis
Cost basis is capital committed for the current held quantity.
cost_basis = total_quantity * average_price
3) Market value
Market value is current valuation using latest available prices.
market_value = total_quantity * current_price
4) ROI
Position ROI expresses percentage change from average price to current price.
ROI(%) = ((current_price - average_price) / average_price) * 100
5) Unrealized and realized PnL
- UGL (unrealized gains/losses):
UGL = market_value - cost_basis- RGL (realized gains/losses):
- Updated when sells are processed; cumulative realized performance is stored per position
6) Weight in portfolio
Position weight shows portfolio share:
weight(%) = position_market_value / total_portfolio_market_value * 100
Portfolio snapshot calculations
1) Portfolio market value
Sum of market values for all positions.
2) Portfolio cost basis
Current implementation uses fiat cash-flow definition:
cost_basis = fiat_deposits - fiat_withdrawals- Supported fiat inputs in this flow:
EUR,USD,CHF
3) Portfolio UPL
UPL = portfolio_market_value - portfolio_cost_basis
4) Portfolio ROI
ROI(%) = ((portfolio_market_value - portfolio_cost_basis) / portfolio_cost_basis) * 100
5) Distribution outputs
- Instrument distribution: top N instruments +
Others - Category distribution:
BITCOIN,STABLE,MEMES,DEFI,OTHER
Fees
Fees are stored as quoted values on each transaction (fee) and contribute to transaction-level economics.
Important caveats
- If price data is missing for some instruments/timestamps, processing continues with partial results and warnings.
- Coherence checks reject operations that would create impossible negative holdings.
Related: