use crate::currency::Currency;
use crate::errors::QlResult;
use crate::handle::Handle;
use crate::indexes::ibor::libor::Libor;
use crate::indexes::iborindex::IborIndex;
use crate::settings::Settings;
use crate::shared::Shared;
use crate::termstructures::yieldtermstructure::YieldTermStructure;
use crate::time::calendars::unitedkingdom::{Market as UkMarket, UnitedKingdom};
use crate::time::date::Date;
use crate::time::daycounters::actual365fixed::Actual365Fixed;
use crate::time::period::Period;
pub struct GbpLibor;
impl GbpLibor {
#[allow(clippy::new_ret_no_self)]
pub fn new(
tenor: Period,
forwarding: Handle<dyn YieldTermStructure>,
settings: Shared<Settings<Date>>,
) -> QlResult<IborIndex> {
Libor::new(
"GBPLibor".into(),
tenor,
0,
Currency::gbp(),
UnitedKingdom::new(UkMarket::Exchange),
Actual365Fixed::new(),
forwarding,
settings,
)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::indexes::index::Index;
use crate::indexes::interestrateindex::InterestRateIndex;
use crate::shared::shared;
use crate::time::businessdayconvention::BusinessDayConvention;
use crate::time::date::Month;
use crate::time::timeunit::TimeUnit;
fn gbp_libor_3m(settings: Shared<Settings<Date>>) -> IborIndex {
GbpLibor::new(Period::new(3, TimeUnit::Months), Handle::empty(), settings)
.expect("a 3M GBPLibor tenor is valid")
}
#[test]
fn gbp_libor_carries_the_ice_configuration() {
let index = gbp_libor_3m(shared(Settings::<Date>::new()));
assert_eq!(index.name(), "GBPLibor3M Actual/365 (Fixed)");
assert_eq!(index.fixing_days(), 0);
assert_eq!(index.currency(), &Currency::gbp());
assert_eq!(index.day_counter().name(), "Actual/365 (Fixed)");
assert_eq!(index.fixing_calendar().name(), "London stock exchange");
assert_eq!(
index.maturity_calendar().name(),
"JoinHolidays(London stock exchange, London stock exchange)"
);
assert_eq!(
index.business_day_convention(),
BusinessDayConvention::ModifiedFollowing
);
assert!(index.end_of_month());
}
#[test]
fn value_date_equals_the_fixing_date() {
let index = gbp_libor_3m(shared(Settings::<Date>::new()));
let fixing = Date::new(11, Month::August, 2020);
assert_eq!(index.value_date(fixing).unwrap(), fixing);
}
#[test]
fn maturity_date_stays_on_the_uk_calendar() {
let index = gbp_libor_3m(shared(Settings::<Date>::new()));
let v = Date::new(11, Month::August, 2020);
let maturity = index.maturity_date(v).unwrap();
let uk = UnitedKingdom::new(UkMarket::Exchange);
let expected = uk.advance_by_period(
v,
index.tenor(),
index.business_day_convention(),
index.end_of_month(),
);
assert_eq!(maturity, expected);
assert_eq!(maturity, Date::new(11, Month::November, 2020));
let clone = index.clone_with(Handle::empty());
assert_eq!(clone.maturity_date(v).unwrap(), maturity);
}
}