Trait quantmath::dates::calendar::Calendar[][src]

pub trait Calendar: Serialize + TypeId + Sync + Send + Debug {
    fn name(&self) -> &str;
fn is_holiday(&self, date: Date) -> bool;
fn count_business_days(
        &self,
        from: Date,
        from_fraction: f64,
        to: Date,
        to_fraction: f64
    ) -> f64;
fn step(&self, from: Date, step: i32, slip_forward: bool) -> Date;
fn standard_basis(&self) -> f64; fn day_weight(&self, date: Date) -> f64 { ... }
fn step_partial(&self, from: Date, step: f64, slip_forward: bool) -> Date { ... }
fn year_fraction(&self, from: DateDayFraction, to: DateDayFraction) -> f64 { ... } }

Calendars define when business holidays are scheduled. They are used for business day volatility, settlement calculations, and the roll-out of schedules for exotic products and swaps.

Required Methods

The name of this calendar. Conventionally, the name is a three-letter upper-case string such as "TGT" or "NYS", though this is not required.

Is the given date a holiday or weekend? The opposite of a business day.

Count business days between the two given dates. The dates at the ends of the range may optionally be partly included in the count, by setting a fraction between zero and one.

Step forward/backward by the given number of business days. The result is always a business day. If today is a business day, a zero step means staying where we are. If today is not a business day, we slip off to the nearest business day in the direction specified by the slip_forward flag. If the step is non-zero, the overall move is equivalent to a zero step followed by the given number of one-step moves.

Note that sadly we cannot use the sign of the step argument to specify the slip_forward flag, because the step may be zero. Effectively, we want to distinguish between +0 and -0. The function works correctly when the sign of step is different from the slip_forward flag, but the results are rather weird. Generally you want slip_forward = true if step > 0 and vice versa.

Returns the basis normally used for business day volatility. Roughly speaking this is the expected number of business days in a year, but conventionalised. It is 365 for EveryDayCalendar and 252 for a pure business day calendar.

Provided Methods

If the given date is a holiday, what weight should it receive? Returns 1.0 for a business day, 0.0 for a pure holiday with no weight, and potentially a number somewhere between for anything else.

The default implementation returns zero for a holiday and one for any other day.

Specialised function where day-counts may be fractional, for example in volatility surfaces. For most calendars, the step is truncated towards zero and an integer number of steps is taken.

Calculate the year-fraction between two date-times, given the count of business days and the standard basis.

Implementors