pub trait Scheduling {
Show 17 methods
// Required methods
fn try_udate(&self, udate: &NaiveDateTime) -> Result<NaiveDateTime, PyErr>;
fn next(&self, date: &NaiveDateTime) -> NaiveDateTime;
fn previous(&self, date: &NaiveDateTime) -> NaiveDateTime;
fn try_uregular(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> Result<Vec<NaiveDateTime>, PyErr>;
// Provided methods
fn try_unext(&self, udate: &NaiveDateTime) -> Result<NaiveDateTime, PyErr> { ... }
fn try_uprevious(
&self,
udate: &NaiveDateTime,
) -> Result<NaiveDateTime, PyErr> { ... }
fn try_uregular_from_unext(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> Result<Vec<NaiveDateTime>, PyErr> { ... }
fn is_regular_period(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool { ... }
fn is_short_front_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool { ... }
fn is_long_front_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool { ... }
fn is_short_back_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool { ... }
fn is_long_back_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool { ... }
fn is_front_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool { ... }
fn is_back_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool { ... }
fn try_infer_ufront_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
short: bool,
) -> Result<Option<NaiveDateTime>, PyErr> { ... }
fn try_infer_uback_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
short: bool,
) -> Result<Option<NaiveDateTime>, PyErr> { ... }
fn periods_per_annum(&self) -> f64 { ... }
}
Expand description
Used to define periods of financial instrument schedules.
Required Methods§
Sourcefn try_udate(&self, udate: &NaiveDateTime) -> Result<NaiveDateTime, PyErr>
fn try_udate(&self, udate: &NaiveDateTime) -> Result<NaiveDateTime, PyErr>
Validate if an unadjusted date aligns with the scheduling object.
Sourcefn next(&self, date: &NaiveDateTime) -> NaiveDateTime
fn next(&self, date: &NaiveDateTime) -> NaiveDateTime
Calculate the next unadjusted scheduling period date from a given date
.
The input date
is not checked to align with the scheduling object. This can lead to
to optically unexpected results (see examples). If a check on the date is required use the
try_unext
method instead.
§Examples
let f = Frequency::Months{number:1, roll: Some(RollDay::Day(1))};
let result = f.next(&ndt(2000, 1, 31));
assert_eq!(ndt(2000, 2, 1), result);
assert!(f.try_unext(&ndt(2000, 1, 31)).is_err());
Sourcefn previous(&self, date: &NaiveDateTime) -> NaiveDateTime
fn previous(&self, date: &NaiveDateTime) -> NaiveDateTime
Calculate the previous unadjusted scheduling period date from a given date
.
The input date
is not checked to align with the scheduling object. This can lead to
to optically unexpected results (see examples). If a check on the date is required use the
try_uprevious
method instead.
§Examples
let f = Frequency::Months{number:1, roll: Some(RollDay::Day(31))};
let result = f.previous(&ndt(2000, 2, 1));
assert_eq!(ndt(2000, 1, 31), result);
assert!(f.try_uprevious(&ndt(2000, 2, 1)).is_err());
Sourcefn try_uregular(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> Result<Vec<NaiveDateTime>, PyErr>
fn try_uregular( &self, ueffective: &NaiveDateTime, utermination: &NaiveDateTime, ) -> Result<Vec<NaiveDateTime>, PyErr>
Return a vector of unadjusted regular scheduling dates if it exists.
§Notes
In many standard cases this will simply use the provided method
try_uregular_from_unext
, but allows for custom
implementations when required.
Provided Methods§
Sourcefn try_unext(&self, udate: &NaiveDateTime) -> Result<NaiveDateTime, PyErr>
fn try_unext(&self, udate: &NaiveDateTime) -> Result<NaiveDateTime, PyErr>
Calculate the next unadjusted scheduling period date from an unadjusted base date.
§Notes
This method first checks that the udate
is valid and returns an error if not.
Sourcefn try_uprevious(&self, udate: &NaiveDateTime) -> Result<NaiveDateTime, PyErr>
fn try_uprevious(&self, udate: &NaiveDateTime) -> Result<NaiveDateTime, PyErr>
Calculate the previous unadjusted scheduling period date from an unadjusted base date.
§Notes
This method first checks that the udate
is valid and returns an error if not.
Sourcefn try_uregular_from_unext(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> Result<Vec<NaiveDateTime>, PyErr>
fn try_uregular_from_unext( &self, ueffective: &NaiveDateTime, utermination: &NaiveDateTime, ) -> Result<Vec<NaiveDateTime>, PyErr>
Sourcefn is_regular_period(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool
fn is_regular_period( &self, ueffective: &NaiveDateTime, utermination: &NaiveDateTime, ) -> bool
Check if two given unadjusted dates define a regular period under a scheduling object.
§Notes
This method tests if try_uregular
has exactly two dates.
Sourcefn is_short_front_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool
fn is_short_front_stub( &self, ueffective: &NaiveDateTime, utermination: &NaiveDateTime, ) -> bool
Check if two given unadjusted dates define a short front stub period under a scheduling object.
§Notes
This method tests if try_uprevious
is before ueffective
.
If dates are undeterminable this returns false
.
Sourcefn is_long_front_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool
fn is_long_front_stub( &self, ueffective: &NaiveDateTime, utermination: &NaiveDateTime, ) -> bool
Check if two given unadjusted dates define a long front stub period under a scheduling object.
Sourcefn is_short_back_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool
fn is_short_back_stub( &self, ueffective: &NaiveDateTime, utermination: &NaiveDateTime, ) -> bool
Check if two given unadjusted dates define a short back stub period under a scheduling object.
§Notes
This method tests if Scheduling::try_unext is after utermination
.
If dates are undeterminable this returns false
.
Sourcefn is_long_back_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool
fn is_long_back_stub( &self, ueffective: &NaiveDateTime, utermination: &NaiveDateTime, ) -> bool
Check if two given unadjusted dates define a long back stub period under a scheduling object.
Sourcefn is_front_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool
fn is_front_stub( &self, ueffective: &NaiveDateTime, utermination: &NaiveDateTime, ) -> bool
Check if two given unadjusted dates define any front stub under a scheduling object.
§Notes
If dates are undeterminable this returns false
.
Sourcefn is_back_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
) -> bool
fn is_back_stub( &self, ueffective: &NaiveDateTime, utermination: &NaiveDateTime, ) -> bool
Check if two given unadjusted dates define any back stub under a scheduling object.
§Notes
If dates are undeterminable this returns false
.
Sourcefn try_infer_ufront_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
short: bool,
) -> Result<Option<NaiveDateTime>, PyErr>
fn try_infer_ufront_stub( &self, ueffective: &NaiveDateTime, utermination: &NaiveDateTime, short: bool, ) -> Result<Option<NaiveDateTime>, PyErr>
Infer an unadjusted front stub date from unadjusted irregular schedule dates.
§Notes
If a regular schedule is defined then the result will hold None
as no stub is required.
If a stub can be inferred then it will be returned as Some(date)
.
An errors will be returned if the dates are too close together to infer stubs and do not
define a regular period.
Sourcefn try_infer_uback_stub(
&self,
ueffective: &NaiveDateTime,
utermination: &NaiveDateTime,
short: bool,
) -> Result<Option<NaiveDateTime>, PyErr>
fn try_infer_uback_stub( &self, ueffective: &NaiveDateTime, utermination: &NaiveDateTime, short: bool, ) -> Result<Option<NaiveDateTime>, PyErr>
Infer an unadjusted back stub date from unadjusted irregular schedule dates.
§Notes
If a regular schedule is defined then the result will hold None
as no stub is required.
If a stub can be inferred then it will be returned as Some(date)
.
An errors will be returned if the dates are too close together to infer stubs and do not
define a regular period.
Sourcefn periods_per_annum(&self) -> f64
fn periods_per_annum(&self) -> f64
Get the approximate number of coupons per annum.
This will average the number coupons paid in 50 year period.