Skip to content

Refactor Calendar trait and related structs to a single Calendar struct #303

Description

@avhz

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    choreTedious chore.enhancementNew feature or requestreworkRe-work, re-structure, etc. Larger project.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions