fix(stock): 총 매입을 각 종목 매입가의 단순 합으로 표시
요약카드(백엔드 매입가×수량)와 증권사별(매입가 단순 합) 총 매입이 서로 달라 혼란. 박재오 정의대로 총 매입 = Σ매입가(수량 미곱산)로 통일. getBrokerSummary를 stockUtils.computeBrokerSummary로 추출(테스트 5건), usePortfolio가 portfolioSummary.total_buy를 프론트 단순 합으로 override해 요약카드·증권사별·AI 프롬프트가 동일 값 사용. 손익은 avg_price×수량 유지. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -125,6 +125,25 @@ export const emptySellForm = () => ({
|
||||
sold_at: toLocalDatetimeValue(new Date().toISOString()),
|
||||
});
|
||||
|
||||
/* ── 증권사별 요약 집계 ──────────────────────────────────────────── */
|
||||
// totalBuy: 총 매입 = 각 종목 매입가(purchase_price)의 단순 합 (수량 미곱산, 박재오 정의).
|
||||
// 매입가 미설정 시 avg_price 폴백. 백엔드 total_buy(×수량)는 표시에 쓰지 않음.
|
||||
// totalCostBasis: 손익 계산용 매입원가 = SUM(avg_price × quantity) — 손익은 수량 곱산 유지.
|
||||
export const computeBrokerSummary = (items) => {
|
||||
let totalBuy = 0, totalCostBasis = 0, totalEval = 0, hasNullPrice = false;
|
||||
for (const item of items) {
|
||||
const qty = item.quantity ?? 0;
|
||||
const purchase = item.purchase_price ?? item.avg_price ?? 0;
|
||||
totalBuy += purchase;
|
||||
totalCostBasis += (item.avg_price ?? 0) * qty;
|
||||
if (item.eval_amount != null) totalEval += item.eval_amount;
|
||||
else hasNullPrice = true;
|
||||
}
|
||||
const totalProfit = totalEval - totalCostBasis;
|
||||
const totalProfitRate = totalCostBasis > 0 ? (totalProfit / totalCostBasis) * 100 : 0;
|
||||
return { totalBuy, totalEval, totalProfit, totalProfitRate, hasNullPrice };
|
||||
};
|
||||
|
||||
/* ── TAB IDs ─────────────────────────────────────────────────────── */
|
||||
|
||||
export const TAB_PORTFOLIO = 'portfolio';
|
||||
|
||||
Reference in New Issue
Block a user