Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Avhz RustQuant Frequency

From Leeroopedia
Revision as of 14:31, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Avhz_RustQuant_Frequency.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Calendar, Time_Value_of_Money
Last Updated 2026-02-07 19:00 GMT

Overview

Concrete tool for representing interest and coupon payment frequencies per year provided by the RustQuant library.

Description

The Frequency module defines the Frequency enum, which represents the number of times a cash flow (such as a coupon payment or interest accrual) occurs per year. This is a fundamental concept in financial instrument pricing, as the payment frequency directly affects present value calculations, yield computations, and accrued interest.

The enum supports 11 frequency variants, each backed by a constant integer value representing the number of payments per year:

  • Daily -- 252 payments per year (business day convention)
  • Weekly -- 52 payments per year
  • BiWeekly -- 26 payments per year
  • SemiMonthly -- 24 payments per year
  • Monthly -- 12 payments per year
  • SemiQuarterly -- 8 payments per year
  • Quarterly -- 4 payments per year
  • TriAnnually -- 3 payments per year
  • SemiAnnually -- 2 payments per year
  • Annually -- 1 payment per year
  • Zero -- 0 (no periodic payments, e.g., zero-coupon bonds)

The constants (DAILY, WEEKLY, BI_WEEKLY, etc.) are defined in the constants module and used as discriminant values for the enum variants.

The module also provides Frequency::infer_frequency(start, end), a method that attempts to determine the payment frequency from the time difference between two consecutive dates. It uses Duration comparisons with ranges to accommodate slight variations in month/quarter lengths. If the duration does not match any recognized frequency, the method panics.

The enum derives Debug, Clone, Copy, PartialEq, and Eq.

Usage

Use this when specifying the payment frequency for coupon bonds, interest rate swaps, amortizing loans, or any periodic cash-flow instrument. The infer_frequency method is useful when parsing schedule data where the frequency is not explicitly stated but can be derived from consecutive payment dates.

Code Reference

Source Location

Signature

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Frequency {
    Daily = DAILY,          // 252
    Weekly = WEEKLY,        // 52
    BiWeekly = BI_WEEKLY,   // 26
    SemiMonthly = SEMI_MONTHLY, // 24
    Monthly = MONTHLY,      // 12
    SemiQuarterly = SEMI_QUARTERLY, // 8
    Quarterly = QUARTERLY,  // 4
    TriAnnually = TRI_ANNUALLY, // 3
    SemiAnnually = SEMI_ANNUALLY, // 2
    Annually = ANNUALLY,    // 1
    Zero = 0,
}

impl Frequency {
    pub fn infer_frequency(start: Date, end: Date) -> Frequency;
}

Import

use RustQuant::time::frequency::Frequency;

I/O Contract

Inputs

Name Type Required Description
start Date Yes (for infer_frequency) The first of two consecutive payment dates
end Date Yes (for infer_frequency) The second of two consecutive payment dates

Outputs

Name Type Description
frequency Frequency The inferred or specified payment frequency

Usage Examples

use time::macros::date;
use RustQuant::time::frequency::Frequency;

// Directly specify a frequency for a semi-annual coupon bond.
let freq = Frequency::SemiAnnually;

// Infer frequency from two consecutive payment dates.
let date1 = date!(2024-01-15);
let date2 = date!(2024-07-15);
let inferred = Frequency::infer_frequency(date1, date2);
assert_eq!(inferred, Frequency::SemiAnnually);

// Infer monthly frequency.
let monthly_start = date!(2024-03-01);
let monthly_end = date!(2024-04-01);
let monthly = Frequency::infer_frequency(monthly_start, monthly_end);
assert_eq!(monthly, Frequency::Monthly);

// Infer quarterly frequency.
let q_start = date!(2024-01-01);
let q_end = date!(2024-04-01);
let quarterly = Frequency::infer_frequency(q_start, q_end);
assert_eq!(quarterly, Frequency::Quarterly);

// Use the integer discriminant value.
assert_eq!(Frequency::Annually as isize, 1);
assert_eq!(Frequency::Monthly as isize, 12);
assert_eq!(Frequency::Daily as isize, 252);

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment