贷款基础知识

房贷计算涉及多个核心概念,理解这些概念是正确使用房贷计算器的前提:

LPR利率与基准利率

LPR(Loan Prime Rate,贷款市场报价利率)是中国人民银行授权全国银行间同业拆借中心发布的贷款市场基准利率。2019年8月起,商业性个人住房贷款利率以LPR为定价基准加点形成。LPR分为1年期和5年期以上两个品种,每月20日由18家报价行报价计算得出。当前5年期以上LPR为3.60%(2025年水平)。

利率上浮比例与折扣利率

银行在LPR基础上根据借款人的信用状况和贷款政策进行加点或减点,形成最终的贷款利率。例如,LPR+45bp表示在LPR基础上上浮45个基点(0.45%),即实际利率为4.05%。在过去的基准利率时代,利率常以"基准利率的X折"表示,如"基准利率的9折"即基准利率乘以0.9。

等额本息公式的数学推导

等额本息是每月还款金额固定不变的还款方式,其核心是每月偿还的本金逐月增加、利息逐月递减。设贷款本金为P,月利率为r,还款总月数为n,每月还款额为M。根据现值公式,贷款本金P等于所有月供的现值之和:

P = M/(1+r) + M/(1+r)^2 + ... + M/(1+r)^n

这是一个等比数列求和,公比 q = 1/(1+r),首项 a1 = M/(1+r):
根据等比数列求和公式:Sn = a1 * (1 - q^n) / (1 - q)

P = M/(1+r) * (1 - 1/(1+r)^n) / (1 - 1/(1+r))
  = M/(1+r) * (1 - 1/(1+r)^n) / (r/(1+r))
  = M * (1 - 1/(1+r)^n) / r

整理得等额本息核心公式:
M = P * r * (1+r)^n / ((1+r)^n - 1)

推导过程的关键点:
1. 将贷款本金视为所有月供在0时刻的现值之和
2. 利用等比数列求和公式简化计算
3. 月利率r = 年利率 / 12,还款月数n = 贷款年限 * 12
function calcEqualInstallment(float $principal, float $annualRate, int $years): array
{
    $monthlyRate = $annualRate / 100 / 12;
    $months = $years * 12;
    $factor = pow(1 + $monthlyRate, $months);
    $monthlyPayment = $principal * $monthlyRate * $factor / ($factor - 1);
    $totalPayment = $monthlyPayment * $months;
    return [
        'monthly_payment' => round($monthlyPayment, 2),
        'total_interest' => round($totalPayment - $principal, 2),
        'total_payment' => round($totalPayment, 2),
    ];
}

等额本金公式的数学推导

等额本金是每月偿还相同本金、利息逐月递减的还款方式。每月偿还本金固定为P/n,第k个月的剩余本金为P - (k-1)*P/n,因此第k个月的利息为剩余本金乘以月利率:

第k个月还款额 = P/n + [P - (k-1)*P/n] * r

总利息 = 所有月份利息之和
       = r * [P + P*(n-1)/n + P*(n-2)/n + ... + P/n]
       = r * P * (1 + (n-1)/n + (n-2)/n + ... + 1/n)
       = r * P * (n + 1) / 2
       = P * r * (n + 1) / 2

推导过程的关键点:
1. 每月偿还本金固定,利息逐月递减(等差数列)
2. 利用等差数列求和公式:Sn = n * (a1 + an) / 2
3. 递减金额为固定值:P * r / n
function calcEqualPrincipal(float $principal, float $annualRate, int $years): array
{
    $monthlyRate = $annualRate / 100 / 12;
    $months = $years * 12;
    $monthlyPrincipal = $principal / $months;
    $firstMonthInterest = $principal * $monthlyRate;
    $firstMonthPayment = $monthlyPrincipal + $firstMonthInterest;
    // 总利息 = P * r * (n + 1) / 2
    $totalInterest = $principal * $monthlyRate * ($months + 1) / 2;
    $monthlyDecrease = $monthlyPrincipal * $monthlyRate;
    return [
        'first_payment' => round($firstMonthPayment, 2),
        'monthly_decrease' => round($monthlyDecrease, 2),
        'last_payment' => round($firstMonthPayment - $monthlyDecrease * ($months - 1), 2),
        'total_interest' => round($totalInterest, 2),
        'total_payment' => round($principal + $totalInterest, 2),
    ];
}

