How do I calculate Interest rate R from EMI formula if I know EMI Principal P and Time N

0 votes

Hello Guys, How do I calculate tenure (N) from the EMI formula if I know EMI, Principal (P), and Interest rate (R)?

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

What should be the rate(R)?

Oct 20, 2022 in Others by Kithuzzz
• 38,020 points
620 views

1 answer to this question.

0 votes

Try this:

#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;
}
answered Oct 21, 2022 by narikkadan
• 63,680 points

Related Questions In Others

0 votes
1 answer

How do I get the current date and time in PHP?

The time would go by your server ...READ MORE

answered Feb 16, 2022 in Others by Aditya
• 7,680 points
701 views
0 votes
1 answer

How do I log into edureka Master and slave Virtual Machine

Hey @Adetayo, If you are asking about ...READ MORE

answered Apr 1, 2020 in Others by Sirajul
• 59,230 points
1,138 views
0 votes
1 answer
0 votes
1 answer

How do I UPDATE from a SELECT in SQL server?

In SQL Server, it is possible to insert ...READ MORE

answered May 30, 2022 in Others by anisha
• 140 points
581 views
0 votes
1 answer

Goal Seek in Excel

The pmt function we are using, which ...READ MORE

answered Sep 30, 2022 in Others by narikkadan
• 63,680 points
836 views
0 votes
1 answer

Historical Yahoo Finance API On Fritz Again?

It appears that Yahoo updated its finance ...READ MORE

answered Nov 17, 2022 in Others by narikkadan
• 63,680 points
2,115 views
0 votes
1 answer

Calculating a Rolling IRR in Excel

I'm assuming a little bit here, but ...READ MORE

answered Jan 3, 2023 in Others by narikkadan
• 63,680 points
1,069 views
0 votes
1 answer

Retrieve epay.info Balance with VBA and Excel

This code should log you in, provided ...READ MORE

answered Sep 5, 2018 in Blockchain by digger
• 26,740 points
1,174 views
0 votes
1 answer

How can I convert excel to PDF by Libreoffice and keep all format from excel file?

"Times New Roman" typeface does not have ...READ MORE

answered Oct 3, 2022 in Others by narikkadan
• 63,680 points
1,624 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP