# Understanding APR via programming [closed]

I am trying to better understand different types of interest rates. However, I am having difficulties complete, consistent and pedagogically-efficient explanations online. Thus, I have decided to design and program a couple of scripts. I find that programming can be a powerful bridge to truly understand tricky concepts.

The first concept I am trying to understand is the so-called annualized percentage rate (APR). Common explanations basically mention this one as an interest rate that somehow accounts for the costs of the loan...

1. The name is very misguiding... right?
2. Does it have to be annualized if and only if the given rate is not quoted per annum?
3. Also, is it computing using the real interest rate, rather than a nominal interest rate?
4. How is the APR used in practice by loan providers? Do they establish a nominal rate that makes sense to them, add the fees and then compute the "APR" to then use it to compute interest payments?

Does the following piece of code make sense? In this piece of code, I use the term "cost-of-borrowing interest rate" to refer to the "APR":

  inflation_rate_per_year            // Annual inflation rate.
nominal_interest_rate_per_year     // Nominal interest rate per year.
real_interest_rate_per_year        // Inf-adj inf. rate per year.
cost_borrow_interest_rate_per_year // Cost-of-borrowing int. rate.
principal_money                    // Amount being loaned.
total_fees_money                   // Total to be payed in fees.
total_cost_loan_money_per_year     // Total cost of loan per year.
total_owned_money                  // Total to pay back.

// Given: inflation_rate_per_year, nominal_interest_rate_per_year
// Given: principal_money, total_fees_money

// Compute real interest rate and percentage.
real_interest_rate_per_year = nominal_interest_rate_per_year - inflation_rate_per_year

// Compute cost-of-borrowing interest rate and percentage.
cost_borrow_interest_rate_per_year =
(total_fees_money + principal_money)/principal_money*
real_interest_rate_per_year

// Compute appreciation on principal.
total_cost_loan_money_per_year =
principal_money*((1 + cost_borrow_interest_rate_per_year) - 1)

total_owned_money = principal_money*(1 + cost_borrow_interest_rate_per_year)


Why do I mean by "making sense"? Well, is it OK, considering the given interest rates assume the borrowing period to be 1 year? If it were not a year... Should I have to add the annualization factor of 365/n, with n equaling the number of days in the borrowing period.

I understand the question is posed a little vaguely. I basically want to better understand the APR via this script :)

• Are you asking about this from the statutory concept of an APR or what is often used in textbooks for students. They are not the same thing. Writing this in C++ isn't very helpful here either. Some of your definitions appear only to be valid in logarithms. What jurisdiction are you in? In the United States, there are differences of opinion as to what goes into an APR among the courts. Although usually minor differences, they do create locality based differences. – Dave Harris Oct 6 '19 at 22:39
• @DaveHarris What is the statutory concept of an APR? – Eduardo Oct 7 '19 at 18:26
• @DaveHarris: I have simplified the source code. – Eduardo Oct 7 '19 at 18:56
• Essentially, the statutory concept is that if there is a cost you must bear only because you are getting a loan and it is financed into the contract, then it is a form of interest. For example, if you had \$50 documentation fee on a \$1,000 loan with a single payment of \$1100 dollars, the law looks at it as a \$950 loan with a final payment of \\$1100 if the fee is included in the credits. Where it becomes very complicated is that specific courts consider different things a finance charge. It is a highly specialized area of law. – Dave Harris Oct 8 '19 at 23:56
• if you are concerned with the statutory meaning you are in the wrong forum. You should probably post it in the personal finance or the law forum. – Dave Harris Oct 9 '19 at 0:00