Calculating the APR









up vote
1
down vote

favorite












I'm using the Microsoft.VisualBasic Assembly to use rate and Pmt for some reason when i run my code it keeps giving me a completely wrong number



I've thoroughly read the docs and cant seem to identify the issue:



origFee30YearRate = 0.04875M;
double Nper = 360;
double Pmt = Financial.Pmt((double)(origFee30YearRate / 12), Nper, 100000);
double PV = ((Pmt * Nper) * -1) - 1775.25;

var org30APR = (Financial.Rate(Nper, Pmt, PV)) * 12;


The values come out to be:



Nper: 360
Pmt: -529.20822384932933
PV: 188739.71058575856


I'm not sure whats going wrong here with calculating the Rate
The output from Rate is: 0.0006268633835987544 where is should be 5.14










share|improve this question























  • you should change the magic numbers in your PV assignment statement to doubles (i.e. 15->15d), especially the ones that are being used for division. e.g. the (1/100) part will always result in the RHS of the first - being -1775.25.
    – Tau
    Nov 9 at 15:16











  • @Charles - FWIW...I worked for a bank a year ago and had to build a loan proposal app which required APR to be calculated on the fly based changes to the loan...ie...amount, interest rate, term, etc. I spent over a month working to get it right with multiple loan officers checking my work along the way. The only way to accurately do what you are after is to calculate the amortization schedule for the life of the loan and use the remaining balance to identify the APR over the term. Financial.Rate looks promising, but will not get you what you need. The code to get it right is a beast.
    – user1011627
    Nov 9 at 17:40










  • @user1011627 any way you have that code?
    – Charles
    Nov 9 at 17:41










  • What is PV, what are you trying to calculate? 360 payments @ $529.21 is $190,515.16, your calculated PV is $188,789.71. Does that sound like 5.14% to you? Fix your PV and your call to Financial.Rate should fix itself.
    – Derrick Moeller
    Nov 9 at 18:08











  • @DerrickMoeller PV is the value of the loan, i guess i cant seem to figure out PV correctly from my understanding its the life of the loan(360) * the monthly payment(529.21) subtracting the lending fees. Not sure why this isn't adding up
    – Charles
    Nov 9 at 18:13














up vote
1
down vote

favorite












I'm using the Microsoft.VisualBasic Assembly to use rate and Pmt for some reason when i run my code it keeps giving me a completely wrong number



I've thoroughly read the docs and cant seem to identify the issue:



origFee30YearRate = 0.04875M;
double Nper = 360;
double Pmt = Financial.Pmt((double)(origFee30YearRate / 12), Nper, 100000);
double PV = ((Pmt * Nper) * -1) - 1775.25;

var org30APR = (Financial.Rate(Nper, Pmt, PV)) * 12;


The values come out to be:



Nper: 360
Pmt: -529.20822384932933
PV: 188739.71058575856


I'm not sure whats going wrong here with calculating the Rate
The output from Rate is: 0.0006268633835987544 where is should be 5.14










share|improve this question























  • you should change the magic numbers in your PV assignment statement to doubles (i.e. 15->15d), especially the ones that are being used for division. e.g. the (1/100) part will always result in the RHS of the first - being -1775.25.
    – Tau
    Nov 9 at 15:16











  • @Charles - FWIW...I worked for a bank a year ago and had to build a loan proposal app which required APR to be calculated on the fly based changes to the loan...ie...amount, interest rate, term, etc. I spent over a month working to get it right with multiple loan officers checking my work along the way. The only way to accurately do what you are after is to calculate the amortization schedule for the life of the loan and use the remaining balance to identify the APR over the term. Financial.Rate looks promising, but will not get you what you need. The code to get it right is a beast.
    – user1011627
    Nov 9 at 17:40










  • @user1011627 any way you have that code?
    – Charles
    Nov 9 at 17:41










  • What is PV, what are you trying to calculate? 360 payments @ $529.21 is $190,515.16, your calculated PV is $188,789.71. Does that sound like 5.14% to you? Fix your PV and your call to Financial.Rate should fix itself.
    – Derrick Moeller
    Nov 9 at 18:08











  • @DerrickMoeller PV is the value of the loan, i guess i cant seem to figure out PV correctly from my understanding its the life of the loan(360) * the monthly payment(529.21) subtracting the lending fees. Not sure why this isn't adding up
    – Charles
    Nov 9 at 18:13












