RustQuant icon indicating copy to clipboard operation
RustQuant copied to clipboard

Refactor `Calendar` trait and related structs to a single `Calendar` struct

Open avhz opened this issue 4 months ago • 0 comments

Instead of having a calendar trait and associated structs, I think a single struct would be more simple.

enum Market {
    // Market Identifier Codes (MIC)
    XNYS,
    XNAS,
    XASX,
    XCBO,
    ...
    // Special case calendars
    Weekends,
    None,
}

struct Calendar(Market);

impl Calendar {
    fn new(market: Market) -> Self {
        Self { market }
    }

    fn is_business_day(&self, date: Date) -> bool {
        !self.is_weekend(date) && !self.is_holiday(date)
    }

    fn is_holiday(&self, date: Date) -> bool {
        match self.0 {
            Market::XNYS => is_holiday_impl_xnys(date),
            Market::XNAS => is_holiday_impl_xnas(date),
            Market::XASX => is_holiday_impl_xasx(date),
            Market::XCBO => is_holiday_impl_xcbo(date),
            ...
        }
    }
}

This will make it easier to pass around (as opposed to using traits), and in particular to write Python bindings.

avhz avatar Aug 30 '25 11:08 avhz