两种还款方式30年对比表

以贷款本金100万元、年利率3.6%、贷款期限30年(360个月)为例:

对比项等额本息等额本金差异说明
每月还款额4,547.59元(固定不变)首月5,777.78元,末月2,786.11元等额本金首月多还1,230元
总利息637,131.96元541,500.00元等额本金少还95,632元
总还款额1,637,131.96元1,541,500.00元等额本金少还95,632元
前期还款压力低(固定金额)高(逐月递减)等额本金前期压力较大
适合人群收入稳定的工薪阶层前期收入高、预期收入增长的借款人根据个人现金流情况选择

公积金贷款与商业贷款利率差异

公积金贷款是国家为支持职工购房提供的政策性贷款,利率远低于商业贷款:

贷款类型5年以下(含5年)5年以上特点
公积金贷款2.35%2.85%利率低,有额度上限(各地不同,通常60-120万)
商业贷款(LPR)3.15%(1年期LPR)3.60%(5年期以上LPR)利率较高,额度灵活

组合贷款计算方法

组合贷款是指公积金贷款额度不足时,剩余部分使用商业贷款补充的方式。总月供为公积金部分月供与商业贷款部分月供之和:

function calcCombinedLoan(float $totalPrincipal, float $commercialRate, float $fundRate, float $fundLimit, int $years): array
{
    // 公积金部分
    $fundPrincipal = min($totalPrincipal, $fundLimit);
    $fundResult = calcEqualInstallment($fundPrincipal, $fundRate, $years);

    // 商业贷款部分
    $commercialPrincipal = $totalPrincipal - $fundPrincipal;
    $commercialResult = $commercialPrincipal > 0
        ? calcEqualInstallment($commercialPrincipal, $commercialRate, $years)
        : ['monthly_payment' => 0, 'total_interest' => 0, 'total_payment' => 0];

    return [
        'fund_portion' => $fundResult,
        'commercial_portion' => $commercialResult,
        'total_monthly' => round($fundResult['monthly_payment'] + $commercialResult['monthly_payment'], 2),
        'total_interest' => round($fundResult['total_interest'] + $commercialResult['total_interest'], 2),
    ];
}

提前还款计算

提前还款分为部分提前还款和全部提前还款两种方式。部分提前还款后,借款人可以选择缩短还款期限(月供不变)或减少月供金额(期限不变):

class PrepaymentCalculator
{
    /**
     * 部分提前还款 - 缩短期限模式
     */
    public function shortenTerm(float $remainingPrincipal, float $annualRate, int $remainingMonths, float $prepaymentAmount): array
    {
        $monthlyRate = $annualRate / 100 / 12;
        $newPrincipal = $remainingPrincipal - $prepaymentAmount;
        $originalMonthlyPayment = $this->calcMonthlyPayment($remainingPrincipal, $monthlyRate, $remainingMonths);

        // 保持月供不变,计算新的剩余期限
        $newMonths = 0;
        $balance = $newPrincipal;
        while ($balance > 0 && $newMonths < 600) {
            $interest = $balance * $monthlyRate;
            $principalPaid = $originalMonthlyPayment - $interest;
            $balance -= $principalPaid;
            $newMonths++;
        }

        return [
            'prepayment_amount' => $prepaymentAmount,
            'new_remaining_months' => $newMonths,
            'original_remaining_months' => $remainingMonths,
            'months_saved' => $remainingMonths - $newMonths,
        ];
    }

    /**
     * 部分提前还款 - 减少月供模式
     */
    public function reducePayment(float $remainingPrincipal, float $annualRate, int $remainingMonths, float $prepaymentAmount): array
    {
        $newPrincipal = $remainingPrincipal - $prepaymentAmount;
        $newResult = calcEqualInstallment($newPrincipal, $annualRate, intval($remainingMonths / 12));
        $originalResult = calcEqualInstallment($remainingPrincipal, $annualRate, intval($remainingMonths / 12));

        return [
            'prepayment_amount' => $prepaymentAmount,
            'original_monthly' => $originalResult['monthly_payment'],
            'new_monthly' => $newResult['monthly_payment'],
            'monthly_reduction' => round($originalResult['monthly_payment'] - $newResult['monthly_payment'], 2),
        ];
    }