up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm using the Microsoft.VisualBasic Assembly to use rate and Pmt for some reason when i run my code it keeps giving me a completely wrong number



I've thoroughly read the docs and cant seem to identify the issue:



origFee30YearRate = 0.04875M;
double Nper = 360;
double Pmt = Financial.Pmt((double)(origFee30YearRate / 12), Nper, 100000);
double PV = ((Pmt * Nper) * -1) - 1775.25;

var org30APR = (Financial.Rate(Nper, Pmt, PV)) * 12;


The values come out to be:



Nper: 360
Pmt: -529.20822384932933
PV: 188739.71058575856


I'm not sure whats going wrong here with calculating the Rate
The output from Rate is: 0.0006268633835987544 where is should be 5.14










share|improve this question















I'm using the Microsoft.VisualBasic Assembly to use rate and Pmt for some reason when i run my code it keeps giving me a completely wrong number



I've thoroughly read the docs and cant seem to identify the issue:



origFee30YearRate = 0.04875M;
double Nper = 360;
double Pmt = Financial.Pmt((double)(origFee30YearRate / 12), Nper, 100000);
double PV = ((Pmt * Nper) * -1) - 1775.25;

var org30APR = (Financial.Rate(Nper, Pmt, PV)) * 12;


The values come out to be:



Nper: 360
Pmt: -529.20822384932933
PV: 188739.71058575856


I'm not sure whats going wrong here with calculating the Rate
The output from Rate is: 0.0006268633835987544 where is should be 5.14







c#






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 18:11









Derrick Moeller

2,46721331




2,46721331










asked Nov 9 at 15:10









Charles

5681723




5681723











  • you should change the magic numbers in your PV assignment statement to doubles (i.e. 15->15d), especially the ones that are being used for division. e.g. the (1/100) part will always result in the RHS of the first - being -1775.25.
    – Tau
    Nov 9 at 15:16











  • @Charles - FWIW...I worked for a bank a year ago and had to build a loan proposal app which required APR to be calculated on the fly based changes to the loan...ie...amount, interest rate, term, etc. I spent over a month working to get it right with multiple loan officers checking my work along the way. The only way to accurately do what you are after is to calculate the amortization schedule for the life of the loan and use the remaining balance to identify the APR over the term. Financial.Rate looks promising, but will not get you what you need. The code to get it right is a beast.
    – user1011627
    Nov 9 at 17:40










  • @user1011627 any way you have that code?
    – Charles
    Nov 9 at 17:41










  • What is PV, what are you trying to calculate? 360 payments @ $529.21 is $190,515.16, your calculated PV is $188,789.71. Does that sound like 5.14% to you? Fix your PV and your call to Financial.Rate should fix itself.
    – Derrick Moeller
    Nov 9 at 18:08











  • @DerrickMoeller PV is the value of the loan, i guess i cant seem to figure out PV correctly from my understanding its the life of the loan(360) * the monthly payment(529.21) subtracting the lending fees. Not sure why this isn't adding up
    – Charles
    Nov 9 at 18:13
















  • you should change the magic numbers in your PV assignment statement to doubles (i.e. 15->15d), especially the ones that are being used for division. e.g. the (1/100) part will always result in the RHS of the first - being -1775.25.
    – Tau
    Nov 9 at 15:16











  • @Charles - FWIW...I worked for a bank a year ago and had to build a loan proposal app which required APR to be calculated on the fly based changes to the loan...ie...amount, interest rate, term, etc. I spent over a month working to get it right with multiple loan officers checking my work along the way. The only way to accurately do what you are after is to calculate the amortization schedule for the life of the loan and use the remaining balance to identify the APR over the term. Financial.Rate looks promising, but will not get you what you need. The code to get it right is a beast.
    – user1011627
    Nov 9 at 17:40










  • @user1011627 any way you have that code?
    – Charles
    Nov 9 at 17:41










  • What is PV, what are you trying to calculate? 360 payments @ $529.21 is $190,515.16, your calculated PV is $188,789.71. Does that sound like 5.14% to you? Fix your PV and your call to Financial.Rate should fix itself.
    – Derrick Moeller
    Nov 9 at 18:08











  • @DerrickMoeller PV is the value of the loan, i guess i cant seem to figure out PV correctly from my understanding its the life of the loan(360) * the monthly payment(529.21) subtracting the lending fees. Not sure why this isn't adding up
    – Charles
    Nov 9 at 18:13















