cppcon-2022-c-20-dates-in-finance's People
cppcon-2022-c-20-dates-in-finance's Issues
Function `check_if_leap` in `module StateChecksAndEom` outputs `true` for 1973-Oct-26
Function check_if_leap
in module StateChecksAndEom
outputs true
for 1973-Oct-26.
Function check_if_leap
is missing the reassignment of variable torf
:
torf = ymd_not_leap.year().is_leap(); // false
Day Count Conventions (slide 8) has unusual formulas for end-of-month dates
The exceptions given on slide 8 for d1 or d2 when they are 30 or 31 are confusing.
// Slide 8
d1 = std::min(d1, 30);
if (d1 > 29)
d2 = std::min(d2, 30);
if (d2 == 31 && (d1 == 30 || d1 == 31))
d2 = 30;
if (d1 == 31)
d1 = 30;
After the first assignment, which sets d1 to min(d1, 30), d1 can never be 31. And yet, the final if-statement tests d1 to see if it is 31!
At first, I suspected that the final if
on slide 8 should test whether d2 (rather than d1) is 31, and set d2 to 30 when it is. But the code on slide 39 shows an implementation that conforms to the description given on slide 8. The code, however, does not include the confusing test at the end which compares d1 to 31.
// Slide 39
if (d1 == 31) d1 = 30;
if ((d2 == 31) && (d1 == 30)) d2 = 30;
I coded the following test to output all the possible combinations of d1 and d2 at the end of a month.
export module main;
import std;
struct day_count_30_360
{
// See Wikipedia:
// https://en.wikipedia.org/wiki/Day_count_convention#30/360_methods
int d1, d2;
day_count_30_360(int const d1, int const d2)
: d1{ d1 }, d2{ d2 }
{
convert_per_slide_8();
}
void convert_per_slide_8()
{
// These conversions appear in the talk at the 9:50 mark.
// https://www.youtube.com/watch?v=iVnZGqAvEEg
//
// And also on slide 8 at:
// https://github.com/QuantDevHacks/CppCon-2022-C-20-Dates-in-Finance
//
// They are close, but not the same, as what Wikipedia has for the US.
// https://en.wikipedia.org/wiki/Day_count_convention#30/360_US
d1 = std::min(d1, 30);
if (d1 > 29)
d2 = std::min(d2, 30);
if (d2 == 31 && (d1 == 30 || d1 == 31))
d2 = 30;
if (d1 == 31)
d1 = 30;
}
std::string to_string() const
{
return std::format("{}, {}", d1, d2);
}
};
void example_day_count_30_360()
{
enum : std::size_t { n_days = 4u };
std::array<int, n_days> days1{ 28, 29, 30, 31 };
std::array<int, n_days> days2{ 28, 29, 30, 31 };
std::array<std::string, n_days * n_days> d;
auto it{ d.begin() };
for (auto const& d1 : days1)
for (auto const& d2 : days2)
{
day_count_30_360 day_count{ d1, d2 };
*it++ = day_count.to_string();
}
std::cout << std::format(
"Day Count Conventions, per slide 8\n"
"\n"
"d1 d2: 28 29 30 31\n"
"28 {} {} {} {}\n"
"29 {} {} {} {}\n"
"30 {} {} {} {}\n"
"31 {} {} {} {}\n\n"
, d[0], d[1], d[2], d[3]
, d[4], d[5], d[6], d[7]
, d[8], d[9], d[10], d[11]
, d[12], d[13], d[14], d[15]
);
}
export int main()
{
example_day_count_30_360();
}
// end file: main.ixx
Here is the output. Notice that when d1 is 28 or 29, and d2 is 31, the conversions leave d2 at 31.
Day Count Conventions, per slide 8
d1 d2: 28 29 30 31
28 28, 28 28, 29 28, 30 28, 31
29 29, 28 29, 29 29, 30 29, 31
30 30, 28 30, 29 30, 30 30, 30
31 30, 28 30, 29 30, 30 30, 30
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.