Steady State
İKT225 / Lecture 2
Lecture 2 · Week 2 · Irizarry ch. 2 & lecture slides · about 45 min

Vectors and Effective Rates

Why R thinks in vectors: one line of code instead of nine, built on a compound-interest homework. Then the rate arithmetic every economist needs: compound vs simple interest, effective annual rates, the rule of 70, and percentage points vs percent.

By the end you can
  • Compute future values with compound interest in R, for one rate and for several years at once
  • Create vectors with c(), :, seq() and explain element-wise arithmetic
  • Fix the four common R mistakes from Homework 1
  • Convert a nominal rate into an effective annual rate
  • Estimate doubling time with the rule of 70
  • Tell a change in percentage points from a percent change

The week had three blocks: Homework 1 written together in class, vectors (Irizarry, Introduction to Data Science, chapter 2, free online at rafalab.dfci.harvard.edu/dsbook-part-1), and effective rates, the rule of 70, and points vs percent. All interest and policy rates used this week are illustrative, not real market data.

Homework 1: compound interest in R

The problem: you deposit a principal of 50,000 TL at an annual interest rate, and interest is added to the balance every year. How much do you have after 1, 3 and 5 years?

Future value with compound interestKey formulaFormula sheet →
FV=P (1+r)tFV = P\,(1 + r)^t
FVFV
future value
PP
principal (the starting amount)
rr
interest rate per year as a decimal (40% = 0.40)
tt
number of years

Use it when interest is paid on the growing balance, not just on the original principal.

In class it was typed one variable at a time:

principal <- 50000
rate <- 0.50                      # interest rate is 50%
one.year.fv   <- principal * (1 + rate)^1
three.year.fv <- principal * (1 + rate)^3
five.year.fv  <- principal * (1 + rate)^5

At 50% this gives 75,000, 168,750 and 379,687.5. The full answer key from the slide:

Rate1 year3 years5 years
30%65,000109,850185,646.5
40%70,000137,200268,912
50%75,000168,750379,687.5
Interactive · Compound vs simple interestFV = P(1 + r)^t
years0k178k356k012345compoundsimple
principal <- 50000
rate <- 0.40
years <- c(1, 3, 5)
principal * (1 + rate)^years
[1] 70000 137200 268912
After 1 year
70,000
After 3 years
137,200
After 5 years
268,912
Simple, 5 years
150,000

The shaded gap is interest earned on interest. At 40% for 5 years compounding beats simple interest by 118,912 TL. These are the numbers from the lecture slide: 268,912 vs 150,000, a gap of 118,912.

Your turn

A principal of 50,000 TL earns 30% a year, compounded yearly. What is it worth after 3 years?

What went wrong? The four common slips

SymptomCause
Result is far too smallprincipal * 1 + 0.40^5: missing parentheses. R does ^ first, then *, then +. Write principal * (1 + 0.40)^5.
object 'principal' not foundThe chunk that defines principal was not run, or the name is spelled differently (R is case-sensitive).
Error at 0,40A decimal comma. R needs a point: 0.40.
Document will not renderAn unfinished chunk, e.g. principal <- with nothing after it.
Check your understanding

You type `principal * 1 + 0.40^5` with principal = 50,000. What does R return?

Check your understanding

You get `Error: object 'principal' not found`, but `principal <- 50000` is in your document. What is the most likely cause?

Vectors: one line instead of nine

The slide “Count the lines” made the point: for three rates and three horizons you write the formula nine times, and only the exponent changes. What if the exponent held three numbers at once?

years <- c(1, 3, 5)
principal * (1 + 0.40)^years
[1]  70000 137200 268912

There are three basic kinds of vector you will meet first:

KindExampleHolds
numericc(0.3, 0.4, 0.5)numbers
characterc("Ankara", "İzmir")text, in quotes
logicalc(TRUE, FALSE, TRUE)true/false values

Element-wise arithmetic

Arithmetic on vectors works element by element: the first element with the first, the second with the second, and so on. A single number (a vector of length 1) is reused for every element.

int.rate.vector <- c(0.3, 0.4, 0.5)
years <- c(1, 3, 5)
(1 + int.rate.vector)^years
[1] 1.30000 2.74400 7.59375
principal * (1 + int.rate.vector)^years
[1]  65000.0 137200.0 379687.5
Check your understanding

