Dear R forum,

Following is an customized extract of a code I am working on.

settlement = as.Date("2013-11-25")
maturity   = as.Date("2015-10-01")
coupon     = 0.066
yield      = 0.1040
basis      = 1  
frequency = 2
redemption = 100

# __________________________________________________________________

add.months = function(date, n) 
{
  nC <- seq(date, by=paste (n, "months"), length = 2)[2]
  fD <- as.Date(strftime(as.Date(date), format='%Y-%m-01'))
  C  <- (seq(fD, by=paste (n+1, "months"), length = 2)[2])-1
  if(nC>C) return(C)
  return(nC)
}

date.diff = function(end, start, basis=1) {
  if (basis != 0 && basis != 4)
  return(as.numeric(end - start))
  e <- as.POSIXlt(end)
  s <- as.POSIXlt(start)
  d <-   (360 * (e$year - s$year)) + (30 * (e$mon  - s$mon )) + (min(30, e$mday) - min(30, s$mday))
  
  return (d)
}

 cashflows   <- 0
 last.coupon <- maturity
 while (last.coupon > settlement) {
          print(last.coupon)             # I need to store these dates
 last.coupon <- add.months(last.coupon, -12/frequency)
 cashflows <- cashflows + 1
print(cashflows)                 # I need to store these cashflow numbers   
  }

The print command causes the following output

[1] "2015-10-01"
[1] 1
[1] "2015-04-01"
[1] 2
[1] "2014-10-01"
[1] 3
[1] "2014-04-01"
[1] 4

My problem is how do I store these print outputs or while the loop is getting executed, how do I save these to some data.frame say

output_dat 

cashflow_tenure    cashflow_nos

1      2015-10-01            1
2      2015-04-01            2
3      2014-10-01            3
4      2014-04-01            4

Kindly advise

With regards

Katherine
	[[alternative HTML version deleted]]