you should change the magic numbers in your PV assignment statement to doubles (i.e. 15->15d), especially the ones that are being used for division. e.g. the (1/100) part will always result in the RHS of the first - being -1775.25.
– Tau
Nov 9 at 15:16





you should change the magic numbers in your PV assignment statement to doubles (i.e. 15->15d), especially the ones that are being used for division. e.g. the (1/100) part will always result in the RHS of the first - being -1775.25.
– Tau
Nov 9 at 15:16













@Charles - FWIW...I worked for a bank a year ago and had to build a loan proposal app which required APR to be calculated on the fly based changes to the loan...ie...amount, interest rate, term, etc. I spent over a month working to get it right with multiple loan officers checking my work along the way. The only way to accurately do what you are after is to calculate the amortization schedule for the life of the loan and use the remaining balance to identify the APR over the term. Financial.Rate looks promising, but will not get you what you need. The code to get it right is a beast.
– user1011627
Nov 9 at 17:40




@Charles - FWIW...I worked for a bank a year ago and had to build a loan proposal app which required APR to be calculated on the fly based changes to the loan...ie...amount, interest rate, term, etc. I spent over a month working to get it right with multiple loan officers checking my work along the way. The only way to accurately do what you are after is to calculate the amortization schedule for the life of the loan and use the remaining balance to identify the APR over the term. Financial.Rate looks promising, but will not get you what you need. The code to get it right is a beast.
– user1011627
Nov 9 at 17:40












@user1011627 any way you have that code?
– Charles
Nov 9 at 17:41




@user1011627 any way you have that code?
– Charles
Nov 9 at 17:41












What is PV, what are you trying to calculate? 360 payments @ $529.21 is $190,515.16, your calculated PV is $188,789.71. Does that sound like 5.14% to you? Fix your PV and your call to Financial.Rate should fix itself.
– Derrick Moeller
Nov 9 at 18:08





What is PV, what are you trying to calculate? 360 payments @ $529.21 is $190,515.16, your calculated PV is $188,789.71. Does that sound like 5.14% to you? Fix your PV and your call to Financial.Rate should fix itself.
– Derrick Moeller
Nov 9 at 18:08













@DerrickMoeller PV is the value of the loan, i guess i cant seem to figure out PV correctly from my understanding its the life of the loan(360) * the monthly payment(529.21) subtracting the lending fees. Not sure why this isn't adding up
– Charles
Nov 9 at 18:13




@DerrickMoeller PV is the value of the loan, i guess i cant seem to figure out PV correctly from my understanding its the life of the loan(360) * the monthly payment(529.21) subtracting the lending fees. Not sure why this isn't adding up
– Charles
Nov 9 at 18:13












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










To start your origFee30YearRate appears to be incorrect. 4.75% should be assigned as 0.0475 not 4.75. Also, you appear to be incorrectly changing the sign of the payment.



double origFee30YearRate = 0.0475;

double Nper = 360;
double Pmt = Financial.Pmt(origFee30YearRate / 12, Nper, 100000);
double PV = (100000 - (100000 * origFee30YearRate / 365 * 15) - (100000 * (1 / 100)) - 1775.25);

var org30APR = Financial.Rate(Nper, Pmt, PV) * 12;


This returns an interest rate of 4.92%, presumably you're trying to calculate back to 4.75%?



The reason you don't get 4.75% is because PVal is how much you borrowed and I'm not entirely sure why you're calculating it.



double origFee30YearRate = 0.0475;

