如果我知道EMI,校长(P)和时间(N),我如何根据EMI公式计算利率(R)?

时间:2018-05-31 14:10:03

标签: finance rate principal

你好,如果我知道EMI,本金(P)和利率(R),如何计算EMI公式的任期(N)?

Example:
P=50000;
EMI=4368;
N(month)=12

费率(R)应该是多少?

2 个答案:

答案 0 :(得分:0)

可能有一些方法可以用对数来做,不知道

#include <iostream>
#include <cmath>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/thread/thread.hpp>

#define TOLERANCE 0.0000001

using namespace std;
using namespace boost::posix_time;

bool active(true);

// just adjust the calc if this isn't the right formula
//
//     EMI = [P x R x (1+R)^N] / [(1+R)^N-1]
//
double calc(double p, double r, double n) {
    return  p * r * pow(r + 1.0, n) / (pow(r + 1.0, n) - 1.0);
}

void timeout_loop() {
    ptime start = microsec_clock::local_time();
    time_duration timeout(seconds(10));

    while(active) {
        boost::this_thread::sleep(milliseconds(1));

        if((microsec_clock::local_time() - start).total_milliseconds() > timeout.total_milliseconds()) {
            cout << "timeout" << endl;
            active = false;
        }
    }
}

int main() {
    double p(50000.0);
    double target(4368.0);
    double n(12.0);

    double min(0.0);
    double max(1.0);
    double current = (max + min) / 2.0;

    boost::thread timeout_thread(timeout_loop);

    while(active) {
        double emi = calc(p, current, n);

        if((target - emi) > TOLERANCE) {
            min = current;
            current = (max + min) / 2.0;
        } else if((emi - target) > TOLERANCE) {
            max = current;
            current = (max + min) / 2.0;
        } else {
            cout << setprecision(12) << current << endl;
            break;
        }
    }

    active = false;

    timeout_thread.join();

    return 0;
}

0.00733556627529

答案 1 :(得分:0)

也许这个答案为时已晚,但是希望这可以帮助仍在寻找答案的任何人。

要通过EMI计算速率,可以在Excel中使用RATE函数。

RATE(nper,pmt,pv)

nper:几个月的贷款期限 pmt:电磁干扰 pv:本金

如果您需要Java实现,请参考以下文章:

http://www.programmersought.com/article/9304223046/