Skip to contents

This function bridges loans from hook data by merging loan attributes and computing various statistics.

Usage

ffp_hfid_bridge_from_hook(
  df_loans_pn_nd,
  df_loans_hooks,
  svr_lender_var = "forinfm4",
  bl_filter_bridge_asinpaper = TRUE,
  bl_filter_bridge_grvgr0 = TRUE,
  it_ll_grv_min = -1,
  bl_filter_loan_duration_a = FALSE,
  bl_filter_loan_duration_b = FALSE,
  bl_filter_lender_type = FALSE,
  bl_filter_bridge_informal = FALSE,
  bl_filter_loan_size = FALSE,
  bl_filter_loan_duration_more = FALSE,
  verbose = FALSE,
  verbose_detail = FALSE,
  it_verbose_detail_nrow = 100
)

Arguments

df_loans_pn_nd

Data frame containing loan attributes for main loans

df_loans_hooks

Data frame containing hook data

svr_lender_var

Name of the variable indicating lender type in the loan attributes data frame

bl_filter_bridge_asinpaper

Boolean filter base paper bridge definition, loan B starts and ends before and after loan a ends, Loan C starts and ends before and after loan b ends. Loan C must start after loan A ends. Loan B can be 1 month in length.

bl_filter_bridge_grvgr0

Logical indicating whether to filter out non-bridge loans based on GRV > 0 condition

it_ll_grv_min

Minimum value of GRV for a loan to be considered a bridge loan

bl_filter_loan_duration_a

Logical indicating whether to filter out non-bridge loans based on duration condition a

bl_filter_loan_duration_b

Logical indicating whether to filter out non-bridge loans based on duration condition b

bl_filter_lender_type

Logical indicating whether to filter out non-bridge loans based on lender type condition

bl_filter_bridge_informal

Logical indicating whether to filter out non-bridge loans based on informal bridge condition

bl_filter_loan_size

Logical indicating whether to filter out non-bridge loans based on loan size condition

bl_filter_loan_duration_more

Logical indicating whether to filter out non-bridge loans based on additional duration condition

verbose

Logical indicating whether to print verbose output

verbose_detail

Logical indicating whether to print detailed verbose output

it_verbose_detail_nrow

Number of rows to print for detailed verbose output

Value

Data frame containing bridged loans with merged attributes and computed statistics

See also

Used by vignette(s) ffv_invest_loan_bridge. Related issue(s): PrjThaiHFID-#32.

Author

Fan Wang, http://fanwangecon.github.io

Examples

df_loans_pn_nd <- PrjThaiHFID::tstm_loans_pn_nd
ls_return <- ffp_hfid_hook_pairs(df_loans_pn_nd)
df_loans_hooks <- ls_return$tstm_loans_hooks
ffp_hfid_bridge_from_hook(df_loans_pn_nd, df_loans_hooks)
#> $tstm_loans_bridges_1t2
#> # A tibble: 47,754 × 25
#>    hhid_Num hh_loan_id_nd_1t2 hh_loan_id_nd_paired…¹ loan_start_1t2 loan_end_1t2
#>       <int>             <int>                  <int>          <dbl>        <dbl>
#>  1     1003                 1                      2              1            8
#>  2     1003                 1                      4              1            8
#>  3     1003                 2                      5              1           10
#>  4     1003                 2                      6              1           10
#>  5     1003                 2                      7              1           10
#>  6     1003                 3                      4              2            3
#>  7     1003                 5                      7              9           26
#>  8     1003                 5                      9              9           26
#>  9     1003                 5                     10              9           26
#> 10     1003                 5                     12              9           26
#> # ℹ 47,744 more rows
#> # ℹ abbreviated name: ¹​hh_loan_id_nd_paired_1t2
#> # ℹ 20 more variables: loan_start_paired_1t2 <dbl>, loan_end_paired_1t2 <dbl>,
#> #   forinfm4_1t2 <chr>, forinfm4_paired_1t2 <chr>, loan_principal_1t2 <dbl>,
#> #   loan_principal_paired_1t2 <dbl>, loan_principal_last_1t2 <dbl>,
#> #   loan_principal_last_paired_1t2 <dbl>, loan_interest_monthly_1t2 <dbl>,
#> #   loan_interest_monthly_paired_1t2 <dbl>, ll_g12l <dbl>, ll_g12m <dbl>, …
#> 
#> $tstm_loans_bridges
#> # A tibble: 94,907 × 41
#>    hhid_Num hh_loan_id_nd_1t2 hh_loan_id_nd_paired_1t2 hh_loan_id_nd_paired_2t3
#>       <int>             <int>                    <int>                    <int>
#>  1     1003                 2                        5                       10
#>  2     1003                 2                        5                       12
#>  3     1003                 2                        6                        7
#>  4     1003                 2                        6                        9
#>  5     1003                 2                        6                       10
#>  6     1003                 2                        6                       12
#>  7     1003                 2                        7                       10
#>  8     1003                 2                        7                       12
#>  9     1003                 8                        9                       12
#> 10     1003                 8                       11                       12
#> # ℹ 94,897 more rows
#> # ℹ 37 more variables: loan_start_1t2 <dbl>, loan_end_1t2 <dbl>,
#> #   loan_start_paired_1t2 <dbl>, loan_end_paired_1t2 <dbl>,
#> #   loan_start_paired_2t3 <dbl>, loan_end_paired_2t3 <dbl>, forinfm4_1t2 <chr>,
#> #   forinfm4_paired_1t2 <chr>, forinfm4_paired_2t3 <chr>,
#> #   loan_principal_1t2 <dbl>, loan_principal_paired_1t2 <dbl>,
#> #   loan_principal_paired_2t3 <dbl>, loan_principal_last_1t2 <dbl>, …
#>