mirror of
https://github.com/wahyd4/links.git
synced 2026-08-09 05:06:16 +10:00
feat: show dollar + % week change per stock in portfolio table
This commit is contained in:
@@ -96,9 +96,11 @@ def get_portfolio_value(portfolio: Portfolio) -> dict:
|
||||
|
||||
price_change = None
|
||||
price_change_pct = None
|
||||
value_change = None
|
||||
if price and last_week_price and last_week_price > 0:
|
||||
price_change = round(price - last_week_price, 4)
|
||||
price_change_pct = round((price_change / last_week_price) * 100, 2)
|
||||
value_change = round(price_change * float(stock.quantity), 2)
|
||||
|
||||
holdings.append({
|
||||
'stock_code': stock.stock_code,
|
||||
@@ -108,6 +110,7 @@ def get_portfolio_value(portfolio: Portfolio) -> dict:
|
||||
'last_week_price': last_week_price,
|
||||
'price_change': price_change,
|
||||
'price_change_pct': price_change_pct,
|
||||
'value_change': value_change,
|
||||
})
|
||||
total_value += value
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@
|
||||
<th class="px-6 py-3 text-left">Ticker</th>
|
||||
<th class="px-6 py-3 text-right">Qty</th>
|
||||
<th class="px-6 py-3 text-right">Price</th>
|
||||
<th class="px-6 py-3 text-right">Week</th>
|
||||
<th class="px-6 py-3 text-right">Week Change</th>
|
||||
<th class="px-6 py-3 text-right">Mkt Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -143,9 +143,9 @@
|
||||
{% if stock.current_price %}${{ stock.current_price|floatformat:2 }}{% else %}<span class="text-stone-300">—</span>{% endif %}
|
||||
</td>
|
||||
<td class="px-6 py-3 text-right">
|
||||
{% if stock.price_change is not None %}
|
||||
<span class="text-xs font-medium {% if stock.price_change >= 0 %}text-green-700{% else %}text-red-600{% endif %}">
|
||||
{% if stock.price_change >= 0 %}+{% endif %}{{ stock.price_change_pct|floatformat:1 }}%
|
||||
{% if stock.value_change is not None %}
|
||||
<span class="text-xs font-medium {% if stock.value_change >= 0 %}text-green-700{% else %}text-red-600{% endif %}">
|
||||
{% if stock.value_change >= 0 %}+{% endif %}${{ stock.value_change|floatformat:0 }} ({% if stock.price_change_pct >= 0 %}+{% endif %}{{ stock.price_change_pct|floatformat:1 }}%)
|
||||
</span>
|
||||
{% else %}
|
||||
<span class="text-stone-300">—</span>
|
||||
|
||||
Reference in New Issue
Block a user