[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 1a941f1 05/10: Add an inchoate GPT reimplemen
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 1a941f1 05/10: Add an inchoate GPT reimplementation |
Date: |
Sun, 18 Apr 2021 18:21:03 -0400 (EDT) |
branch: master
commit 1a941f1e0e641076458c95d9f3356bb5e8ede38c
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Add an inchoate GPT reimplementation
---
Makefile.am | 14 ++++++++
gpt_test.cpp | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
irc7702.cpp | 26 ++++++++++++++
irc7702.hpp | 31 +++++++++++++++++
objects.make | 11 ++++++
5 files changed, 192 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index e3513ff..417fb81 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -118,6 +118,7 @@ TESTS = \
getopt_test \
global_settings_test \
gpt_cf_triad_test \
+ gpt_test \
handle_exceptions_test \
i7702_test \
ieee754_test \
@@ -426,6 +427,7 @@ liblmi_la_SOURCES = \
cso_table.cpp \
financial.cpp \
fund_data.cpp \
+ gpt_commutation_functions.cpp \
gpt_input.cpp \
gpt_server.cpp \
gpt_specamt.cpp \
@@ -443,6 +445,7 @@ liblmi_la_SOURCES = \
ihs_irc7702a.cpp \
ihs_mortal.cpp \
ihs_server7702.cpp \
+ irc7702.cpp \
irc7702_tables.cpp \
lingo.cpp \
lmi.cpp \
@@ -747,6 +750,16 @@ gpt_cf_triad_test_LDADD = \
libtest_common.la \
$(BOOST_LIBS)
+gpt_test_SOURCES = \
+ commutation_functions.cpp \
+ cso_table.cpp \
+ gpt_commutation_functions.cpp \
+ gpt_test.cpp \
+ irc7702.cpp
+gpt_test_CXXFLAGS = $(AM_CXXFLAGS)
+gpt_test_LDADD = \
+ libtest_common.la
+
handle_exceptions_test_LDADD = \
libtest_common.la
@@ -1195,6 +1208,7 @@ noinst_HEADERS = \
input_sequence_parser.hpp \
interest_rates.hpp \
interpolate_string.hpp \
+ irc7702.hpp \
irc7702_tables.hpp \
istream_to_string.hpp \
ledger.hpp \
diff --git a/gpt_test.cpp b/gpt_test.cpp
new file mode 100644
index 0000000..541a04e
--- /dev/null
+++ b/gpt_test.cpp
@@ -0,0 +1,110 @@
+// Internal Revenue Code section 7702 guideline premium--unit test.
+//
+// Copyright (C) 2021 Gregory W. Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// https://savannah.nongnu.org/projects/lmi
+// email: <gchicares@sbcglobal.net>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+#include "pchfile.hpp"
+
+#include "irc7702.hpp"
+
+#include "assert_lmi.hpp"
+#include "cso_table.hpp"
+#include "et_vector.hpp"
+#include "math_functions.hpp"
+#include "ssize_lmi.hpp"
+#include "test_tools.hpp"
+
+namespace
+{
+/// Convert annual mortality rates to monthly.
+///
+/// 7702 !! Duplicated in 'gpt_cf_triad_test.cpp': factor out.
+
+std::vector<double> a_to_m(std::vector<double> const& q_a)
+{
+ std::vector<double> q_m(lmi::ssize(q_a));
+ assign(q_m, apply_binary(coi_rate_from_q<double>(), q_a, 1.0 / 11.0));
+ return q_m;
+}
+
+/// 1980 CSO Ultimate ANB Male Unismoke
+
+std::vector<double> sample_q(int age)
+{
+ static std::vector<double> const q_a = cso_table
+ (mce_1980cso
+ ,oe_orthodox
+ ,oe_age_nearest_birthday_ties_younger
+ ,mce_male
+ ,mce_unismoke
+ );
+ LMI_ASSERT(0 <= age && age < lmi::ssize(q_a));
+ static std::vector<double> const q_m(a_to_m(q_a));
+ return std::vector<double>(q_m.begin() + age, q_m.end());
+}
+} // Unnamed namespace.
+
+class gpt_test
+{
+ public:
+ static void test()
+ {
+ test_guideline_negative();
+ }
+
+ private:
+ static void test_guideline_negative();
+};
+
+/// Validate a guideline-negative example.
+///
+/// Example similar to SOA textbook, page 101, Table V-4.
+/// cum
+/// cum rejected prems
+/// GLP GLP GSP forceout pmt paid
+/// ------------------------------------------------------------------------
+/// initialization 2035.42 50885.50 23883.74 50000.00
+/// GPT adjustment -1804.87 ... -5067.35
+/// march of time 49080.63
+/// decr prems paid ...
+/// forceout 919.37 49080.63
+///
+/// See 'commutation_functions_test.cpp' for validated premium calculations.
+///
+/// GLP adjustment: // OL (textbook) vs. UL commfns: A + B - C
+/// OL: 2035.42 + 3903.42 - 7743.71 = -1804.87
+/// UL: 2074.40 + 3980.10 - 7900.49 = -1845.99 (each rounded)
+/// UL: 2074.402884 + 3980.10414 - 7900.495224 = -1845.9882
+///
+/// GSP similarly:
+/// OL: 23883.74 + 29453.12 - 58404.21 = -5067.35
+/// UL: 24486.32 + 30225.88 - 59979.47 = -5267.27 (each rounded)
+/// UL: 24486.3207 + 30225.8816 - 59979.4650 = -5267.2627
+
+void gpt_test::test_guideline_negative()
+{
+ std::cout << "watch this space" << std::endl;
+ LMI_ASSERT(100 == lmi::ssize(sample_q(0)));
+}
+
+int test_main(int, char*[])
+{
+ gpt_test::test();
+ return EXIT_SUCCESS;
+}
diff --git a/irc7702.cpp b/irc7702.cpp
new file mode 100644
index 0000000..a5cd5e5
--- /dev/null
+++ b/irc7702.cpp
@@ -0,0 +1,26 @@
+// Internal Revenue Code section 7702
+//
+// Copyright (C) 2021 Gregory W. Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// https://savannah.nongnu.org/projects/lmi
+// email: <gchicares@sbcglobal.net>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+#include "pchfile.hpp"
+
+#include "irc7702.hpp"
+
+// implementation of class irc7702
diff --git a/irc7702.hpp b/irc7702.hpp
new file mode 100644
index 0000000..d63fe82
--- /dev/null
+++ b/irc7702.hpp
@@ -0,0 +1,31 @@
+// Internal Revenue Code section 7702
+//
+// Copyright (C) 2021 Gregory W. Chicares.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software Foundation,
+// Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+//
+// https://savannah.nongnu.org/projects/lmi
+// email: <gchicares@sbcglobal.net>
+// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA
+
+#ifndef irc7702_hpp
+#define irc7702_hpp
+
+#include "config.hpp"
+
+class irc7702
+{
+};
+
+#endif // irc7702_hpp
diff --git a/objects.make b/objects.make
index 37601d6..4bae197 100644
--- a/objects.make
+++ b/objects.make
@@ -277,6 +277,7 @@ lmi_common_objects := \
cso_table.o \
financial.o \
fund_data.o \
+ gpt_commutation_functions.o \
gpt_input.o \
gpt_server.o \
gpt_specamt.o \
@@ -294,6 +295,7 @@ lmi_common_objects := \
ihs_irc7702a.o \
ihs_mortal.o \
ihs_server7702.o \
+ irc7702.o \
irc7702_tables.o \
lingo.o \
lmi.o \
@@ -430,6 +432,7 @@ unit_test_targets := \
getopt_test \
global_settings_test \
gpt_cf_triad_test \
+ gpt_test \
handle_exceptions_test \
i7702_test \
ieee754_test \
@@ -682,6 +685,14 @@ gpt_cf_triad_test$(EXEEXT): \
path_utility.o \
timer.o \
+gpt_test$(EXEEXT): \
+ $(common_test_objects) \
+ commutation_functions.o \
+ cso_table.o \
+ gpt_commutation_functions.o \
+ gpt_test.o \
+ irc7702.o \
+
handle_exceptions_test$(EXEEXT): \
$(common_test_objects) \
handle_exceptions_test.o \
- [lmi-commits] [lmi] master updated (191757a -> 8be683c), Greg Chicares, 2021/04/18
- [lmi-commits] [lmi] master 947c1d1 01/10: Upgrade gcc-{8, 9} dialect from c++17 to c++2a, Greg Chicares, 2021/04/18
- [lmi-commits] [lmi] master 325848d 07/10: Change order of struct members, Greg Chicares, 2021/04/18
- [lmi-commits] [lmi] master 14575f1 06/10: Favor designated initializers, Greg Chicares, 2021/04/18
- [lmi-commits] [lmi] master b2d963e 08/10: Rename some struct members, Greg Chicares, 2021/04/18
- [lmi-commits] [lmi] master 1a941f1 05/10: Add an inchoate GPT reimplementation,
Greg Chicares <=
- [lmi-commits] [lmi] master 34b010b 02/10: Rename a unit test, Greg Chicares, 2021/04/18
- [lmi-commits] [lmi] master 3e46bba 03/10: Rename a unit-test class, Greg Chicares, 2021/04/18
- [lmi-commits] [lmi] master 8be683c 10/10: Record speed measurements, Greg Chicares, 2021/04/18
- [lmi-commits] [lmi] master 10299f3 09/10: Augment a parameter object, Greg Chicares, 2021/04/18
- [lmi-commits] [lmi] master 1665c7a 04/10: Follow the rule of zero, Greg Chicares, 2021/04/18