`c(2, 3, 4)^c(1, 2, 3)` returns what?

Building sequences

CodeResultUse
1:51 2 3 4 5consecutive integers
seq(1, 5, 2)1 3 5from, to, by
seq(0, 1, 0.25)0.00 0.25 0.50 0.75 1.00steps that are not whole numbers
length(x)how many elements x haschecking your vector

seq(from, to, by) is the one you will use most. With it the homework becomes: principal * (1 + 0.30)^(1:5) gives the balance for every year from 1 to 5 in one line.

Your turn

How many elements does `seq(0, 1, 0.25)` have?

Effective rates

A rate is often quoted per year but paid more often: monthly, quarterly, daily. If 40% a year is paid as 40/12=3.33%40/12 = 3.33\% every month, interest starts earning interest within the year, so you end up with more than 40%.

Effective annual rateKey formulaFormula sheet →
EAR=(1+rm)m−1EAR = \left(1 + \frac{r}{m}\right)^m - 1
rr
quoted (nominal) annual rate as a decimal
mm
number of compounding periods per year

Use it when two offers quote rates with different payment frequencies and you need to compare what they really pay.

Worked example · 40% a year, paid monthly0/4

A deposit quotes 40% a year with monthly compounding. What is the effective annual rate?

Interactive · Effective annual rateEAR = (1 + r/m)^m − 1
Yearly40.00%
Half-yearly44.00%
Quarterly46.41%
Monthly48.21%
Daily49.15%

Upper limit (continuous compounding): e^r − 1 = 49.18%

Per-period rate r/m
3.333%
Effective annual rate
48.21%

A quoted 40% paid 12 times a year grows 1 TL to 1.4821 TL after a year, so the rate you really earn is 48.21%. More frequent compounding raises the effective rate, but with a ceiling.

Check your understanding

Bank A pays 36% compounded yearly. Bank B pays 34% compounded monthly. Which pays more over a year?

The rule of 70

How long does it take for something growing at g%g\% a year to double? The exact answer solves (1+g)t=2(1 + g)^t = 2, which gives t=ln⁡2/ln⁡(1+g)t = \ln 2 / \ln(1 + g). For small gg, ln⁡(1+g)≈g\ln(1+g) \approx g and ln⁡2≈0.70\ln 2 \approx 0.70, which gives a rule you can do in your head:

Rule of 70ApproximationFormula sheet →
tdouble≈70gt_{\text{double}} \approx \frac{70}{g}
gg
growth rate in percent per year (write 7, not 0.07)
tt
years to double

Use it when you need a quick doubling time for GDP, prices, population or an investment growing at a steady rate.

Interactive · The rule of 70doubling time ≈ 70 / g
×years2×1×10.270/g = 10.0
Rule of 70: 70 / 7
10.00 yrs
Exact: ln 2 / ln(1 + g)
10.24 yrs
Error of the rule
-2.4%

For small rates the rule is almost exact, which is why it is used for GDP and price growth.

Your turn

An economy grows at 3.5% a year. Using the rule of 70, about how many years until its GDP doubles?

Points vs percent

When a rate changes, there are two ways to describe it, and they give different numbers.

Interactive · Points vs percent
Old rate40%
New rate50%

+10 percentage points  =  +25.0% percent change

Points are a subtraction: 50 − 40 = 10. Percent change divides by where you started: (50 − 40) / 40 = 25.0%. A news line "the policy rate rose 10%" from 40% means 44%, not 50%.

Check your understanding

Unemployment falls from 10% to 8%. Which statement is correct?

Exam practice

Exam question 1

Using the lecture numbers, how much more does 50,000 TL earn over 5 years at 40% with compounding than with simple interest?

Exam question 2

Which line returns the balance after 1, 3 and 5 years at 40% in one step?

Exam question 3

A loan quotes 24% a year compounded quarterly. What is the effective annual rate, in percent? (Two decimals.)

Exam question 4

Inflation rises from 4% to 6%. A headline says 'inflation up 50%'. Is it right?

Exam question 5

Prices rise 10% a year. Using the rule of 70, in how many years do prices double?

Summary and review

Review deck · 14 cards0/14 mastered