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 in Others by Kithuzzz
• 20,660 points
45 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 by narikkadan
• 37,660 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 in Others by Aditya
• 7,660 points
116 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,190 points
374 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 in Others by anisha
• 140 points
68 views
0 votes
1 answer

Goal Seek in Excel

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

answered Sep 30 in Others by narikkadan
• 37,660 points
75 views
0 votes
1 answer

Historical Yahoo Finance API On Fritz Again?

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

answered Nov 17 in Others by narikkadan
• 37,660 points
49 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,720 points
452 views
0 votes
1 answer

ImportError: openpyxl is required for loading excel format files

Forget the PsychoPy complications for the time ...READ MORE

answered Oct 3, 2018 in Python by Priyaj
• 58,100 points
397 views
0 votes
1 answer
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