利率换算器

年利率/月利率/日利率互转,名义利率(APR)转实际年利率(EAR)

年/月/日利率互转
名义利率(APR) → 实际年利率(EAR)
function switchTab(tab){ document.querySelectorAll('.tab-btn').forEach((b,i)=>b.classList.toggle('active',(tab==='basic'?i===0:i===1))); document.getElementById('tab-basic').classList.toggle('show',tab==='basic'); document.getElementById('tab-ear').classList.toggle('show',tab==='ear'); } function calcBasic(){ const yr = parseFloat(document.getElementById('yearRate').value); const mr = parseFloat(document.getElementById('monthRate').value); const dr = parseFloat(document.getElementById('dayRate').value); const basis = parseInt(document.getElementById('dayBasis').value); let yearR, monthR, dayR; if(document.activeElement.id === 'yearRate' || (!mr && !dr)){ yearR = yr; monthR = yr / 12 * 10; // ‰ dayR = yr / basis * 100; // ‱ } else if(document.activeElement.id === 'monthRate'){ monthR = mr; yearR = mr / 10 * 12; dayR = mr / 10 / basis * 100; } else { dayR = dr; yearR = dr / 100 * basis; monthR = dr / 100 * basis / 12 * 10; } document.getElementById('yearRate').value = yearR ? yearR.toFixed(4) : ''; document.getElementById('monthRate').value = monthR ? monthR.toFixed(4) : ''; document.getElementById('dayRate').value = dayR ? dayR.toFixed(4) : ''; // 计算不同频率下的EAR const freqs = [ {name:'年复利',m:1},{name:'半年复利',m:2},{name:'季度复利',m:4}, {name:'月复利',m:12},{name:'日复利',m:365},{name:'连续复利',m:0} ]; let earHTML = ''; freqs.forEach(f=>{ let ear; if(f.m===0) ear = Math.exp(yearR/100) - 1; else ear = Math.pow(1+yearR/100/f.m, f.m) - 1; earHTML += `
${(ear*100).toFixed(4)}%
${f.name}EAR
${f.m===0?'e^r-1':'(1+r/'+f.m+')^'+f.m+'-1'}
`; }); document.getElementById('basicResult').innerHTML = earHTML; document.getElementById('basicFormula').innerHTML = `

换算公式

年利率 ÷ 12 = 月利率 → ${yearR.toFixed(4)}% ÷ 12 = ${(yearR/12).toFixed(4)}%/月 = ${monthR.toFixed(4)}‰

年利率 ÷ ${basis} = 日利率 → ${yearR.toFixed(4)}% ÷ ${basis} = ${(yearR/basis).toFixed(4)}%/日 = ${dayR.toFixed(4)}‱

注意:以上为单利换算。考虑复利后,实际年利率(EAR)会高于名义年利率。

`; } function calcEAR(){ const apr = parseFloat(document.getElementById('aprRate').value)||0; const freq = parseInt(document.getElementById('compFreq').value); let ear; if(freq===0){ ear = Math.exp(apr/100)-1; } else { ear = Math.pow(1+apr/100/freq, freq)-1; } const diff = ear*100 - apr; const freqNames={1:'年',2:'半年',4:'季度',12:'月',52:'周',365:'日',0:'连续'}; const freqName = freqNames[freq]||freq+'次'; document.getElementById('earResult').innerHTML = `
${apr.toFixed(4)}%
名义年利率 (APR)
${(ear*100).toFixed(4)}%
实际年利率 (EAR)
${diff>=0?'+':''}${diff.toFixed(4)}%
差额
`; // 不同频率对比表 const freqs=[{n:1,name:'年复利'},{n:2,name:'半年复利'},{n:4,name:'季度复利'},{n:12,name:'月复利'},{n:52,name:'周复利'},{n:365,name:'日复利'},{n:0,name:'连续复利'}]; let tableHTML=`复利频率APREAR差额计算式`; freqs.forEach(f=>{ let e=f.n===0?Math.exp(apr/100)-1:Math.pow(1+apr/100/f.n,f.n)-1; const d=e*100-apr; const isActive=(f.n===(freq||freq)); tableHTML+=`${f.name}${apr.toFixed(4)}%${(e*100).toFixed(4)}%${d>=0?'+':''}${d.toFixed(4)}%${f.n===0?'e^'+(apr/100).toFixed(4)+'-1':'(1+'+(apr/100/f.n).toFixed(6)+')^'+f.n+'-1'}`; }); document.getElementById('earTable').innerHTML = tableHTML; document.getElementById('earFormula').innerHTML = `

计算公式

APR → EAR 公式:EAR = (1 + APR/m)^m - 1

其中 m = 复利次数/年,当前 m = ${freq||'∞(连续)'}

本例:APR = ${apr}%,${freqName}复利

${freq===0 ?`EAR = e^(${(apr/100).toFixed(6)}) - 1 = ${(ear*100).toFixed(4)}%` :`EAR = (1 + ${apr}%/${freq})^${freq} - 1 = (1 + ${(apr/freq).toFixed(4)}%)^${freq} - 1 = ${(ear*100).toFixed(4)}%`}

结论:由于复利效应,实际年利率比名义利率${diff>=0?'高':'低'} ${Math.abs(diff).toFixed(4)}个百分点

`; } // 初始化 calcBasic(); calcEAR();