Struct UsExchangeCalendar

Source
pub struct UsExchangeCalendar { /* private fields */ }
Expand description

Calendar specific to US stock exchanges

Implementations§

Source§

impl UsExchangeCalendar

Source

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?
examples/simple.rs (line 3)
2fn main() {
3    let mut sc = UsExchangeCalendar::with_default_range(false);
4    sc.populate_cal(Some(2021), Some(2024));
5    let c = sc.get_cal();
6    println!("{:?}", c);
7}
More examples
Hide additional 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}
Source

pub fn add_holiday_rule(&mut self, holiday: Holiday) -> &mut Self

add an ad-hoc holiday rule to the rule list

Source

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?
examples/simple.rs (line 4)
2fn main() {
3    let mut sc = UsExchangeCalendar::with_default_range(false);
4    sc.populate_cal(Some(2021), Some(2024));
5    let c = sc.get_cal();
6    println!("{:?}", c);
7}
More examples
Hide additional 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}
Source

pub fn get_cal(&self) -> Calendar

Examples found in repository?
examples/simple.rs (line 5)
2fn main() {
3    let mut sc = UsExchangeCalendar::with_default_range(false);
4    sc.populate_cal(Some(2021), Some(2024));
5    let c = sc.get_cal();
6    println!("{:?}", c);
7}
More examples
Hide additional 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

Source§

fn clone(&self) -> UsExchangeCalendar

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UsExchangeCalendar

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.