<commit_before>from datetime import date
from decimal import Decimal

from dateutil.relativedelta import relativedelta


class Loan(object):
    def __init__(self, principal, interest, term, term_unit='years', compounded='monthly', start_date=None):

        assert principal > 0, 'Principal must be positive value'
        assert 0 <= interest <= 1, 'Interest rate must be between zero and one'
        assert term > 0, 'Term must be a positive number'
        assert term_unit in ['days', 'months', 'years'], 'term_unit can be either  days, months, or years'
        assert compounded in ['daily', 'monthly', 'annually'], 'Compounding can occur daily, monthly, or annually'

        periods = {
            'daily': 365,
            'monthly': 12,
            'annually': 1
        }

        self.principal = Decimal(principal)
        self.interest = Decimal(interest * 100) / 100
        self.term = term
        self.term_unit = term_unit
        self.compounded = compounded
        self.start_date = date(*start_date)
        self.n_periods = periods[compounded]
        self.interest_rate_month = self.interest / 12
        self.payment_range = range(1, self.term * self.n_periods + 1)

        self._schedule = self._amortize()

    @staticmethod
    def _quantize(value):
        return Decimal(value).quantize(Decimal('0.01'))

    def schedule(self, nth_payment=None):

        if nth_payment:
            return self._schedule[nth_payment]
        else:
            return self._schedule

    @property
    def _monthly_payment(self):
        p = self.principal
        i = self.interest
        n = self.n_periods
        t = self.term
        payment = p * i / n / (1 - (1 + i / n) ** (- n * t))
        return payment

    @property
    def monthly_payment(self):
        return self._quantize(self._monthly_payment)

    def _simple_interest(self, p, i, n):
        amt = p * i * n
        return self._quantize(amt)

    @property
    def apr(self):
        new_payment = self._simple_interest(self.principal, self.interest, 1)
        apr = new_payment / self.principal
        return self._quantize(apr * 100)<commit_msg>Refactored _simple_interest function to use descriptive variable names<commit_after>from datetime import date
from decimal import Decimal

from dateutil.relativedelta import relativedelta


class Loan(object):
    def __init__(self, principal, interest, term, term_unit='years', compounded='monthly', start_date=None):

        assert principal > 0, 'Principal must be positive value'
        assert 0 <= interest <= 1, 'Interest rate must be between zero and one'
        assert term > 0, 'Term must be a positive number'
        assert term_unit in ['days', 'months', 'years'], 'term_unit can be either  days, months, or years'
        assert compounded in ['daily', 'monthly', 'annually'], 'Compounding can occur daily, monthly, or annually'

        periods = {
            'daily': 365,
            'monthly': 12,
            'annually': 1
        }

        self.principal = Decimal(principal)
        self.interest = Decimal(interest * 100) / 100
        self.term = term
        self.term_unit = term_unit
        self.compounded = compounded
        self.start_date = date(*start_date)
        self.n_periods = periods[compounded]
        self.interest_rate_month = self.interest / 12
        self.payment_range = range(1, self.term * self.n_periods + 1)

        self._schedule = self._amortize()

    @staticmethod
    def _quantize(value):
        return Decimal(value).quantize(Decimal('0.01'))

    def schedule(self, nth_payment=None):

        if nth_payment:
            return self._schedule[nth_payment]
        else:
            return self._schedule

    @property
    def _monthly_payment(self):
        p = self.principal
        i = self.interest
        n = self.n_periods
        t = self.term
        payment = p * i / n / (1 - (1 + i / n) ** (- n * t))
        return payment

    @property
    def monthly_payment(self):
        return self._quantize(self._monthly_payment)

    def _simple_interest(self, term):
        amt = self.principal * self.interest * term
        return self._quantize(amt)

    @property
    def apr(self):
        new_payment = self._simple_interest(term=1)
        apr = new_payment / self.principal
        return self._quantize(apr * 100)
{'fraction_non_alphanumeric': 0.09976958525345622, 'fraction_numerical': 0.013364055299539171, 'mean_word_length': 2.4127358490566038, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '459164', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1255, 'n_words': 358}