    private function calcMonthlyPayment(float $principal, float $monthlyRate, int $months): float
    {
        $factor = pow(1 + $monthlyRate, $months);
        return $principal * $monthlyRate * $factor / ($factor - 1);
    }
}

还款计划表(每期明细)

function generateSchedule(float $principal, float $annualRate, int $years, string $type = 'equal_installment'): array
{
    $monthlyRate = $annualRate / 100 / 12;
    $months = $years * 12;
    $monthlyPrincipal = $principal / $months;
    $totalPayment = calcEqualInstallment($principal, $annualRate, $years)['monthly_payment'];
    $schedule = [];
    $remaining = $principal;

    for ($i = 1; $i <= $months; $i++) {
        $interest = $remaining * $monthlyRate;
        if ($type === 'equal_installment') {
            $payment = $totalPayment;
            $principalPaid = $payment - $interest;
        } else {
            $principalPaid = $monthlyPrincipal;
            $payment = $principalPaid + $interest;
        }
        $remaining -= $principalPaid;
        $schedule[] = [
            'period' => $i,
            'payment' => round($payment, 2),
            'principal' => round($principalPaid, 2),
            'interest' => round($interest, 2),
            'remaining' => round(max($remaining, 0), 2),
        ];
    }
    return $schedule;
}

税费计算

购房过程中涉及的税费种类繁多,主要包括以下项目:

税费类型计算方式税率承担方
契税房屋总价 x 税率首套90平以下1%,90平以上1.5%;二套3%买方
增值税及附加房屋总价 x 5.6%5.6%(满两年免征)卖方
个人所得税(售价-原值-合理费用)x 20% 或总价1%20%差额或1%总价卖方
维修基金建筑面积 x 单价通常20-30元/平方米买方
印花税房屋总价 x 0.05%0.05%双方
登记费固定金额80元/件买方
class PurchaseTaxCalculator
{
    public function deedTax(float $price, float $area, bool $isFirstHome): float
    {
        if (!$isFirstHome) return $price * 0.03;
        return $area <= 90 ? $price * 0.01 : $price * 0.015;
    }

    public function vat(float $price, bool $isOverTwoYears): float
    {
        return $isOverTwoYears ? 0 : $price * 0.056;
    }

    public function incomeTax(float $sellPrice, float $buyPrice, bool $isOverFiveYears, bool $isOnlyHome): float
    {
        if ($isOverFiveYears && $isOnlyHome) return 0;
        return $sellPrice * 0.01;
    }

    public function calculateAll(float $price, float $area, bool $isFirstHome, bool $isOverTwoYears, bool $isOverFiveYears, bool $isOnlyHome): array
    {
        $deedTax = $this->deedTax($price, $area, $isFirstHome);
        $vat = $this->vat($price, $isOverTwoYears);
        $incomeTax = $this->incomeTax($price, $price * 0.7, $isOverFiveYears, $isOnlyHome);
        $maintenanceFund = $area * 25;
        $stampDuty = $price * 0.0005;
        $registrationFee = 80;

        return [
            'deed_tax' => round($deedTax, 2),
            'vat' => round($vat, 2),
            'income_tax' => round($incomeTax, 2),
            'maintenance_fund' => round($maintenanceFund, 2),
            'stamp_duty' => round($stampDuty, 2),
            'registration_fee' => $registrationFee,
            'total' => round($deedTax + $vat + $incomeTax + $maintenanceFund + $stampDuty + $registrationFee, 2),
        ];
    }
}

API接口设计

接口路径参数返回数据
贷款计算GET /api/mortgage/calculateprincipal, rate, years, type月供、总利息、总还款额、还款方式
还款计划表GET /api/mortgage/scheduleprincipal, rate, years, type每期本金、利息、剩余本金明细
组合贷款GET /api/mortgage/combinedtotal, commercial_rate, fund_rate, fund_limit, years公积金和商贷两部分明细
提前还款GET /api/mortgage/prepaymentremaining, rate, months, amount, mode缩短期限或减少月供的方案
税费计算GET /api/mortgage/taxesprice, area, is_first_home, ...各项税费明细和总额