Fixed a UI bug calculating equity percentage incorrectly.
This commit is contained in:
@@ -533,17 +533,13 @@ def render_dashboard(snapshot: DashboardSnapshot) -> str:
|
|||||||
if snapshot.warning
|
if snapshot.warning
|
||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
latest_account_value = (
|
current_portfolio_value = sum(row.market_value for row in snapshot.portfolio)
|
||||||
snapshot.performance[-1].account_value
|
|
||||||
if snapshot.performance
|
|
||||||
else sum(row.market_value for row in snapshot.portfolio)
|
|
||||||
)
|
|
||||||
portfolio_rows = "\n".join(
|
portfolio_rows = "\n".join(
|
||||||
"<tr>"
|
"<tr>"
|
||||||
f"<td>{escape(row.symbol)}</td>"
|
f"<td>{escape(row.symbol)}</td>"
|
||||||
f"<td>{_format_number(row.quantity)}</td>"
|
f"<td>{_format_number(row.quantity)}</td>"
|
||||||
f"<td>{_format_currency(row.market_value)}</td>"
|
f"<td>{_format_currency(row.market_value)}</td>"
|
||||||
f"<td>{_format_percent(row.market_value / latest_account_value if latest_account_value else None)}</td>"
|
f"<td>{_format_percent(row.market_value / current_portfolio_value if current_portfolio_value else None)}</td>"
|
||||||
f"<td>{_format_currency(row.average_entry_price)}</td>"
|
f"<td>{_format_currency(row.average_entry_price)}</td>"
|
||||||
f"<td>{_format_currency(row.current_price)}</td>"
|
f"<td>{_format_currency(row.current_price)}</td>"
|
||||||
f"<td>{_format_currency(row.unrealized_pl)}</td>"
|
f"<td>{_format_currency(row.unrealized_pl)}</td>"
|
||||||
|
|||||||
@@ -139,3 +139,22 @@ def test_render_dashboard_contains_requested_sections() -> None:
|
|||||||
assert "FILLED</span>" in html
|
assert "FILLED</span>" in html
|
||||||
assert "orderside.sell" not in html
|
assert "orderside.sell" not in html
|
||||||
assert "orderstatus.filled" not in html
|
assert "orderstatus.filled" not in html
|
||||||
|
|
||||||
|
|
||||||
|
def test_portfolio_percentage_uses_current_portfolio_total() -> None:
|
||||||
|
html = render_dashboard(
|
||||||
|
DashboardSnapshot(
|
||||||
|
refreshed_at=datetime(2026, 8, 11, 10, 0, tzinfo=UTC),
|
||||||
|
performance=[
|
||||||
|
PerformancePoint(date(2026, 8, 11), 10_000.0, 10_000.0),
|
||||||
|
],
|
||||||
|
portfolio=[
|
||||||
|
PortfolioRow("CASH", "cash", None, 100.0, None, None, None),
|
||||||
|
PortfolioRow("SPY", "us_equity", 10.0, 10_000.0, 900.0, 1_000.0, 1_000.0),
|
||||||
|
],
|
||||||
|
trades=[],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
assert "99.01%" in html
|
||||||
|
assert "100.00%" not in html
|
||||||
|
|||||||
Reference in New Issue
Block a user