algotradelib 0.0.0.9000
C++ header-only library for algorithmic trading
Loading...
Searching...
No Matches
algotradelib::TradingCalendar Struct Reference

The trading days a broker reported for one market, ascending by date. More...

#include <algotradelib/src/core/calendar.hpp>

Public Member Functions

std::optional< bool > is_trading_day (const Date &date) const
 Looks up whether the market opens on a date.
std::optional< Date > next_trading_day (const Date &date) const
 Finds the first trading day after a date.
std::optional< Date > previous_trading_day (const Date &date) const
 Finds the last trading day before a date.
std::optional< std::pair< Date, Date > > covered () const
 Returns the first and last dates the calendar covers.

Public Attributes

Country country_ {Country::KR}
 The market this calendar is for.
std::vector< TradingDay > days_
 The days the broker reported, ascending. A date outside them is uncovered, not closed.
std::chrono::system_clock::time_point received_at_
 When the calendar was received, on this machine's clock.
std::size_t unreadable_days_ {0}
 How many rows from the broker had a date that could not be read.

Detailed Description

The trading days a broker reported for one market, ascending by date.

A calendar covers a finite set of dates. is_trading_day tells "closed" apart from "not covered": a date the broker did not report, or one whose row could not be read, has no answer rather than a guessed one. The searches return reported days only, and do not say whether unreported dates are open.

Keep days_ ascending if you fill it yourself.

Intraday session hours are not part of this type, and the library does not expose them yet (Toss publishes them).

Definition at line 44 of file calendar.hpp.

Member Function Documentation

◆ covered()

std::optional< std::pair< Date, Date > > algotradelib::TradingCalendar::covered ( ) const
inline

Returns the first and last dates the calendar covers.

Returns
The pair (first, last), or std::nullopt if the calendar is empty.

Definition at line 119 of file calendar.hpp.

◆ is_trading_day()

std::optional< bool > algotradelib::TradingCalendar::is_trading_day ( const Date & date) const
inline

Looks up whether the market opens on a date.

Parameters
dateThe date to look up.
Returns
true if the market opens, false if it is closed, or std::nullopt if the calendar does not cover date.

Definition at line 69 of file calendar.hpp.

◆ next_trading_day()

std::optional< Date > algotradelib::TradingCalendar::next_trading_day ( const Date & date) const
inline

Finds the first trading day after a date.

Parameters
dateThe date to search from; it is not itself a candidate.
Returns
The first open day after date, or std::nullopt if none is covered.
See also
unreadable_days_ for a day this search may skip.

Definition at line 85 of file calendar.hpp.

◆ previous_trading_day()

std::optional< Date > algotradelib::TradingCalendar::previous_trading_day ( const Date & date) const
inline

Finds the last trading day before a date.

Parameters
dateThe date to search from; it is not itself a candidate.
Returns
The last open day before date, or std::nullopt if none is covered.
See also
unreadable_days_ for a day this search may skip.

Definition at line 101 of file calendar.hpp.

Member Data Documentation

◆ country_

Country algotradelib::TradingCalendar::country_ {Country::KR}

The market this calendar is for.

Definition at line 46 of file calendar.hpp.

Referenced by main().

◆ days_

std::vector<TradingDay> algotradelib::TradingCalendar::days_

The days the broker reported, ascending. A date outside them is uncovered, not closed.

Definition at line 48 of file calendar.hpp.

Referenced by covered(), is_trading_day(), main(), next_trading_day(), and previous_trading_day().

◆ received_at_

std::chrono::system_clock::time_point algotradelib::TradingCalendar::received_at_

When the calendar was received, on this machine's clock.

Definition at line 50 of file calendar.hpp.

Referenced by main().

◆ unreadable_days_

std::size_t algotradelib::TradingCalendar::unreadable_days_ {0}

How many rows from the broker had a date that could not be read.

Each such row is dropped, and the day it described is uncovered: is_trading_day returns nothing for it.

Warning
The dropped day can fall inside the covered span. When this count is nonzero, next_trading_day and previous_trading_day may skip over a trading day.

Definition at line 60 of file calendar.hpp.


The documentation for this struct was generated from the following file: