Class TradingCalendar
Defined in File trading_calendar.hpp
Class Documentation
-
class TradingCalendar
Utility class for determining trading days, holidays, and related calendar computations.
Public Functions
-
TradingCalendar()
Default constructor.
-
inline void set_holidays(const std::vector<boost::gregorian::date> &holidays)
Sets the holiday calendar and sorts it.
- Parameters:
holidays – List of dates to set as holidays.
Public Static Functions
-
static inline bool next_to_non_trade_day(const boost::gregorian::date &day)
Checks if a given day is adjacent to a non-trading day.
- Parameters:
day – The date to check.
- Returns:
True if the previous or next day is a non-trade day.
-
static inline bool non_trade_day(const boost::gregorian::date &day)
Checks whether a given day is a non-trade day (weekend or holiday).
- Parameters:
day – The date to check.
- Returns:
True if the date is a non-trade day.
-
static inline bool trade_day(const boost::gregorian::date &day)
Checks if a given day is a valid trade day.
- Parameters:
day – The date to check.
- Returns:
True if the date is not a weekend or holiday.
-
static inline bool half_trade_day(const boost::gregorian::date &day)
Checks if a date is a half trading day.
- Parameters:
day – The date to check.
- Returns:
True if the date is a half trading day.
-
static inline bool holiday(const boost::gregorian::date &day)
Checks whether a date is a recognized holiday.
- Parameters:
day – The date to check.
- Returns:
True if the date is a holiday.
-
static inline bool weekend(const boost::gregorian::date &day)
Checks if a date is a weekend (Saturday or Sunday).
- Parameters:
day – The date to check.
- Returns:
True if it’s Saturday or Sunday.
-
static inline int non_trade_days(const boost::gregorian::date &start, const boost::gregorian::date &end)
Computes the number of non-trading days between two dates.
- Parameters:
start – Start date (inclusive).
end – End date (exclusive).
- Returns:
The number of non-trading days.
-
static int trade_days(const boost::gregorian::date &first_day, const boost::gregorian::date &last_day)
Computes the number of trading days between two dates.
- Parameters:
first_day – Start date (inclusive).
last_day – End date (exclusive).
- Returns:
Number of trading days.
-
static inline int calendar_days(const boost::gregorian::date &start, const boost::gregorian::date &end)
Computes the total number of calendar days between two dates.
- Parameters:
start – Start date (inclusive).
end – End date (exclusive).
- Returns:
Total number of calendar days.
-
static std::vector<boost::gregorian::date> trade_dates(const boost::gregorian::date &start, const boost::gregorian::date &end)
Retrieves a list of all trade dates between two dates.
- Parameters:
start – Start date (inclusive).
end – End date (exclusive).
- Returns:
Vector of trade dates.
-
static boost::gregorian::date previous_trade_date(const boost::gregorian::date &d)
Gets the last trading day before a given date.
- Parameters:
d – The reference date.
- Returns:
The previous trading day.
-
static boost::posix_time::ptime previous_trade_day_cutoff(const boost::gregorian::date &d)
Gets the market cutoff time on the previous trading day before the given date.
- Parameters:
d – The reference date.
- Returns:
Time of market close on the previous trade day.
-
static boost::posix_time::ptime effective_dividend_time_for_early_exercise(const boost::gregorian::date &d)
Returns the effective dividend time relevant for early exercise logic.
- Parameters:
d – The reference date.
- Returns:
The timestamp representing the dividend time.
-
static int pre_holidays(const boost::gregorian::date &start, const boost::gregorian::date &end)
Counts the number of days immediately before holidays in a range.
- Parameters:
start – Start date (inclusive).
end – End date (exclusive).
- Returns:
Number of pre-holiday days.
-
static int post_holidays(const boost::gregorian::date &start, const boost::gregorian::date &end)
Counts the number of days immediately after holidays in a range.
- Parameters:
start – Start date (inclusive).
end – End date (exclusive).
- Returns:
Number of post-holiday days.
-
static int day_of_week_days(const boost::gregorian::date &start, const boost::gregorian::date &end, int day_of_week)
Counts the number of specific weekday occurrences between two dates.
- Parameters:
start – Start date (inclusive).
end – End date (exclusive).
day_of_week – 0 = Sunday, …, 6 = Saturday.
- Returns:
Number of days matching the specified weekday.
-
static inline std::vector<boost::gregorian::date> get_holidays()
Returns the list of holiday dates.
- Returns:
Vector of holiday dates.
-
static inline int trade_days_to_calendar_days(const boost::gregorian::date &day, int trade_offset)
Converts a trade day offset into calendar day offset.
- Parameters:
day – Starting date.
trade_offset – Number of trade days to move.
- Returns:
Number of calendar days between start and resulting trade day.
-
static boost::gregorian::date trade_day_offset(const boost::gregorian::date &day, int trade_offset)
Returns the trade day that is a given number of trade days from the specified day.
- Parameters:
day – The reference date.
trade_offset – The number of trade days to offset.
- Returns:
The resulting trade date.
-
TradingCalendar()