Effective annual rate: Excel effect() function
///////////////////////////////////////////

Effective annual rate: Excel effect() function

   Assume that a given APR (Annual Percentage Rate) is 10%, 
       compouded semiannually, what is the corresponding 
       Effective Annual Rate?

  100                 5                      5+100
  |-------------------|----------------------|
                     0.5                     1


 The Excel function called effect() can be applied. 

///////////////////////////////////////////

Effective annual rate: formula
///////////////////////////////////////////

   Effective annual rate: formula

   EAR = (1+ APR/m) ^m -1


  APR: Annual Percentage Rate
       m compounded frequency 

///////////////////////////////////////////

Other effective rates
/////////////////////////////////////
 Other effective rates

  Given: APR1, m1, m2, 
        what is APR2 with a compouding frequency of m2?

   Assume that a given APR1 (Annual Percentage Rate) is 10%, 
       compouded semiannually, what is the corresponding 
       Effective monthly rate?

/////////////////////////////////////

/////////////////////////////////////

Function APR2effect(APR1,n1,n2) As Variant
   APR2effect=(1+APR1/n1)^(n1/n2)-1
End Function

Function APR2effectHelp() As String
   APR2effectHelp = "usage: =APR2effect(APR1,n1,n2)"
End Function  

/////////////////////////////////////

Simple for loop 
///////////////////////////
# Example #1:

  for(i in 1:3) print(i)

# Example #2:

  n<-1:10
  for(j in n) print(j)

# Example #3:
  tickers<-c("ibm","c","wmt")
  for(ticker in tickers)print(ticker)

///////////////////////////

How to stop an infinitive loop
///////////////////////////

  Click the red Stop icon on the menu bar

///////////////////////////

Loops vs. matrix manipulation 
///////////////////////////
Sometimes, matrix manipulation could save us lots of time. 

For example, assume that we have a price vector, such as
  p<-c(100,102,99,120,98,120)

Assume that the price vector is sorted from the oldest to newest. 
  In other words, the first return is (102-100)/100=0.02

Method I: we use a loop
          n<-length(p)
          for(i in 1:(n-1)){
             r[i]<-p[i+1]/p[i]-1
          }

Method II: use a matrix manipulation 
           r2<-p[2:n]/p[1:(n-1)]-1

///////////////////////////