您可以直接复制下面的代码到支持HTML的编辑器(如VS Code、Sublime Text,甚至是记事本保存为.html文件)中,在浏览器中打开即可使用。
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">个人基金定投计算器</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
margin: 0;
padding: 20px;
background-color: #f4f7f6;
color: #333;
}
.container {
max-width: 800px;
margin: 20px auto;
padding: 25px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
h1 {
text-align: center;
color: #2c3e50;
border-bottom: 2px solid #3498db;
padding-bottom: 10px;
}
.input-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #555;
}
input[type="number"], input[type="month"] {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box; /* Important for padding and width */
}
button {
display: block;
width: 100%;
padding: 12px;
background-color: #3498db;
color: white;
border: none;
border-radius: 4px;
font-size: 16px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #2980b9;
}
.result {
margin-top: 30px;
padding: 20px;
background-color: #ecf0f1;
border-radius: 4px;
border-left: 5px solid #3498db;
}
.result h2 {
margin-top: 0;
color: #2c3e50;
}
.result-item {
display: flex;
justify-content: space-between;
margin-bottom: 10px;
font-size: 1.1em;
}
.result-label {
font-weight: bold;
}
.result-value {
color: #27ae60;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h1>个人基金定投计算器</h1>
<div class="input-group">
<label for="monthly-investment">每月定投金额 (元):</label>
<input type="number" id="monthly-investment" value="1000" min="1">
</div>
<div class="input-group">
<label for="annual-return">预期年化收益率 (%):</label>
<input type="number" id="annual-return" value="10" min="0" max="100" step="0.1">
</div>
<div class="input-group">
<label for="investment-years">投资年限:</label>
<input type="number" id="investment-years" value="10" min="1" max="50">
</div>
<button onclick="calculate()">计算定投收益</button>
<div id="result" class="result" style="display: none;">
<h2>计算结果</h2>
<div class="result-item">
<span class="result-label">累计投入本金:</span>
<span class="result-value" id="total-principal">¥0</span>
</div>
<div class="result-item">
<span class="result-label">资产总价值:</span>
<span class="result-value" id="total-value">¥0</span>
</div>
<div class="result-item">
<span class="result-label">累计收益:</span>
<span class="result-value" id="total-profit">¥0</span>
</div>
<div class="result-item">
<span class="result-label">收益收益率:</span>
<span class="result-value" id="profit-rate">0%</span>
</div>
</div>
</div>
<script>
function calculate() {
// 1. 获取输入值
const monthlyInvestment = parseFloat(document.getElementById('monthly-investment').value);
const annualReturnRate = parseFloat(document.getElementById('annual-return').value) / 100;
const investmentYears = parseInt(document.getElementById('investment-years').value);
// 2. 计算参数
const months = investmentYears * 12;
const monthlyReturnRate = annualReturnRate / 12;
// 3. 使用未来值公式计算
// FV = P * [((1 + r)^n - 1) / r] * (1 + r)
// P = 每期投入金额
// r = 每期利率
// n = 总期数
// * (1 + r) 是因为公式假设每期期末投入,我们通常在期初投入,所以多算一期利息。
// 如果严格按期末投入,则公式为 FV = P * [((1 + r)^n - 1) / r]
// 这里我们采用更常见的期初投入计算。
const totalValue = monthlyInvestment * (Math.pow(1 + monthlyReturnRate, months) - 1) / monthlyReturnRate * (1 + monthlyReturnRate);
// 4. 计算本金和收益
const totalPrincipal = monthlyInvestment * months;
const totalProfit = totalValue - totalPrincipal;
const profitRate = (totalProfit / totalPrincipal) * 100;
// 5. 格式化并显示结果
document.getElementById('total-principal').textContent = `¥${totalPrincipal.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',')}`;
document.getElementById('total-value').textContent = `¥${totalValue.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',')}`;
document.getElementById('total-profit').textContent = `¥${totalProfit.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',')}`;
document.getElementById('profit-rate').textContent = `${profitRate.toFixed(2)}%`;
// 6. 显示结果框
document.getElementById('result').style.display = 'block';
}
</script>
</body>
</html>
这个计算器可以帮助您估算在基金定投模式下的长期收益,您只需输入三个关键信息:

计算器将为您输出四个核心结果:
本计算器基于等额分期付款的未来值公式,这是金融学中计算定期定额投资终值的经典公式。
公式:
FV = P * [((1 + r)^n - 1) / r] * (1 + r)
公式中每个字母的含义:


#基金定投真实收益计算方法#定投基金年化收益率准确计算#基金定投收益计算器使用技巧