{# Math explainer fragment for the Total Return KPI tile. Receives `b: TotalReturnBreakdown`. Loaded via HTMX from /portfolio/explain/total-return and swapped into a div under the tile. #}
Total Return — {{ b.period_label }}
{# Equation: aligned 2-col grid (label | right-aligned number). #}
Ending value
${{ "{:,.2f}".format(b.ending_value|float) }}
− Starting value
−${{ "{:,.2f}".format(b.starting_value|float) }}
− Contributions
−${{ "{:,.2f}".format(b.contributions|float) }}
= Total Return
{% if b.total_return < 0 %}−{% else %}+{% endif %}${{ "{:,.2f}".format(b.total_return|float|abs) }}
{# Footnotes for the variable definitions — kept out of the equation column. #} {% if not b.is_lifetime %}
Starting value = account value at the close of the day before the period.
Contributions = deposits − withdrawals during the period.
{% endif %}
Decomposition:
Realized P/L (period)
{% if b.realized_in_period < 0 %}−{% else %}+{% endif %}${{ "{:,.2f}".format(b.realized_in_period|float|abs) }}
Δ Unrealized (period)
{% if b.delta_unrealized_residual < 0 %}−{% else %}+{% endif %}${{ "{:,.2f}".format(b.delta_unrealized_residual|float|abs) }}
= Total Return
{% if b.total_return < 0 %}−{% else %}+{% endif %}${{ "{:,.2f}".format(b.total_return|float|abs) }}
Δ Unrealized is computed as a residual (Total Return − Realized). It differs from the standalone Unrealized P/L tile, which always shows current open unrealized regardless of period.
{% if b.unpriced_lot_count and b.unpriced_lot_count > 0 %}
⚠ Starting value may be undercounted. {{ b.unpriced_lot_count }} lot{% if b.unpriced_lot_count != 1 %}s{% endif %} (cost basis ${{ "{:,.2f}".format(b.unpriced_basis_total|float) }}{% if b.unpriced_tickers %}: {{ b.unpriced_tickers[:8]|join(", ") }}{% if b.unpriced_tickers|length > 8 %}, +{{ b.unpriced_tickers|length - 8 }} more{% endif %}{% endif %}) had no historical close cached for the period boundary, so they were treated as $0 in the starting value. Run net-alpha refresh-historical-cache to repair the cache, then reopen this panel.
{% endif %}
⚠ This is informational only. Consult a tax professional before filing.