24#include <ql/time/asx.hpp>
25#include <ql/settings.hpp>
26#include <ql/utilities/dataparsers.hpp>
27#include <boost/algorithm/string/case_conv.hpp>
30using boost::algorithm::to_upper_copy;
43 if (!mainCycle)
return true;
60 string str1(
"0123456789");
61 string::size_type loc = str1.find(in.substr(1,1), 0);
62 if (loc == string::npos)
65 if (mainCycle) str1 =
"hmzuHMZU";
66 else str1 =
"fghjkmnquvxzFGHJKMNQUVXZ";
67 loc = str1.find(in.substr(0,1), 0);
68 return loc != string::npos;
73 date <<
" is not an ASX date");
75 std::ostringstream ASXcode;
115 QL_FAIL(
"not an ASX month (and it should have been)");
118 #if defined(QL_EXTRA_SAFETY_CHECKS)
119 QL_ENSURE(
isASXcode(ASXcode.str(),
false),
120 "the result " << ASXcode.str() <<
121 " is an invalid ASX code");
123 return ASXcode.str();
127 const Date& refDate) {
129 asxCode <<
" is not a valid ASX code");
131 Date referenceDate = (refDate !=
Date() ?
135 std::string
code = to_upper_copy(asxCode);
136 std::string ms =
code.substr(0,1);
140 else if (ms==
"H") m =
March;
141 else if (ms==
"J") m =
April;
142 else if (ms==
"K") m =
May;
143 else if (ms==
"M") m =
June;
144 else if (ms==
"N") m =
July;
145 else if (ms==
"Q") m =
August;
150 else QL_FAIL(
"invalid ASX month letter");
152 Year y = std::stoi(
code.substr(1,1));
155 if (y==0 && referenceDate.
year()<=1909) y+=10;
156 Year referenceYear = (referenceDate.
year() % 10);
157 y += referenceDate.
year() - referenceYear;
159 if (result<referenceDate)
172 Size offset = mainCycle ? 3 : 1;
173 Size skipMonths = offset-(m%offset);
174 if (skipMonths != offset || refDate.
dayOfMonth() > 14) {
175 skipMonths +=
Size(m);
176 if (skipMonths<=12) {
192 const Date& referenceDate) {
193 Date asxDate =
date(ASXcode, referenceDate);
194 return nextDate(asxDate+1, mainCycle);
205 const Date& referenceDate) {
static Date nthWeekday(Size n, Weekday w, Month m, Year y)
n-th given weekday in the given month and year
static Settings & instance()
access to the unique instance
std::size_t Size
size of a container
static Date date(const std::string &asxCode, const Date &referenceDate=Date())
static std::string nextCode(const Date &d=Date(), bool mainCycle=true)
next ASX code following the given date
static Date nextDate(const Date &d=Date(), bool mainCycle=true)
next ASX date following the given date
static bool isASXcode(const std::string &in, bool mainCycle=true)
returns whether or not the given string is an ASX code
static std::string code(const Date &asxDate)
static bool isASXdate(const Date &d, bool mainCycle=true)
returns whether or not the given date is an ASX date