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.

An adapter that declares BrokerCaps::has_calendar_sessions also fills each open day's session hours (TradingDay::regular_ and extended_), from which a live loop takes the market phase (strategy::stated_session_phase). is_trading_day and the searches ignore the hours.

Definition at line 72 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 164 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 97 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 130 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 146 of file calendar.hpp.

Member Data Documentation

◆ country_

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

The market this calendar is for.

Definition at line 74 of file calendar.hpp.

Referenced by algotradelib::kis::KisClient::adopt_calendar(), algotradelib::alpaca::AlpacaBlockingClient::calendar(), and main().

◆ days_

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

◆ 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 78 of file calendar.hpp.

Referenced by algotradelib::alpaca::AlpacaBlockingClient::calendar(), main(), and algotradelib::network::FileCalendarCache::publish().

◆ 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 88 of file calendar.hpp.

Referenced by algotradelib::alpaca::AlpacaBlockingClient::calendar(), and algotradelib::strategy::stated_session_phase().


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