Skip to main content

luna.financial.interest_calculator

Defines financial enumerations and utility functions for interest rate calculations in Luna's financial framework.

Enumerations:

  • 'FrequencyCode': Enum for specifying frequency codes (CD, WK, MN, YR).
  • 'InterestType': Enum for defining interest types (SIMPLE, COMPOUND).
  • 'HoldOption': Enum for options to hold annuity or term.

Utility Functions:

  • 'compute_timedelta': Computes a timedelta dictionary based on frequency code and unit.
  • 'calculate_interest_payment_rate': Calculates the interest payment rate given various parameters like interest rate, frequency unit, and day count convention.
  • 'convert_payment_period_rate_to_daily_rate': Converts a payment period rate to a daily rate based on interest type and frequency.

Includes a 'FREQUENCY_CODE_MAP' for mapping frequency codes to time units.

FrequencyCode Objects

@enum.unique
class FrequencyCode(enum.Enum)

Enum for specifying frequency codes in financial calculations.

  • CD: Day frequency
  • WK: Week frequency
  • MN: Month frequency
  • YR: Year frequency

InterestType Objects

@enum.unique
class InterestType(enum.Enum)

Enum for defining types of interest in financial calculations.

  • SIMPLE: Simple interest
  • COMPOUND: Compound interest

compute_timedelta

def compute_timedelta(frequency_code: str, frequency_unit: int) -> dict

Computes a timedelta dictionary based on the specified frequency code and unit.

calculate_interest_payment_rate

def calculate_interest_payment_rate(interest_rate: Decimal,
interest_payment_freq_unit: int,
interest_payment_freq_code: str,
day_count_convention: DayCountConvention,
interest_type: str) -> SixteenDecimal

Calculates the interest payment rate given interest rate, frequency unit, frequency code, day count convention, and interest type.

convert_payment_period_rate_to_daily_rate

def convert_payment_period_rate_to_daily_rate(
payment_period_rate: Decimal,
interest_payment_frequency_unit: int,
interest_payment_frequency_code: str,
interest_type: str,
prev_day: date | None = None,
next_day: date | None = None,
day_count_convention: DayCountConvention | None = None
) -> SixteenDecimal

Converts a payment period rate to a daily rate based on the interest type, frequency, and day count convention.