0

编辑:

该函数的债务上限部分实际上将在我尚未编写的步骤中使用。它用于确定用户的债务收入比是否过高,但不会影响现在编写的函数的结果。

但是,我仍然遇到问题,非常感谢任何见解。我想我在 javasctipt 的下一部分中有一些不好的逻辑。这是我的新功能:

$(function(){

function calculate_affordability() {

    var income = parseFloat($('#income').val());
    var debts = parseFloat($('#debts').val());
    var apr_decimal = parseFloat($('#apr').val()) / 100;
    var monthly_interest = apr_decimal / 12;
    var down = parseFloat($('#down').val());
    var term = parseFloat($('#term').val()) * 12;

    var debts_ceiling = (debts * .08).toFixed(2);
    var mortgage_ceiling = (income * .28).toFixed(2);

    var formula_numerator = Math.pow((1 + monthly_interest), term) -1;
    var formula_denominator = monthly_interest * Math.pow((1 + monthly_interest), term);
    var formula_result = (formula_numerator / formula_denominator);

    var loan_amount = (mortgage_ceiling * formula_result).toFixed(2);

    //  the issue is in here somewhere:
    var closing_costs = (loan_amount * .03).toFixed(2);
    var actual_down = (down - closing_costs);
    var max_purchase_price = (loan_amount + actual_down);

    $('#monthly-payment').html('$' + mortgage_ceiling);
    $('#loan-amount').html('$' + loan_amount);
    $('#max-purchase-price').html('$' + max_purchase_price);
    $('#actual-down').html('$' + actual_down);
    $('#closing-costs').html('$' + closing_costs);

}


$('#term').keyup(calculate_affordability);

$('#term').mouseup(calculate_affordability);

});

再次感谢您的帮助!

原来的:

这实际上是按揭计算。

当使用正常方式时,我已经让它工作了——也就是说,当用户输入四个变量(贷款金额、首付、利率和期限年)时确定每月付款。

但是当我尝试更改公式来解决贷款金额(负担能力计算器)时,我得到了不好的结果。

这是按揭教授解释的原始公式:

以下公式用于计算按月利率 c 在 n 个月内完全摊销 L 美元贷款所需的固定每月还款额 (P)。[例如,如果报价率为 6%,则 c 为 0.06/12 或 0.005]。

P = L[c(1 + c)n]/[(1 + c)n - 1]

http://www.mtgprofessor.com/formulas.htm

我将首先给出正常工作的示例。

HTML:

<form>
    <div class="col-md-4">
        <h4>Home Price</h4>
            <input type="text" id="price">
        <h4>Down Payment</h4>
            <input type="text" id="down">
    </div>
    <div class="col-md-4">
        <h4>Rate (%)</h4>
            <input type="text" id="apr">
        <h4>Term (Years)</h4>
            <input type="text" id="term">
    </div>
    <div class="col-md-4">
        Your Monthly Payment:
        <div id="payment"></div>
    </div>
</form>

jQuery:

$(function(){

function calculate_monthly_payment() {

    var price = parseFloat($('#price').val());
    var down = parseFloat($('#down').val());
    var apr_decimal = parseFloat($('#apr').val()) / 100;
    var monthly_interest = apr_decimal / 12;
    var term = parseFloat($('#term').val()) * 12;

    var loan_amount = parseFloat(price - down);

    var formula_numerator = monthly_interest * Math.pow((1 + monthly_interest), term);
    var formula_denominator = Math.pow((1 + monthly_interest), term) -1;

    var monthly_payment = parseFloat(loan_amount * (formula_numerator / formula_denominator)).toFixed(2);

    if (!isNaN(monthly_payment)) {
        $('#payment').html('$' + monthly_payment);
    } else {
        $('#payment').html('Calculating...');
    }

}

$('#price').keyup(calculate_monthly_payment);
$('#down').keyup(calculate_monthly_payment);
$('#apr').keyup(calculate_monthly_payment);
$('#term').keyup(calculate_monthly_payment);

$('#price').mouseup(calculate_monthly_payment);
$('#down').mouseup(calculate_monthly_payment);
$('#apr').mouseup(calculate_monthly_payment);
$('#term').mouseup(calculate_monthly_payment);

});

