[R] modifying list in loop

Glenn Schultz glennmschultz at me.com
Sat Apr 1 19:05:10 CEST 2017


All,

I am working on structuring a FHLMC credit risk transfer deal.  I have the deal modeled as a list of lists as shown below.  I would like to fill in the CashFlows.  The first step is simply to assign the current balance to the first position in CashFlow$BeginBal.  I am using the below function to update the values in the list.  The function works properly but the list values are not updated.  Any help is appreciated.

Best,
Glenn

BeginBal <- function(deal,period){
numtranches = length(deal)
tranches = seq(numtranches,1,-1)
for(tranche in seq_along(tranches)){
cashflow <- NULL
if(period == 1) {cashflow <- 
c(deal[[tranche]]$CashFlow$BeginBal, deal[[tranche]]$CurrBal)
} else {
cashflow <- c(deal[[tranche]]$CashFlow$BeginBal, 
deal[[tranche]]$CashFlow$EndingBal[[period -1]])}
deal[[tranche]]$CashFlow$BeginBal <- cashflow
print(deal[[tranche]]$CashFlow$BeginBal)
}
}

for(period in 1:1){
BeginBal(Deal, period)
}

structure(list(OC = structure(list(Tranche = "OC", Cusip = NULL, 
Coupon = 0L, Index = NULL, Margin = NULL, OrigBal = 25905603, 
CurrBal = 25905603, CashFlow = structure(list(BeginBal = list(), 
WriteDown = list(), WriteUp = list(), EndBal = list()), .Names = c("BeginBal", 
"WriteDown", "WriteUp", "EndBal"))), .Names = c("Tranche", 
"Cusip", "Coupon", "Index", "Margin", "OrigBal", "CurrBal", "CashFlow"
)), B2H = structure(list(Tranche = "B2H", Cusip = NULL, Coupon = 10.7794, 
Index = "LIBOR1M", Margin = 10, OrigBal = 152827059, CurrBal = 152827059, 
IssueDate = "02-01-2017", DatedDate = "02-01-2017", LastPmtDate = "02-01-2017", 
NextPmtDate = "02-25-2017", MaturityDate = "07-25-2029", 
CashFlow = structure(list(BeginBal = list(), Interest = list(), 
WriteDown = list(), WriteUp = list(), SeniorReduction = list(), 
SubReduction = list(), EndBal = list()), .Names = c("BeginBal", 
"Interest", "WriteDown", "WriteUp", "SeniorReduction", "SubReduction", 
"EndBal"))), .Names = c("Tranche", "Cusip", "Coupon", "Index", 
"Margin", "OrigBal", "CurrBal", "IssueDate", "DatedDate", "LastPmtDate", 
"NextPmtDate", "MaturityDate", "CashFlow")), B2 = structure(list(
Tranche = "B2", Cusip = NULL, Coupon = 10.77944, Index = "LIBOR1M", 
Margin = 10, OrigBal = 1.7e+07, CurrBal = 1.7e+07, IssueDate = "02-01-2017", 
DatedDate = "02-01-2017", LastPmtDate = "02-01-2017", NextPmtDate = "02-25-2017", 
MaturityDate = "07-25-2029", CashFlow = structure(list(BeginBal = list(), 
Interest = list(), WriteDown = list(), WriteUp = list(), 
SeniorReduction = list(), SubReduction = list(), EndBal = list()), .Names = c("BeginBal", 
"Interest", "WriteDown", "WriteUp", "SeniorReduction", "SubReduction", 
"EndBal"))), .Names = c("Tranche", "Cusip", "Coupon", "Index", 
"Margin", "OrigBal", "CurrBal", "IssueDate", "DatedDate", "LastPmtDate", 
"NextPmtDate", "MaturityDate", "CashFlow")), B1H = structure(list(
Tranche = "B1H", Cusip = NULL, Coupon = 5.72944, Index = "LIBOR1M", 
Margin = 4.95, OrigBal = 49827059, CurrBal = 49827059, IssueDate = "02-01-2017", 
DatedDate = "02-01-2017", LastPmtDate = "02-01-2017", NextPmtDate = "02-25-2017", 
MaturityDate = "07-25-2029", CashFlow = structure(list(BeginBal = list(), 
Interest = list(), WriteDown = list(), WriteUp = list(), 
SeniorReduction = list(), SubReduction = list(), EndBal = list()), .Names = c("BeginBal", 
"Interest", "WriteDown", "WriteUp", "SeniorReduction", "SubReduction", 
"EndBal"))), .Names = c("Tranche", "Cusip", "Coupon", "Index", 
"Margin", "OrigBal", "CurrBal", "IssueDate", "DatedDate", "LastPmtDate", 
"NextPmtDate", "MaturityDate", "CashFlow")), B1 = structure(list(
Tranche = "B1", Cusip = NULL, Coupon = 5.72944, Index = "LIBOR1M", 
Margin = 4.95, OrigBal = 1.2e+08, CurrBal = 1.2e+08, IssueDate = "02-01-2017", 
DatedDate = "02-01-2017", LastPmtDate = "02-01-2017", NextPmtDate = "02-25-2017", 
MaturityDate = "07-25-2029", CashFlow = structure(list(BeginBal = list(), 
Interest = list(), WriteDown = list(), WriteUp = list(), 
SeniorReduction = list(), SubReduction = list(), EndBal = list()), .Names = c("BeginBal", 
"Interest", "WriteDown", "WriteUp", "SeniorReduction", "SubReduction", 
"EndBal"))), .Names = c("Tranche", "Cusip", "Coupon", "Index", 
"Margin", "OrigBal", "CurrBal", "IssueDate", "DatedDate", "LastPmtDate", 
"NextPmtDate", "MaturityDate", "CashFlow")), M2H = structure(list(
Tranche = "M2H", Cusip = NULL, Coupon = 4.02944, Index = "LIBOR1M", 
Margin = 3.25, OrigBal = 151463884, CurrBal = 151463884, 
IssueDate = "02-01-2017", DatedDate = "02-01-2017", LastPmtDate = "02-01-2017", 
NextPmtDate = "02-25-2017", MaturityDate = "07-25-2029", 
CashFlow = structure(list(BeginBal = list(), Interest = list(), 
WriteDown = list(), WriteUp = list(), SeniorReduction = list(), 
SubReduction = list(), EndBal = list()), .Names = c("BeginBal", 
"Interest", "WriteDown", "WriteUp", "SeniorReduction", "SubReduction", 
"EndBal"))), .Names = c("Tranche", "Cusip", "Coupon", "Index", 
"Margin", "OrigBal", "CurrBal", "IssueDate", "DatedDate", "LastPmtDate", 
"NextPmtDate", "MaturityDate", "CashFlow")), M2 = structure(list(
Tranche = "M2", Cusip = NULL, Coupon = 4.02944, Index = "LIBOR1M", 
Margin = 3.25, OrigBal = 3.75e+08, CurrBal = 3.75e+08, IssueDate = "02-01-2017", 
DatedDate = "02-01-2017", LastPmtDate = "02-01-2017", NextPmtDate = "02-25-2017", 
MaturityDate = "07-25-2029", CashFlow = structure(list(BeginBal = list(), 
Interest = list(), WriteDown = list(), WriteUp = list(), 
SeniorReduction = list(), SubReduction = list(), EndBal = list()), .Names = c("BeginBal", 
"Interest", "WriteDown", "WriteUp", "SeniorReduction", "SubReduction", 
"EndBal"))), .Names = c("Tranche", "Cusip", "Coupon", "Index", 
"Margin", "OrigBal", "CurrBal", "IssueDate", "DatedDate", "LastPmtDate", 
"NextPmtDate", "MaturityDate", "CashFlow")), M1H = structure(list(
Tranche = "M1H", Cusip = NULL, Coupon = 1.97944, Index = "LIBOR1M", 
Margin = 1.2, OrigBal = 117584943, CurrBal = 117584943, IssueDate = "02-01-2017", 
DatedDate = "02-01-2017", LastPmtDate = "02-01-2017", NextPmtDate = "02-25-2017", 
MaturityDate = "07-25-2029", CashFlow = structure(list(BeginBal = list(), 
Interest = list(), WriteDown = list(), WriteUp = list(), 
SeniorReduction = list(), SubReduction = list(), EndBal = list()), .Names = c("BeginBal", 
"Interest", "WriteDown", "WriteUp", "SeniorReduction", "SubReduction", 
"EndBal"))), .Names = c("Tranche", "Cusip", "Coupon", "Index", 
"Margin", "OrigBal", "CurrBal", "IssueDate", "DatedDate", "LastPmtDate", 
"NextPmtDate", "MaturityDate", "CashFlow")), M1 = structure(list(
Tranche = "M1", Cusip = NULL, Coupon = 1.97944, Index = "LIBOR1M", 
Margin = 1.2, OrigBal = 2.9e+08, CurrBal = 2.9e+08, IssueDate = "02-01-2017", 
DatedDate = "02-01-2017", LastPmtDate = "02-01-2017", NextPmtDate = "02-25-2017", 
MaturityDate = "07-25-2029", CashFlow = structure(list(BeginBal = list(), 
Interest = list(), WriteDown = list(), WriteUp = list(), 
SeniorReduction = list(), SubReduction = list(), EndBal = list()), .Names = c("BeginBal", 
"Interest", "WriteDown", "WriteUp", "SeniorReduction", "SubReduction", 
"EndBal"))), .Names = c("Tranche", "Cusip", "Coupon", "Index", 
"Margin", "OrigBal", "CurrBal", "IssueDate", "DatedDate", "LastPmtDate", 
"NextPmtDate", "MaturityDate", "CashFlow")), A1H = structure(list(
Tranche = "AH", Cusip = NULL, Coupon = 0L, Index = "LIBOR1M", 
Margin = 1.2, OrigBal = 32691709407, CurrBal = 32691709407, 
IssueDate = "02-01-2017", DatedDate = "02-01-2017", LastPmtDate = "02-01-2017", 
NextPmtDate = "02-25-2017", MaturityDate = "07-25-2029", 
CashFlow = structure(list(BeginBal = list(), Interest = list(), 
WriteDown = list(), WriteUp = list(), SeniorReduction = list(), 
SubReduction = list(), EndBal = list()), .Names = c("BeginBal", 
"Interest", "WriteDown", "WriteUp", "SeniorReduction", "SubReduction", 
"EndBal"))), .Names = c("Tranche", "Cusip", "Coupon", "Index", 
"Margin", "OrigBal", "CurrBal", "IssueDate", "DatedDate", "LastPmtDate", 
"NextPmtDate", "MaturityDate", "CashFlow"))), .Names = c("OC", 
"B2H", "B2", "B1H", "B1", "M2H", "M2", "M1H", "M1", "A1H"))



BeginBal <- function(deal,period){
numtranches = length(deal)
tranches = seq(numtranches,1,-1)
for(tranche in seq_along(tranches)){
cashflow <- NULL
if(period == 1) {cashflow <- 
c(deal[[tranche]]$CashFlow$BeginBal, deal[[tranche]]$CurrBal)
} else {
cashflow <- c(deal[[tranche]]$CashFlow$BeginBal, 
deal[[tranche]]$CashFlow$EndingBal[[period -1]])}
deal[[tranche]]$CashFlow$BeginBal <- cashflow
print(deal[[tranche]]$CashFlow$BeginBal)
}
}


More information about the R-help mailing list