libitofin 0.5.0

A ground-up Rust port of QuantLib: quantitative-finance primitives for pricing, risk, and numerical methods.
Documentation
//! The ESTR index.
//!
//! Port of `ql/indexes/ibor/estr.{hpp,cpp}`. [`Estr`] is the Euro Short-Term
//! Rate fixed by the ECB: an [`OvernightIndex`] fixing "ESTR" on the [`Target`]
//! calendar in [`EUR`](Currency::eur) with zero settlement days and an
//! [`Actual360`] day counter. It adds no behaviour over [`OvernightIndex`] - it
//! is pure configuration, so [`Estr::new`] returns a plain [`OvernightIndex`].

use crate::currency::Currency;
use crate::handle::Handle;
use crate::indexes::iborindex::OvernightIndex;
use crate::settings::Settings;
use crate::shared::Shared;
use crate::termstructures::yieldtermstructure::YieldTermStructure;
use crate::time::calendars::target::Target;
use crate::time::date::Date;
use crate::time::daycounters::actual360::Actual360;

/// The ESTR index (`ql/indexes/ibor/estr.hpp`).
///
/// A zero-sized namespace for the ESTR constructor.
pub struct Estr;

impl Estr {
    /// Builds an ESTR index over the `forwarding` curve.
    ///
    /// Mirrors the C++ `Estr::Estr(h)` constructor (`estr.cpp:27`): family name
    /// "ESTR", zero settlement days, [`EUR`](Currency::eur), the [`Target`]
    /// calendar, and an [`Actual360`] day counter.
    #[allow(clippy::new_ret_no_self)]
    pub fn new(
        forwarding: Handle<dyn YieldTermStructure>,
        settings: Shared<Settings<Date>>,
    ) -> OvernightIndex {
        OvernightIndex::new(
            "ESTR".into(),
            0,
            Currency::eur(),
            Target::new(),
            Actual360::new(),
            forwarding,
            settings,
        )
    }
}

#[cfg(test)]
mod tests {
    //! `estr.cpp` construction table, the swap oracle's index (#330).

    use super::*;
    use crate::indexes::index::Index;
    use crate::indexes::interestrateindex::InterestRateIndex;
    use crate::shared::shared;
    use crate::time::businessdayconvention::BusinessDayConvention;
    use crate::time::period::Period;
    use crate::time::timeunit::TimeUnit;

    /// `Estr::Estr` (`estr.cpp:27`): "ESTR", zero fixing days, EUR, TARGET,
    /// Actual/360, and the overnight configuration (one-day tenor, `Following`,
    /// no end-of-month) inherited from `OvernightIndex`.
    #[test]
    fn estr_matches_the_quantlib_construction_table() {
        let settings = shared(Settings::<Date>::new());
        let index = Estr::new(Handle::empty(), settings);

        assert_eq!(index.name(), "ESTRON Actual/360");
        assert_eq!(index.fixing_days(), 0);
        assert_eq!(*index.currency(), Currency::eur());
        assert_eq!(index.fixing_calendar().name(), "TARGET");
        assert_eq!(index.day_counter().name(), "Actual/360");
        assert_eq!(index.tenor(), Period::new(1, TimeUnit::Days));
        assert_eq!(
            index.business_day_convention(),
            BusinessDayConvention::Following
        );
        assert!(!index.end_of_month());
    }
}