22 · 2026

เครื่องคำนวณปรับสมดุลพอร์ตPortfolio Rebalancer

ใส่สินทรัพย์ที่ถือกับสัดส่วนเป้าหมาย แล้วดูว่าต้องซื้อหรือขายเท่าไหร่ — มีโหมด 'ซื้ออย่างเดียว' ใช้เงินที่เติมเข้ามาโดยไม่ต้องขายEnter your holdings and target mix to see exactly what to buy or sell — including a buy-only mode that rebalances with new cash.

rebalance/index.ts
// ซื้ออย่างเดียว: แบ่งเงินตามส่วนที่ขาดconst deficits = holdings.map((h, i) =>  Math.max(0, targets[i] - h.value));const need = sum(deficits);deltas = deficits.map((d) => cash * d / need);
22TESTS9

ทำไมถึงทำ

แยกส่วน "rebalancing" ออกมาจากโปรเจกต์ระบบจัดการพอร์ตลงทุน (CP353002) ให้ลองใช้ได้ทันทีโดยไม่ต้องมี backend

Logic

  • ซื้อ/ขายได้: ปรับทุกตัวให้ตรงเป้า เป้า − ปัจจุบัน
  • ซื้ออย่างเดียว: แบ่งเงินสดใหม่ตามสัดส่วนของ "ส่วนที่ขาด" — พิสูจน์ได้ว่าผลรวมส่วนที่ขาด ≥ เงินสดเสมอ จึงไม่มีตัวไหนเกินเป้า
  • ตรวจว่าเป้ารวมได้ 100% และไม่มีค่าติดลบ ก่อนคำนวณ

การเข้าถึง

  • ตารางกรอกมี label ทุกช่อง และแสดงผลเป็นตาราง (ไม่ใช่กราฟอย่างเดียว)
  • แถบสัดส่วนมีตัวเลขกำกับ ไม่ใช้สีอย่างเดียวในการสื่อความหมาย

Why

The rebalancing piece of my investment portfolio system (CP353002), pulled out so anyone can use it instantly — no backend needed.

Logic

  • Buy & sell: move every holding to target, target − current
  • Buy only: split new cash by each holding's shortfall. The shortfalls always add up to at least the cash, so nothing overshoots its target
  • Targets must add up to 100% and values can't be negative — checked before calculating

Accessibility

  • Every input has a label, and results are a real table, not just a chart
  • Allocation bars carry numbers, so meaning never depends on colour alone