knitr::opts_chunk$set(echo = FALSE, message=FALSE, warning = FALSE)
library(LendingClub)
suppressPackageStartupMessages(library(dplyr))
library(knitr)
suppressMessages(library(ggplot2))


LC_CRED<- lc_MakeCredential(params$investorID, params$APIkey)

holdings<- LendingClub::lc_DetailedNotesOwned()$content

summarydata<-  lc_AccountSummary()$content

atRisk<- {
  at_risk_status<- c("Late (16-30 days)",
                     "Late (31-120 days)")
  x<- holdings[holdings$loanStatus %in% at_risk_status,]    
  sum(as.numeric(x$noteAmount)- as.numeric(x$principalReceived))
  }

Account KPIs

stats<- c("Account Total",
          "Available Cash",
          "All Time Interest Received",
          "Principal at Risk",
          "At Risk Ratio")

vals<- as.numeric(c(summarydata$accountTotal,
                    summarydata$availableCash,
                    summarydata$receivedInterest,
                    atRisk,
                    round(as.numeric(
                        atRisk / (summarydata$outstandingPrincipal+ summarydata$infundingBalance)*100),2)
                    ))

summtable<- data.frame(stats, vals)

kable(summtable, 
      col.names= NULL,
      align = c("l","r"), 
      format.args = list(big.mark = ','),
      padding = 2) 

Portfolio Summary

x<-lapply(split(holdings, f= holdings$portfolioName), summary)
x<- c(x, list( summary (holdings)))
names(x)[length(x)]<- "Total"

for (i in 1:length(x)){
  names(x[[i]])[2] <- names(x[i])
  }


y<- Reduce(function(...) merge(..., by= 'col_labs',  all.x=TRUE), x)
colnames(y)[1]<- ""

z<- y[c(1,4,3,8,6,5,7,9,2), ]
kable(z,
  row.names= FALSE,
  format.args = list(big.mark = ','),
  padding = 2) 

Principal Distribution by Grade

h<- ggplot(holdings %>% 
               filter(currentPaymentStatus != "ChargedOff") %>%
               mutate(majGrade = strtrim(grade, 1)) %>%
               group_by(majGrade) %>% 
               summarize(total = round(sum(as.numeric(principalPending))),0))
h<- h + aes(x= majGrade, y= total, label=total)
h<- h + geom_col()
h<- h + theme_classic()
h<- h + labs(x= "Grade",
             y= "Outstanding Principal")
h<- h + geom_text(vjust=0, nudge_y=.7, size=3.5)
h

Payback Ratio {.tabset}

Chart

dat<-holdings %>%
  mutate(CFRatio= round((as.numeric(paymentsReceived) - as.numeric(noteAmount)) /as.numeric(noteAmount)*100,2)+100 +1,
         orderDate= as.Date(orderDate))

dat$simpleStatus <- case_when(dat$loanStatus == "Charged Off" ~ "Dead",
                              dat$loanStatus == "Current" ~"Performing",
                              dat$loanStatus == "Fully Paid" ~ "Complete",
                              dat$loanStatus == "In Grace Period" ~ "Performing",
                              dat$loanStatus == "In Review" ~ "Performing",
                              dat$loanStatus == "Issued" ~ "Performing",
                              dat$loanStatus == "Late (16-30 days)" ~ "Late",
                              dat$loanStatus == "Late (31-120 days)" ~ "Late")

ThreeYear<- as.Date(Sys.time())-(365*3)
FiveYear<- as.Date(Sys.time()-(365*5))

status_colors<-c("Performing"="#377eb8", #blue
                 "Late"= "#e41a1c", #red
                 "Dead"="#707070", #gray
                 "Complete"= "#4daf4a") #gree

g<- ggplot(dat)
g<- g + aes(x= as.Date(Sys.time())-orderDate, 
            y= CFRatio, 
            group= portfolioName,
            fill= simpleStatus)
g<- g + geom_point(aes(colour=simpleStatus), size=1)
g<- g + scale_colour_manual(values=status_colors)
g<- g + scale_x_continuous()
g<- g + facet_wrap(~portfolioName, ncol=2)
g<- g + theme_classic()
g<- g + labs(x= "Age in Days",
             y= "Payback Ratio")
g<- g + geom_hline(yintercept = 100, linetype="dashed")
g<- g + theme(legend.position="none",
              panel.border  = element_rect(colour = "black", fill=NA))
g

Late Notes

LateNotes<- dat %>%
    filter(simpleStatus=="Late") %>%
    mutate(LastPayment= as.Date(lastPaymentDate),
           DaysLate=as.Date(Sys.time())- LastPayment) %>%
    select(portfolioName, grade, purpose, CFRatio, principalPending, LastPayment, DaysLate)


kable(LateNotes, 
      col.names= c("Portfolio",
                   "Grade",
                   "Purpose",
                   "Payback Ratio",
                   "Outstanding Principal",
                   "Last Payment",
                   "Days Since Payment"),
      align = c("l","l","l","r","r","l","l"), 
      format.args = list(big.mark = ','),
      padding = 2) 


Principal At Risk includes the outstanding principal of notes greater than 15 days late.

At Risk Ratio is the Principal at Risk as a percentage of the outstanding principal amount.

Wgt Int Rate interest rate weighted by the outstanding principal.

Payback Ratio measures the difference between cash invested in a note and the total payments received. The payments include both interest and principal. All notes start at zero and will increase as payments are made. A note with a ratio greater than 100 indicates that more cash was received than was initially invested. Notes will start at the bottom left of the chart and trend towards the upper right corner as they mature.

LendingClub



kuhnrl30/LendingClub documentation built on Jan. 1, 2020, 6:02 p.m.