12 changed files with 555 additions and 143 deletions
@ -1,6 +1,6 @@ |
|||||
{ |
{ |
||||
"source_window_id": "", |
"source_window_id": "", |
||||
"Source": "Source", |
"Source": "Source", |
||||
"cursorPosition": "50,5", |
"cursorPosition": "50,4", |
||||
"scrollLine": "25" |
"scrollLine": "12" |
||||
} |
} |
||||
@ -1,6 +1,6 @@ |
|||||
{ |
{ |
||||
"source_window_id": "", |
"source_window_id": "", |
||||
"Source": "Source", |
"Source": "Source", |
||||
"cursorPosition": "36,2", |
"cursorPosition": "140,7", |
||||
"scrollLine": "0" |
"scrollLine": "121" |
||||
} |
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
{ |
||||
|
"id": "FEF97A26", |
||||
|
"path": "~/Projects/LoanRisk/mod_basic.R", |
||||
|
"project_path": "mod_basic.R", |
||||
|
"type": "r_source", |
||||
|
"hash": "1266759796", |
||||
|
"contents": "", |
||||
|
"dirty": false, |
||||
|
"created": 1686047786220.0, |
||||
|
"source_on_save": false, |
||||
|
"relative_order": 3, |
||||
|
"properties": { |
||||
|
"source_window_id": "", |
||||
|
"Source": "Source" |
||||
|
}, |
||||
|
"folds": "", |
||||
|
"lastKnownWriteTime": 1637757473, |
||||
|
"encoding": "UTF-8", |
||||
|
"collab_server": "", |
||||
|
"source_window": "", |
||||
|
"last_content_update": 1637757473, |
||||
|
"read_only": false, |
||||
|
"read_only_alternatives": [] |
||||
|
} |
||||
@ -0,0 +1,141 @@ |
|||||
|
# Module for a graph |
||||
|
|
||||
|
# Module to show some stats |
||||
|
basicstatUI <- function(id) { |
||||
|
ns <- NS(id) |
||||
|
fluidRow( |
||||
|
h3("No of Assets"), |
||||
|
br(), |
||||
|
p( |
||||
|
"This section shows some basic information about the portfolio." |
||||
|
), |
||||
|
plotOutput(ns("statplot")), |
||||
|
verbatimTextOutput(ns("balancetext")) |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
basicstatServer <- function(id, dt) { |
||||
|
moduleServer(id, |
||||
|
function(input, output, session) { |
||||
|
df <- reactive({ |
||||
|
dt %>% |
||||
|
ungroup() %>% |
||||
|
arrange(id, report_date) %>% |
||||
|
group_by(id) %>% |
||||
|
slice_max(report_date, n = 1) %>% |
||||
|
mutate(yr = lubridate::year(origination_date)) |
||||
|
}) |
||||
|
|
||||
|
|
||||
|
output$statplot <- renderPlot({ |
||||
|
req(!is.null(df)) |
||||
|
withProgress(message = "Plotting some graphs", |
||||
|
detail = "Won't take long", |
||||
|
value = 0, |
||||
|
{ |
||||
|
setProgress(value = 1, message = "1 of 3..") |
||||
|
|
||||
|
p1 <- |
||||
|
df() %>% |
||||
|
group_by(yr, loan_status) %>% |
||||
|
summarise(no_of_loans = n()) %>% |
||||
|
ungroup() %>% |
||||
|
ggplot(aes( |
||||
|
x = yr, |
||||
|
y = no_of_loans, |
||||
|
label = no_of_loans, |
||||
|
fill = factor( |
||||
|
loan_status, |
||||
|
levels = c("0", "1"), |
||||
|
labels = c("Good", "Bad") |
||||
|
) |
||||
|
)) + |
||||
|
geom_col(position = "dodge") + |
||||
|
geom_text(aes(y = no_of_loans + 20), position = position_dodge(width = 1)) + |
||||
|
labs(title = "No. of assets by year", |
||||
|
x = "Year", |
||||
|
y = "#") + |
||||
|
theme_bw() + |
||||
|
theme(legend.position = "none") |
||||
|
setProgress(value = 2, message = "2 of 3..") |
||||
|
|
||||
|
p2 <- |
||||
|
df() %>% |
||||
|
group_by(asset_type, loan_status) %>% |
||||
|
summarise(no_of_loans = n()) %>% |
||||
|
ungroup() %>% |
||||
|
ggplot(aes( |
||||
|
x = asset_type, |
||||
|
y = no_of_loans, |
||||
|
label = no_of_loans, |
||||
|
fill = factor( |
||||
|
loan_status, |
||||
|
levels = c("0", "1"), |
||||
|
labels = c("Good", "Bad") |
||||
|
) |
||||
|
)) + |
||||
|
geom_col(position = "dodge") + |
||||
|
geom_text(aes(y = no_of_loans + 20), position = position_dodge(width = 1)) + |
||||
|
labs(title = "No. of assets by asset type", |
||||
|
x = "Asset Type", |
||||
|
y = "#") + |
||||
|
theme_bw() + |
||||
|
theme(legend.position = "none") |
||||
|
|
||||
|
setProgress(value = 3, message = "3 of 3..") |
||||
|
|
||||
|
p3 <- |
||||
|
df() %>% |
||||
|
group_by(customer_type, loan_status) %>% |
||||
|
summarise(no_of_loans = n()) %>% |
||||
|
ungroup() %>% |
||||
|
ggplot( |
||||
|
aes( |
||||
|
x = customer_type, |
||||
|
y = no_of_loans, |
||||
|
label = no_of_loans, |
||||
|
fill = factor( |
||||
|
loan_status, |
||||
|
levels = c("0", "1"), |
||||
|
labels = c("Good", "Bad") |
||||
|
) |
||||
|
) |
||||
|
) + |
||||
|
geom_col(position = "dodge") + |
||||
|
geom_text(aes(y = no_of_loans + 20), position = position_dodge(width = 1)) + |
||||
|
labs(title = "No. of assets by customer type", |
||||
|
x = "Customer Type", |
||||
|
y = "#") + |
||||
|
theme_bw() + |
||||
|
theme(legend.position = "bottom", |
||||
|
legend.title = element_blank()) |
||||
|
|
||||
|
setProgress(value = 4, message = "Patching..") |
||||
|
|
||||
|
p4 <- p1 / (p2 | p3) |
||||
|
|
||||
|
setProgress(value = 5, message = "Done..") |
||||
|
|
||||
|
}) |
||||
|
|
||||
|
|
||||
|
p4 |
||||
|
|
||||
|
}) |
||||
|
|
||||
|
output$balancetext <- renderText({ |
||||
|
paste0( |
||||
|
"Total assets (no.): ", |
||||
|
length(unique(df()$id)) , |
||||
|
"\n", |
||||
|
"Total balance outstanding: ", |
||||
|
round(sum(df()$balance) / 1000000, 2), |
||||
|
" M" |
||||
|
|
||||
|
) |
||||
|
}) |
||||
|
|
||||
|
|
||||
|
}) |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,141 @@ |
|||||
|
# Module for a graph |
||||
|
|
||||
|
# Module to show some stats |
||||
|
basicstatUI <- function(id) { |
||||
|
ns <- NS(id) |
||||
|
fluidRow( |
||||
|
h3("No of Assets"), |
||||
|
br(), |
||||
|
p( |
||||
|
"This section shows some basic information about the portfolio." |
||||
|
), |
||||
|
plotOutput(ns("statplot")), |
||||
|
verbatimTextOutput(ns("balancetext")) |
||||
|
) |
||||
|
} |
||||
|
|
||||
|
basicstatServer <- function(id, dt) { |
||||
|
moduleServer(id, |
||||
|
function(input, output, session) { |
||||
|
df <- reactive({ |
||||
|
dt %>% |
||||
|
ungroup() %>% |
||||
|
arrange(id, report_date) %>% |
||||
|
group_by(id) %>% |
||||
|
slice_max(report_date, n = 1) %>% |
||||
|
mutate(yr = lubridate::year(origination_date)) |
||||
|
}) |
||||
|
|
||||
|
|
||||
|
output$statplot <- renderPlot({ |
||||
|
req(!is.null(df)) |
||||
|
withProgress(message = "Plotting some graphs", |
||||
|
detail = "Won't take long", |
||||
|
value = 0, |
||||
|
{ |
||||
|
setProgress(value = 1, message = "1 of 3..") |
||||
|
|
||||
|
p1 <- |
||||
|
df() %>% |
||||
|
group_by(yr, loan_status) %>% |
||||
|
summarise(no_of_loans = n()) %>% |
||||
|
ungroup() %>% |
||||
|
ggplot(aes( |
||||
|
x = yr, |
||||
|
y = no_of_loans, |
||||
|
label = no_of_loans, |
||||
|
fill = factor( |
||||
|
loan_status, |
||||
|
levels = c("0", "1"), |
||||
|
labels = c("Good", "Bad") |
||||
|
) |
||||
|
)) + |
||||
|
geom_col(position = "dodge") + |
||||
|
geom_text(aes(y = no_of_loans + 20), position = position_dodge(width = 1)) + |
||||
|
labs(title = "No. of assets by year", |
||||
|
x = "Year", |
||||
|
y = "#") + |
||||
|
theme_bw() + |
||||
|
theme(legend.position = "none") |
||||
|
setProgress(value = 2, message = "2 of 3..") |
||||
|
|
||||
|
p2 <- |
||||
|
df() %>% |
||||
|
group_by(asset_type, loan_status) %>% |
||||
|
summarise(no_of_loans = n()) %>% |
||||
|
ungroup() %>% |
||||
|
ggplot(aes( |
||||
|
x = asset_type, |
||||
|
y = no_of_loans, |
||||
|
label = no_of_loans, |
||||
|
fill = factor( |
||||
|
loan_status, |
||||
|
levels = c("0", "1"), |
||||
|
labels = c("Good", "Bad") |
||||
|
) |
||||
|
)) + |
||||
|
geom_col(position = "dodge") + |
||||
|
geom_text(aes(y = no_of_loans + 20), position = position_dodge(width = 1)) + |
||||
|
labs(title = "No. of assets by asset type", |
||||
|
x = "Asset Type", |
||||
|
y = "#") + |
||||
|
theme_bw() + |
||||
|
theme(legend.position = "none") |
||||
|
|
||||
|
setProgress(value = 3, message = "3 of 3..") |
||||
|
|
||||
|
p3 <- |
||||
|
df() %>% |
||||
|
group_by(customer_type, loan_status) %>% |
||||
|
summarise(no_of_loans = n()) %>% |
||||
|
ungroup() %>% |
||||
|
ggplot( |
||||
|
aes( |
||||
|
x = customer_type, |
||||
|
y = no_of_loans, |
||||
|
label = no_of_loans, |
||||
|
fill = factor( |
||||
|
loan_status, |
||||
|
levels = c("0", "1"), |
||||
|
labels = c("Good", "Bad") |
||||
|
) |
||||
|
) |
||||
|
) + |
||||
|
geom_col(position = "dodge") + |
||||
|
geom_text(aes(y = no_of_loans + 20), position = position_dodge(width = 1)) + |
||||
|
labs(title = "No. of assets by customer type", |
||||
|
x = "Customer Type", |
||||
|
y = "#") + |
||||
|
theme_bw() + |
||||
|
theme(legend.position = "bottom", |
||||
|
legend.title = element_blank()) |
||||
|
|
||||
|
setProgress(value = 4, message = "Patching..") |
||||
|
|
||||
|
p4 <- p1 / (p2 | p3) |
||||
|
|
||||
|
setProgress(value = 5, message = "Done..") |
||||
|
|
||||
|
}) |
||||
|
|
||||
|
|
||||
|
p4 |
||||
|
|
||||
|
}) |
||||
|
|
||||
|
output$balancetext <- renderText({ |
||||
|
paste0( |
||||
|
"Total assets (no.): ", |
||||
|
length(unique(df()$id)) , |
||||
|
"\n", |
||||
|
"Total balance outstanding: ", |
||||
|
round(sum(df()$balance) / 1000000, 2), |
||||
|
" M" |
||||
|
|
||||
|
) |
||||
|
}) |
||||
|
|
||||
|
|
||||
|
}) |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,104 @@ |
|||||
|
|
||||
|
# 2nd modal |
||||
|
modal2<-modalDialog( |
||||
|
title = "File formatting", |
||||
|
fluidRow( |
||||
|
|
||||
|
column( |
||||
|
width = 6, |
||||
|
p("Transactions file"), |
||||
|
varSelectInput("transid","Select id column", NULL), |
||||
|
varSelectInput("reportdate","Select report date column", NULL), |
||||
|
varSelectInput("origindate","Select origin date column", NULL), |
||||
|
varSelectInput("maturitydate","Select maturity date column", NULL), |
||||
|
varSelectInput("assettype","Select asset classifier column", NULL), |
||||
|
varSelectInput("customertype","Select customer classifier column", NULL), |
||||
|
varSelectInput("otherfact","Select any other classifier column", NULL, multiple = T) |
||||
|
), |
||||
|
column( |
||||
|
width = 6, |
||||
|
p("Transactions file"), |
||||
|
varSelectInput("bureauscore","Select bureau score column", NULL), |
||||
|
varSelectInput("balance","Select asset balance column", NULL), |
||||
|
varSelectInput("status","Select loan status column", NULL), |
||||
|
varSelectInput("defaultflag","Select default flag column", NULL), |
||||
|
radioButtons("dateformat","Select date format",choices = c("dmy","ymd"), selected = "ymd", inline = T), |
||||
|
p("Collateral File"), |
||||
|
varSelectInput("collateralid","Select id column", NULL), |
||||
|
varSelectInput("collateralvalue","Select Collateral value column", NULL) |
||||
|
) |
||||
|
), |
||||
|
easyClose = F, |
||||
|
size = "l", |
||||
|
footer = tagList( |
||||
|
actionButton("confirmupload", "Confirm"), |
||||
|
actionButton("closemodal2","Close") |
||||
|
) |
||||
|
) |
||||
|
|
||||
|
modal1<- modalDialog( |
||||
|
title = "Upload files", |
||||
|
fluidRow( |
||||
|
column( |
||||
|
width = 6, |
||||
|
p("Add Transaction file"), |
||||
|
fileInput("transaction", "Choose CSV File of transactions", |
||||
|
multiple = F, |
||||
|
accept = c("text/csv", |
||||
|
"text/comma-separated-values,text/plain", |
||||
|
".csv")), |
||||
|
p("Add Collateral file"), |
||||
|
fileInput("collaterals", "Choose CSV File of collaterals", |
||||
|
multiple = F, |
||||
|
accept = c("text/csv", |
||||
|
"text/comma-separated-values,text/plain", |
||||
|
".csv")), |
||||
|
checkboxInput("header", "Header", TRUE), |
||||
|
fluidRow( |
||||
|
column( |
||||
|
width = 6, |
||||
|
radioButtons("sep", "Separator", |
||||
|
choices = c(Comma = ",", |
||||
|
Semicolon = ";", |
||||
|
Tab = "\t"), |
||||
|
selected = ",") |
||||
|
), |
||||
|
column( |
||||
|
width = 6, |
||||
|
radioButtons("quote", "Quote", |
||||
|
choices = c(None = "", |
||||
|
"Double Quote" = '"', |
||||
|
"Single Quote" = "'"), |
||||
|
selected = '"') |
||||
|
) |
||||
|
) |
||||
|
), |
||||
|
column( |
||||
|
width = 6, |
||||
|
fluidRow( |
||||
|
tags$div( |
||||
|
"Following columns are required in the transaction file", |
||||
|
tags$ul( |
||||
|
tags$li("A unique identifier of asset (id)"), |
||||
|
tags$li("Date on which last report was generated. The last reporting date of all the assets must be same."), |
||||
|
tags$li("Origination Date"), |
||||
|
tags$li("Maturity Date"), |
||||
|
tags$li("Default flag i.e. whether previously defaulted"), |
||||
|
tags$li("Bureau/internal credit score"), |
||||
|
tags$li("Current loan status (1 is bad and 0 is good)"), |
||||
|
tags$li("Asset classification"), |
||||
|
tags$li("Customer classification"), |
||||
|
tags$li("Asset balance") |
||||
|
), |
||||
|
"The collateral file should contain present value of the collateral/possible price of sales of the asset/sales of hypothecated asset etc." |
||||
|
) |
||||
|
) |
||||
|
) |
||||
|
), |
||||
|
easyClose = F, |
||||
|
size = "l", |
||||
|
footer = tagList( |
||||
|
actionButton("uploadfiles", "Proceed"), |
||||
|
actionButton("closemodal1","Close") |
||||
|
) |
||||
|
) |
||||
Loading…
Reference in new issue