不能正常工作的部分:

HTML:

<form>
    <div class="col-md-6">
        <h4>Income (Monthly)</h4>
            <input type="text" id="income">
        <h4>Debts (Monthly, not including housing costs)</h4>
            <input type="text" id="debts">
        <h4>Down Payment</h4>
            <input type="text" id="down">
        <h4>Rate (%)</h4>
            <input type="text" id="apr">
        <h4>Term (Years)</h4>
            <input type="text" id="term">
    </div>
    <div class="col-md-6">
        Monthly Payment:
        <div id="monthly-payment"></div>
        Loan Amount:
        <div id="loan-amount"></div>
        Purchase Price:
        <div id="purchase-price"></div>
        Down Payment:
        <div id="actual-down"></div>
        Closing Costs:
        <div id="closing-costs"></div>
    </div>
</form>

jQuery:

$(function(){

function calculate_affordability() {

    var income = parseFloat($('#income').val());
    var debts = parseFloat($('#debts').val());
    var down = parseFloat($('#down').val());
    var apr_decimal = parseFloat($('#apr').val()) / 100;
    var monthly_interest = apr_decimal / 12;
    var term = parseFloat($('#term').val());

    var debt_ceiling = income * .08;
    var monthly_payment = (income * .28).toFixed(2);

    var formula_numerator = monthly_interest * Math.pow((1 + monthly_interest), term);
    var formula_denominator = Math.pow((1 + monthly_interest), term) -1;

    var loan_amount = parseFloat(monthly_payment / (formula_numerator / formula_denominator)).toFixed(2);
    var closing_costs = (loan_amount * .03).toFixed(2);
    var actual_down = (down - closing_costs).toFixed(2);
    var purchase_price = (loan_amount - actual_down).toFixed(2);


    $('#monthly-payment').html('$' + monthly_payment);
    $('#loan-amount').html('$' + loan_amount);
    $('#purchase-price').html('$' + purchase_price);
    $('#actual-down').html('$' + actual_down);
    $('#closing-costs').html('$' + closing_costs);

}


$('#term').keyup(calculate_affordability);

$('#term').mouseup(calculate_affordability);

});

以上是基于查看公式并重新排列它。

原文:x = y(a/b)

求解 y:y = x/(a/b)

不知何故,我的新公式出错了,但我不确定在哪里以及如何修复它。

感谢您的任何帮助!

4

3 回答 3

1

新公式变为 L= P / [(1+c)^n-1]/[c(1+c)^n]

让我为你解决这个问题。要将 L 添加到另一侧,您必须乘以 1/L。所以现在等式的左边是 P/L。要摆脱 P,您必须使用多个 1/P。现在不考虑 L 会使 L 的比率为 1/L。要摆脱一个,你必须扭转右边的方程。所以你得到了上面的新公式。

于 2015-07-07T08:22:41.613 回答
0

半解决:

问题出在我的公式和一位同事身上,我发现了主要问题。当我转换原始公式时(我没有在这里非常详细地概述),我没有执行适当的代数方法来反转对另一侧所做的事情。基本上,原始公式的分数位需要翻转和相乘。所以这是新公式,求解 L 而不是 P:

L = P[(1 + c)^n -1]/[c(1 + c)^n]

原来用胡萝卜表示“n次方”:P = L[c(1 + c)^n]/[(1 + c)^n - 1]

但是仍然有一个问题,我将其添加到我原来的问题中。

于 2013-09-11T23:59:01.587 回答
0

Your monthly payment isn't being calculated correctly in the code that isn't working properly. If you look at it, you'll see that you're not factoring in your debts whatsoever.

I'm not sure exactly how you're choosing to calculate the monthly payment, but my guess is you need to subtract your debts from your income and then do your ceiling math, maybe something like this:

var debt_ceiling = (income - debts) * .92;
var monthly_payment = (debt_ceiling * .28).toFixed(2);

Or something like that... but in there is your error, I think.

于 2013-09-11T00:31:13.800 回答