pub struct UsExchangeCalendar { /* private fields */ }
Expand description
Calendar specific to US stock exchanges
Implementations§
Source§impl UsExchangeCalendar
impl UsExchangeCalendar
Sourcepub fn with_default_range(populate: bool) -> UsExchangeCalendar
pub fn with_default_range(populate: bool) -> UsExchangeCalendar
NYSE holiday calendar as of 2022
create a new US Exchange calendar with default rules, populate the
calendar with default range (2000-2050) if populate
is set to true
Examples found in repository?
More examples
examples/show_year.rs (line 17)
5fn main() {
6 let args: Vec<String> = args().collect();
7 let len = args.len();
8 if len < 2 {
9 panic!("Usage: {} first [last]", args[0]);
10 }
11 let first: i32 = (&args[1]).parse().unwrap();
12 let last: i32 = if len > 2 {
13 (&args[2]).parse().unwrap()
14 } else {
15 first
16 };
17 let mut usec = UsExchangeCalendar::with_default_range(false);
18 let usec = usec.populate_cal(Some(first), Some(last));
19 let cal = usec.get_cal();
20 let mut first_date = NaiveDate::from_ymd_opt(first, 1, 1).unwrap();
21 let last_date = NaiveDate::from_ymd_opt(last, 12, 31).unwrap();
22 let mut holidays: Vec<NaiveDate> = Vec::new();
23 let mut halfdays: Vec<NaiveDate> = Vec::new();
24 while first_date < last_date {
25 if cal.is_holiday(first_date) {
26 holidays.push(first_date);
27 } else if cal.is_half_holiday(first_date) {
28 halfdays.push(first_date);
29 }
30 first_date = first_date + Duration::days(1);
31 }
32 println!("holidays: {:?}", holidays);
33 println!("half days: {:?}", halfdays);
34}
Sourcepub fn add_holiday_rule(&mut self, holiday: Holiday) -> &mut Self
pub fn add_holiday_rule(&mut self, holiday: Holiday) -> &mut Self
add an ad-hoc holiday rule to the rule list
Sourcepub fn populate_cal(
&mut self,
start: Option<i32>,
end: Option<i32>,
) -> &mut Self
pub fn populate_cal( &mut self, start: Option<i32>, end: Option<i32>, ) -> &mut Self
populate calendar for given start
and end
years (inclusively, defaults to 2000 and 2050 if None,
None are given)
Examples found in repository?
More examples
examples/show_year.rs (line 18)
5fn main() {
6 let args: Vec<String> = args().collect();
7 let len = args.len();
8 if len < 2 {
9 panic!("Usage: {} first [last]", args[0]);
10 }
11 let first: i32 = (&args[1]).parse().unwrap();
12 let last: i32 = if len > 2 {
13 (&args[2]).parse().unwrap()
14 } else {
15 first
16 };
17 let mut usec = UsExchangeCalendar::with_default_range(false);
18 let usec = usec.populate_cal(Some(first), Some(last));
19 let cal = usec.get_cal();
20 let mut first_date = NaiveDate::from_ymd_opt(first, 1, 1).unwrap();
21 let last_date = NaiveDate::from_ymd_opt(last, 12, 31).unwrap();
22 let mut holidays: Vec<NaiveDate> = Vec::new();
23 let mut halfdays: Vec<NaiveDate> = Vec::new();
24 while first_date < last_date {
25 if cal.is_holiday(first_date) {
26 holidays.push(first_date);
27 } else if cal.is_half_holiday(first_date) {
28 halfdays.push(first_date);
29 }
30 first_date = first_date + Duration::days(1);
31 }
32 println!("holidays: {:?}", holidays);
33 println!("half days: {:?}", halfdays);
34}
Sourcepub fn get_cal(&self) -> Calendar
pub fn get_cal(&self) -> Calendar
Examples found in repository?
More examples
examples/show_year.rs (line 19)
5fn main() {
6 let args: Vec<String> = args().collect();
7 let len = args.len();
8 if len < 2 {
9 panic!("Usage: {} first [last]", args[0]);
10 }
11 let first: i32 = (&args[1]).parse().unwrap();
12 let last: i32 = if len > 2 {
13 (&args[2]).parse().unwrap()
14 } else {
15 first
16 };
17 let mut usec = UsExchangeCalendar::with_default_range(false);
18 let usec = usec.populate_cal(Some(first), Some(last));
19 let cal = usec.get_cal();
20 let mut first_date = NaiveDate::from_ymd_opt(first, 1, 1).unwrap();
21 let last_date = NaiveDate::from_ymd_opt(last, 12, 31).unwrap();
22 let mut holidays: Vec<NaiveDate> = Vec::new();
23 let mut halfdays: Vec<NaiveDate> = Vec::new();
24 while first_date < last_date {
25 if cal.is_holiday(first_date) {
26 holidays.push(first_date);
27 } else if cal.is_half_holiday(first_date) {
28 halfdays.push(first_date);
29 }
30 first_date = first_date + Duration::days(1);
31 }
32 println!("holidays: {:?}", holidays);
33 println!("half days: {:?}", halfdays);
34}
Trait Implementations§
Source§impl Clone for UsExchangeCalendar
impl Clone for UsExchangeCalendar
Source§fn clone(&self) -> UsExchangeCalendar
fn clone(&self) -> UsExchangeCalendar
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for UsExchangeCalendar
impl RefUnwindSafe for UsExchangeCalendar
impl Send for UsExchangeCalendar
impl Sync for UsExchangeCalendar
impl Unpin for UsExchangeCalendar
impl UnwindSafe for UsExchangeCalendar
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more