Example #1
0
    def expected_IRR(self, df,
                           actual_rate=True,
                           rate_dict={},
                           actual_as_compound=True,
                           compound_rate=0.01):
        '''
        Calculates expected IRR, i.e. the cube root of the sum of all the
        cashflows post-adjustment by risk and time. Expected IRR figure allows
        comparisons to be made between loans of the same sub-grade.

        Parameters:
        df: Training data with n features. pandas dataframe.
        actual_rate: Choice as to whether actual interest rate is to be used, or
        a custom entry. Custom interest rates are generally chosen to allow for
        comparison of loans of the same sub-grade over time. boolean
        rate_dict: Custom interest rate dictionary if actual_rate was True. Key-
        value pair of loan sub-grade and interest rate. dictionary.
        actual_as_compound: Choice as to whether actual interest rate is to be
        used for time value of money calculations. boolean.
        compound_rate: Custom interest rate if actual_as_compound was true. float.

        Returns:
        Expected IRR of each loan. list of floats.
        '''
        X = df[self.features].values
        date_range_length = self.term * 12

        if actual_rate:
            X_int_rate = df['int_rate'].values
        else:
            X_int_rate = df['sub_grade'].map(rate_dict).values

        if actual_as_compound:
            X_compound_rate = X_int_rate
        else:
            X_compound_rate = np.array([compound_rate] * X_int_rate.shape[0])

        X_sub_grade = df['sub_grade'].values

        expected_cashflows = self.get_expected_cashflows(X, 
                                                         X_int_rate,
                                                         X_compound_rate, 
                                                         X_sub_grade,
                                                         date_range_length)

        return calc_IRR(expected_cashflows, self.term)
Example #2
0
    def expected_IRR(self,
                     df,
                     actual_rate=True,
                     rate_dict={},
                     actual_as_compound=True,
                     compound_rate=0.01):
        '''
        Calculates expected IRR, i.e. the cube root of the sum of all the
        cashflows post-adjustment by risk and time. Expected IRR figure allows
        comparisons to be made between loans of the same sub-grade.

        Parameters:
        df: Training data with n features. pandas dataframe.
        actual_rate: Choice as to whether actual interest rate is to be used, or
        a custom entry. Custom interest rates are generally chosen to allow for
        comparison of loans of the same sub-grade over time. boolean
        rate_dict: Custom interest rate dictionary if actual_rate was True. Key-
        value pair of loan sub-grade and interest rate. dictionary.
        actual_as_compound: Choice as to whether actual interest rate is to be
        used for time value of money calculations. boolean.
        compound_rate: Custom interest rate if actual_as_compound was true. float.

        Returns:
        Expected IRR of each loan. list of floats.
        '''
        X = df[self.features].values
        date_range_length = self.term * 12

        if actual_rate:
            X_int_rate = df['int_rate'].values
        else:
            X_int_rate = df['sub_grade'].map(rate_dict).values

        if actual_as_compound:
            X_compound_rate = X_int_rate
        else:
            X_compound_rate = np.array([compound_rate] * X_int_rate.shape[0])

        X_sub_grade = df['sub_grade'].values

        expected_cashflows = self.get_expected_cashflows(
            X, X_int_rate, X_compound_rate, X_sub_grade, date_range_length)

        return calc_IRR(expected_cashflows, self.term)
Example #3
0
def actual_IRR(df, 
               actual_rate=True, 
               rate_dict={},
               actual_as_compound=True,
               compound_rate=0.01):
    '''
    Calculates IRR for loans that have already matured.

    Parameters:
    df: Validation data with features reflecting payments made.
    actual_rate: Choice as to whether actual interest rate is to be used, or
    a custom entry. Custom interest rates are generally chosen to allow for
    comparison of loans of the same sub-grade over time. boolean
    rate_dict: Custom interest rate dictionary if actual_rate was True. Key-
    value pair of loan sub-grade and interest rate. dictionary.
    actual_as_compound: Choice as to whether actual interest rate is to be
    used for time value of money calculations. boolean.
    compound_rate: Custom interest rate if actual_as_compound was true. float.

    Returns:
    Actual IRR of each loan. list of floats.
    '''
    term = 3
    date_range_length = term * 12

    X = df[['default_status', 'months_paid', 'residual', 'recovery']].values

    if actual_rate:
        X_int_rate = df['int_rate'].values
    else:
        X_int_rate = df['sub_grade'].map(rate_dict).values

    if actual_as_compound:
        X_compound_rate = X_int_rate
    else:
        X_compound_rate = np.array([compound_rate] * X_int_rate.shape[0])

    actual_cashflows = get_actual_cashflows(X, 
                                            X_int_rate, 
                                            X_compound_rate,
                                            date_range_length)

    return calc_IRR(actual_cashflows, term)   
Example #4
0
def actual_IRR(df,
               actual_rate=True,
               rate_dict={},
               actual_as_compound=True,
               compound_rate=0.01):
    '''
    Calculates IRR for loans that have already matured.

    Parameters:
    df: Validation data with features reflecting payments made.
    actual_rate: Choice as to whether actual interest rate is to be used, or
    a custom entry. Custom interest rates are generally chosen to allow for
    comparison of loans of the same sub-grade over time. boolean
    rate_dict: Custom interest rate dictionary if actual_rate was True. Key-
    value pair of loan sub-grade and interest rate. dictionary.
    actual_as_compound: Choice as to whether actual interest rate is to be
    used for time value of money calculations. boolean.
    compound_rate: Custom interest rate if actual_as_compound was true. float.

    Returns:
    Actual IRR of each loan. list of floats.
    '''
    term = 3
    date_range_length = term * 12

    X = df[['default_status', 'months_paid', 'residual', 'recovery']].values

    if actual_rate:
        X_int_rate = df['int_rate'].values
    else:
        X_int_rate = df['sub_grade'].map(rate_dict).values

    if actual_as_compound:
        X_compound_rate = X_int_rate
    else:
        X_compound_rate = np.array([compound_rate] * X_int_rate.shape[0])

    actual_cashflows = get_actual_cashflows(X, X_int_rate, X_compound_rate,
                                            date_range_length)

    return calc_IRR(actual_cashflows, term)