present value formula for perpetuity 
////////////////////////////////
Write an R program to calculate present value for perpetuity
 The definition of perpetuity: same cash flows at the same interval forever.
 Example #1: 
                          c        c   -> infinity 
   |-------|-------|-------|   ... |
   0       1       2       3           -> infinity 
 Example #2:
           c       c      c        c   -> infinity 
   |-------|-------|-------|   ... |
   0       1       2       3           -> infinity 
  When the first cash flow occurs at the end of the first period, we have the following formula 
                     C
  pv(perpetuity) = ------
                     R
  where C is the constant cash flow
        R is the period discount rate

present value formula for annuity 
------------------------------
Definition of annuity: same cash flows at the same interval for n periods
 Example #1: 
                           c       c 
   |-------|-------|-------|   ... |
   0       1       2       3       n
 Example #2:
           c       c      c        c
   |-------|-------|-------|   ... |
   0       1       2       3       n
 When cash flows happen at the end of each period and
      the first cash flow happens at the end of the first period
                 C                 1
   pv(annuity)= ---- * [1 -    -------- ]
                 R             (1+R)^n
   where C is the period cash flow
         R is the period discount rate
         n is the number of periods
////////////////////////////////

perpetuity due and annuity due
////////////////////////////////
For normal perpetuity or annuity, each cash flow would 
     happen at the end of each period. 

For perpetuity due or annuity due, each cash flow would 
     happen at the beginning of each period. 

There are two ways to calculate present (future) value of annuity due. 

  Method I: choose type=1 when use Excel pv() or fv() functions

          =pv(rate,nper,pmt,fv,1)           
          =fv(rate,nper,pmt,pv,1)           

  Method 2: try annuity as normal annuity
            Then type your result by (1+R)
         pv(annuity due) = pv(annuity)* (1+R)
         fv(annuity due) = fv(annuity)* (1+R)

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