Skip to content

deposit_interest

Deposit interest rules: daily accrual and monthly settlement.

Classes:

DepositInterestAccrualRule

DepositInterestAccrualRule(
    annual_rate: Decimal = _DEFAULT_ANNUAL_RATE,
)

Generate a daily INTEREST_ACCRUAL transaction for deposit positions.

Banks pay interest on customer deposits. This rule computes a simplified daily accrual using a fixed annual rate (default 2 %) divided by 365. The resulting transaction carries ("side", "expense") metadata so the accounting service books: Dr Interest Expense / Cr Interest Payable.

Methods:

  • applies_to

    Return True unconditionally — runs every simulation day.

  • generate

    Generate a 1-day interest accrual transaction.

applies_to

applies_to(
    _instrument: Instrument,
    _position: Position,
    _context: RuleContext,
) -> bool

Return True unconditionally — runs every simulation day.

generate

generate(
    instrument: Instrument,
    position: Position,
    context: RuleContext,
) -> list[Transaction]

Generate a 1-day interest accrual transaction.

Since the simulation advances one calendar day at a time, the accrual is always exactly cost * rate / 365.

DepositInterestSettlementRule

DepositInterestSettlementRule(
    annual_rate: Decimal = _DEFAULT_ANNUAL_RATE,
)

Monthly settlement of accrued deposit interest.

Fires on the first business day of each month (when previous_date's month differs from current date's month). Generates an INTEREST_SETTLEMENT transaction with ("side", "expense") metadata so the accounting service books: Dr Interest Payable / Cr Cash.

Methods:

  • applies_to

    Return True on the 1st of each month (timing check only).

  • generate

    Settle accrued interest for the previous month.

applies_to

applies_to(
    _instrument: Instrument,
    _position: Position,
    context: RuleContext,
) -> bool

Return True on the 1st of each month (timing check only).

generate

generate(
    instrument: Instrument,
    position: Position,
    context: RuleContext,
) -> list[Transaction]

Settle accrued interest for the previous month.

Uses calendar.monthrange to determine the number of days in the previous month. For the first month, starts from acquisition_date instead of the 1st to match the accrual rule.