function formatIdr(idr) {
const abs = Math.abs(idr);
if (abs >= 1e9) return `Rp ${(idr / 1e9).toFixed(2)}B`;
if (abs >= 1e6) return `Rp ${(idr / 1e6).toFixed(2)}M`;
return `Rp ${Math.round(idr).toLocaleString("en-US")}`;
}
function computeModel() {
const row = orderedSbn.find(d => d.series === selectedSeries) || orderedSbn[0];
const principalIdr = principalM * 1e6;
const biShocked = biRateBase + biShockBps / 100;
const isCustom = Boolean(useCustomSbn);
const couponType = isCustom ? customCouponType : row.coupon_type;
const isFloating = couponType === "Floating with floor";
const tenorY = isCustom ? customTenorY : Number(row.tenor_years);
const floorPct = isCustom ? customCouponPct : Number(row.initial_coupon_pct);
const spreadBps = isCustom ? (isFloating ? customSpreadBps : 0) : (row.spread_bps ? Number(row.spread_bps) : 0);
const tradable = isCustom ? !isFloating : (row.tradable === true || row.tradable === "true");
const earlyRedemption = isCustom ? isFloating : (row.early_redemption === true || row.early_redemption === "true");
// Retail SBN gross coupon under BI-Rate shock
const sbnGrossPct = isFloating
? Math.max(floorPct, biShocked + spreadBps / 100)
: floorPct;
const sbnNetPct = sbnGrossPct * (1 - taxSbnPct / 100);
const sbnMonthlyNet = principalIdr * (sbnNetPct / 100) / 12;
const sbnTotalProfit = principalIdr * (sbnNetPct / 100) * tenorY;
// Bank deposit
const isBpr = bankTier.startsWith("BPR");
const lpsRateCap = isBpr ? lpsBprCap : lpsBankCap;
const lpsPrincipalCapM = 2000; // Rp 2B per depositor per bank
const rateBreach = depositGrossPct > lpsRateCap + 1e-9;
const principalBreach = principalM > lpsPrincipalCapM;
const lpsInsured = !rateBreach && !principalBreach;
const depNetPct = depositGrossPct * (1 - taxDepPct / 100);
const depMonthlyNet = principalIdr * (depNetPct / 100) / 12;
const depTotalProfit = principalIdr * (depNetPct / 100) * tenorY;
const lpsBankNetPct = lpsBankCap * (1 - taxDepPct / 100);
const lpsBprNetPct = lpsBprCap * (1 - taxDepPct / 100);
// Breakeven gross deposit rate to match Retail SBN net yield
const depTaxDenom = Math.max(0.01, 1 - taxDepPct / 100);
const breakevenDepGrossPct = sbnNetPct / depTaxDenom;
// Mutual fund (RDPT / RDPU)
let fundGrossPct = fundCustomGrossPct;
let fundLabel = "Mutual Fund (Custom)";
if (fundPreset.includes("5Y SBN")) {
fundGrossPct = sbn5yBench;
fundLabel = "RDPT (5Y SBN)";
} else if (fundPreset.includes("2Y SBN")) {
fundGrossPct = sbn2yBench;
fundLabel = "RDPT (2Y SBN)";
} else if (fundPreset.includes("12M SRBI")) {
fundGrossPct = srbi12Bench;
fundLabel = "RDPU (12M SRBI)";
}
const fundAfterInternalPct = fundGrossPct * (1 - taxFundInternalPct / 100) - fundTerPct;
const fundNetPct = Math.max(0, fundAfterInternalPct * (1 - taxFundInvestorPct / 100));
const fundMonthlyNet = principalIdr * (fundNetPct / 100) / 12;
const fundTotalProfit = principalIdr * (fundNetPct / 100) * tenorY;
const sbnPickupVsUserDepBps = (sbnNetPct - depNetPct) * 100;
const sbnPickupVsLpsBankBps = (sbnNetPct - lpsBankNetPct) * 100;
const sbnPickupVsFundBps = (sbnNetPct - fundNetPct) * 100;
// Bar comparison rows
const barData = [
{
label: isCustom ? `Custom SBN (${tenorY}Y)` : `${row.series} (${tenorY}Y)`,
group: "Retail SBN",
gross: sbnGrossPct,
net: sbnNetPct,
profit: sbnTotalProfit,
color: gold
},
{
label: fundLabel,
group: "Mutual Fund",
gross: fundGrossPct,
net: fundNetPct,
profit: fundTotalProfit,
color: teal
},
{
label: `Your Deposit (${depositGrossPct.toFixed(2)}%)`,
group: lpsInsured ? "Deposit (LPS OK)" : "Deposit (Uninsured)",
gross: depositGrossPct,
net: depNetPct,
profit: depTotalProfit,
color: lpsInsured ? grey : red
},
{
label: `LPS Bank Umum Cap (${lpsBankCap.toFixed(2)}%)`,
group: "LPS Cap",
gross: lpsBankCap,
net: lpsBankNetPct,
profit: principalIdr * (lpsBankNetPct / 100) * tenorY,
color: greyDark
},
{
label: `LPS BPR Cap (${lpsBprCap.toFixed(2)}%)`,
group: "LPS Cap",
gross: lpsBprCap,
net: lpsBprNetPct,
profit: principalIdr * (lpsBprNetPct / 100) * tenorY,
color: grey
}
];
// Cumulative net IDR profit path over months 0 .. 12*tenorY
const totalMonths = tenorY * 12;
const growthPath = [];
for (let m = 0; m <= totalMonths; m++) {
growthPath.push({month: m, instrument: isCustom ? "Retail SBN" : row.series, net_profit_m: (sbnMonthlyNet * m) / 1e6});
growthPath.push({month: m, instrument: fundLabel, net_profit_m: (fundMonthlyNet * m) / 1e6});
growthPath.push({month: m, instrument: "Bank Deposit (Your Rate)", net_profit_m: (depMonthlyNet * m) / 1e6});
growthPath.push({month: m, instrument: "LPS Bank Umum Cap (4.25%)", net_profit_m: (principalIdr * (lpsBankNetPct / 100) / 12 * m) / 1e6});
}
// BI-Rate shock sensitivity curve (-150 bps to +150 bps)
const shockCurve = [];
for (let bps = -150; bps <= 150; bps += 25) {
const biS = biRateBase + bps / 100;
const gSbn = isFloating ? Math.max(floorPct, biS + spreadBps / 100) : floorPct;
const nSbn = gSbn * (1 - taxSbnPct / 100);
// Deposit assumed 0.5x pass-through around user's chosen rate for sensitivity view
const gDep = Math.max(1.0, depositGrossPct + 0.5 * bps / 100);
const nDep = gDep * (1 - taxDepPct / 100);
shockCurve.push({shock_bps: bps, bi_rate: biS, instrument: isCustom ? "Retail SBN" : row.series, net_yield: nSbn});
shockCurve.push({shock_bps: bps, bi_rate: biS, instrument: "Bank Deposit (0.5x beta)", net_yield: nDep});
}
return {
row, isCustom, couponType, isFloating, tenorY, floorPct, spreadBps, tradable, earlyRedemption,
principalIdr, biShocked,
sbnGrossPct, sbnNetPct, sbnMonthlyNet, sbnTotalProfit,
depositGrossPct, depNetPct, depMonthlyNet, depTotalProfit,
lpsRateCap, lpsPrincipalCapM, rateBreach, principalBreach, lpsInsured, isBpr,
lpsBankNetPct, breakevenDepGrossPct,
fundLabel, fundGrossPct, fundNetPct, fundMonthlyNet, fundTotalProfit,
sbnPickupVsUserDepBps, sbnPickupVsLpsBankBps, sbnPickupVsFundBps,
barData, growthPath, shockCurve
};
}
sim = computeModel()