double Nper = 360;
double Pmt = Financial.Pmt(origFee30YearRate / 12, Nper, 100000);

var org30APR = Financial.Rate(Nper, Pmt, 100000) * 12;


Also, if you want to change your units back to %, simply multiply by 100.



var org30APR = (Financial.Rate(Nper, Pmt, 100000) * 12) * 100;


For APR, I believe you just need to subtract the fees.



var apr = (Financial.Rate(Nper, Pmt, (100000 - 1775.25)) * 12) * 100;





share|improve this answer






















  • please refer to my comment on OP's post. PV will have the wrong value if you do integer division.
    – Tau
    Nov 9 at 16:56










  • @DerrickMoeller with a interest rate of 4.75% should return an APR of 5.04%. This algorithm is returning 4.75%
    – Charles
    Nov 9 at 18:18










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228333%2fcalculating-the-apr%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










To start your origFee30YearRate appears to be incorrect. 4.75% should be assigned as 0.0475 not 4.75. Also, you appear to be incorrectly changing the sign of the payment.



double origFee30YearRate = 0.0475;

double Nper = 360;
double Pmt = Financial.Pmt(origFee30YearRate / 12, Nper, 100000);
double PV = (100000 - (100000 * origFee30YearRate / 365 * 15) - (100000 * (1 / 100)) - 1775.25);

var org30APR = Financial.Rate(Nper, Pmt, PV) * 12;


This returns an interest rate of 4.92%, presumably you're trying to calculate back to 4.75%?



The reason you don't get 4.75% is because PVal is how much you borrowed and I'm not entirely sure why you're calculating it.



double origFee30YearRate = 0.0475;

double Nper = 360;
double Pmt = Financial.Pmt(origFee30YearRate / 12, Nper, 100000);

var org30APR = Financial.Rate(Nper, Pmt, 100000) * 12;


Also, if you want to change your units back to %, simply multiply by 100.



var org30APR = (Financial.Rate(Nper, Pmt, 100000) * 12) * 100;


For APR, I believe you just need to subtract the fees.



var apr = (Financial.Rate(Nper, Pmt, (100000 - 1775.25)) * 12) * 100;





share|improve this answer






















  • please refer to my comment on OP's post. PV will have the wrong value if you do integer division.
    – Tau
    Nov 9 at 16:56










  • @DerrickMoeller with a interest rate of 4.75% should return an APR of 5.04%. This algorithm is returning 4.75%
    – Charles
    Nov 9 at 18:18














up vote
2
down vote



accepted










To start your origFee30YearRate appears to be incorrect. 4.75% should be assigned as 0.0475 not 4.75. Also, you appear to be incorrectly changing the sign of the payment.



double origFee30YearRate = 0.0475;

double Nper = 360;
double Pmt = Financial.Pmt(origFee30YearRate / 12, Nper, 100000);
double PV = (100000 - (100000 * origFee30YearRate / 365 * 15) - (100000 * (1 / 100)) - 1775.25);

var org30APR = Financial.Rate(Nper, Pmt, PV) * 12;


This returns an interest rate of 4.92%, presumably you're trying to calculate back to 4.75%?



The reason you don't get 4.75% is because PVal is how much you borrowed and I'm not entirely sure why you're calculating it.



double origFee30YearRate = 0.0475;

double Nper = 360;
double Pmt = Financial.Pmt(origFee30YearRate / 12, Nper, 100000);

var org30APR = Financial.Rate(Nper, Pmt, 100000) * 12;


Also, if you want to change your units back to %, simply multiply by 100.



var org30APR = (Financial.Rate(Nper, Pmt, 100000) * 12) * 100;


For APR, I believe you just need to subtract the fees.



var apr = (Financial.Rate(Nper, Pmt, (100000 - 1775.25)) * 12) * 100;





share|improve this answer






















  • please refer to my comment on OP's post. PV will have the wrong value if you do integer division.
    – Tau
    Nov 9 at 16:56










  • @DerrickMoeller with a interest rate of 4.75% should return an APR of 5.04%. This algorithm is returning 4.75%
    – Charles
    Nov 9 at 18:18












up vote
2
down vote



accepted







up vote
2
down vote



accepted






To start your origFee30YearRate appears to be incorrect. 4.75% should be assigned as 0.0475 not 4.75. Also, you appear to be incorrectly changing the sign of the payment.



double origFee30YearRate = 0.0475;

double Nper = 360;
double Pmt = Financial.Pmt(origFee30YearRate / 12, Nper, 100000);
double PV = (100000 - (100000 * origFee30YearRate / 365 * 15) - (100000 * (1 / 100)) - 1775.25);

var org30APR = Financial.Rate(Nper, Pmt, PV) * 12;


This returns an interest rate of 4.92%, presumably you're trying to calculate back to 4.75%?



The reason you don't get 4.75% is because PVal is how much you borrowed and I'm not entirely sure why you're calculating it.



double origFee30YearRate = 0.0475;

double Nper = 360;
double Pmt = Financial.Pmt(origFee30YearRate / 12, Nper, 100000);

var org30APR = Financial.Rate(Nper, Pmt, 100000) * 12;


Also, if you want to change your units back to %, simply multiply by 100.



var org30APR = (Financial.Rate(Nper, Pmt, 100000) * 12) * 100;


For APR, I believe you just need to subtract the fees.



var apr = (Financial.Rate(Nper, Pmt, (100000 - 1775.25)) * 12) * 100;





share|improve this answer














To start your origFee30YearRate appears to be incorrect. 4.75% should be assigned as 0.0475 not 4.75. Also, you appear to be incorrectly changing the sign of the payment.



double origFee30YearRate = 0.0475;

double Nper = 360;
double Pmt = Financial.Pmt(origFee30YearRate / 12, Nper, 100000);
double PV = (100000 - (100000 * origFee30YearRate / 365 * 15) - (100000 * (1 / 100)) - 1775.25);

var org30APR = Financial.Rate(Nper, Pmt, PV) * 12;


This returns an interest rate of 4.92%, presumably you're trying to calculate back to 4.75%?



The reason you don't get 4.75% is because PVal is how much you borrowed and I'm not entirely sure why you're calculating it.



double origFee30YearRate = 0.0475;

double Nper = 360;
double Pmt = Financial.Pmt(origFee30YearRate / 12, Nper, 100000);

var org30APR = Financial.Rate(Nper, Pmt, 100000) * 12;


Also, if you want to change your units back to %, simply multiply by 100.



var org30APR = (Financial.Rate(Nper, Pmt, 100000) * 12) * 100;


For APR, I believe you just need to subtract the fees.



var apr = (Financial.Rate(Nper, Pmt, (100000 - 1775.25)) * 12) * 100;






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 9 at 19:51

























answered Nov 9 at 15:27









Derrick Moeller

2,46721331




2,46721331











  • please refer to my comment on OP's post. PV will have the wrong value if you do integer division.
    – Tau
    Nov 9 at 16:56










  • @DerrickMoeller with a interest rate of 4.75% should return an APR of 5.04%. This algorithm is returning 4.75%
    – Charles
    Nov 9 at 18:18
















  • please refer to my comment on OP's post. PV will have the wrong value if you do integer division.
    – Tau
    Nov 9 at 16:56










  • @DerrickMoeller with a interest rate of 4.75% should return an APR of 5.04%. This algorithm is returning 4.75%
    – Charles
    Nov 9 at 18:18















please refer to my comment on OP's post. PV will have the wrong value if you do integer division.
– Tau
Nov 9 at 16:56




please refer to my comment on OP's post. PV will have the wrong value if you do integer division.
– Tau
Nov 9 at 16:56












@DerrickMoeller with a interest rate of 4.75% should return an APR of 5.04%. This algorithm is returning 4.75%
– Charles
Nov 9 at 18:18




@DerrickMoeller with a interest rate of 4.75% should return an APR of 5.04%. This algorithm is returning 4.75%
– Charles
Nov 9 at 18:18

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228333%2fcalculating-the-apr%23new-answer', 'question_page');

);

Post as a guest














































































Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Darth Vader #20

Ondo