lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 5dbf2e3 06/25: Validate class i7702


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 5dbf2e3 06/25: Validate class i7702
Date: Wed, 24 Feb 2021 19:00:51 -0500 (EST)

branch: master
commit 5dbf2e35d82dc727817763874d0b4e50516227c1
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Validate class i7702
    
    Assertions ensure that the copied-and-adapted code does the same thing
    as the now-obsolete original, which can therefore be removed soon.
    
    The defective i7702::gross_ value is preserved for the nonce.
---
 ihs_basicval.cpp     |  9 +++++++++
 irc7702_interest.cpp | 47 +++++++++++++++++++++++++++++------------------
 irc7702_interest.hpp |  9 ++++++++-
 3 files changed, 46 insertions(+), 19 deletions(-)

diff --git a/ihs_basicval.cpp b/ihs_basicval.cpp
index 11604d1..64fe867 100644
--- a/ihs_basicval.cpp
+++ b/ihs_basicval.cpp
@@ -41,6 +41,7 @@
 #include "ihs_irc7702a.hpp"
 #include "input.hpp"
 #include "interest_rates.hpp"
+#include "irc7702_interest.hpp"         // class i7702
 #include "lingo.hpp"
 #include "loads.hpp"
 #include "math_functions.hpp"
@@ -298,6 +299,8 @@ void BasicValues::Init()
     SetMaxSurvivalDur();
     set_partial_mortality();
 
+    // 7702 !! should become a member, to be shared with 7702A:
+//  i7702_ = i7702(database(), *StratifiedCharges_);
     Init7702();
     Init7702A();
 }
@@ -431,6 +434,8 @@ void BasicValues::Init7702()
         || mce_variable_loan_rate != yare_input_.LoanRateType
         );
 
+    // 7702 !! local with '_' suffix: should become a member
+    i7702 i7702_(database(), *StratifiedCharges_);
 #if 1 // 7702 !! moved to class i7702
     // Monthly guar net int for 7702 is
     //   greater of {iglp(), igsp()} and annual guar int rate
@@ -495,6 +500,10 @@ void BasicValues::Init7702()
 
     database().query_into(DB_NaarDiscount, Mly7702ig);
 #endif // 1 // 7702 !! moved to class i7702
+    LMI_ASSERT(i7702_.gross  () == Mly7702ig);
+    LMI_ASSERT(i7702_.net_glp() == Mly7702iGlp);
+    LMI_ASSERT(i7702_.net_gsp() == Mly7702iGsp);
+    LMI_ASSERT(i7702_.spread () == SpreadFor7702_);
 
     // TODO ?? We should avoid reading the rate file again; but
     // the GPT server doesn't initialize a MortalityRates object
diff --git a/irc7702_interest.cpp b/irc7702_interest.cpp
index 2a13673..212883e 100644
--- a/irc7702_interest.cpp
+++ b/irc7702_interest.cpp
@@ -25,7 +25,10 @@
 
 #include "contains.hpp"                 // 7702 !! obsolescent
 #include "database.hpp"
+#include "et_vector.hpp"
 #include "global_settings.hpp"          // 7702 !! obsolescent
+#include "math_functions.hpp"
+#include "miscellany.hpp"               // each_equal()
 #include "stratified_charges.hpp"
 
 /// Statutory interest rate for 7702 and 7702A (except GSP).
@@ -58,10 +61,9 @@ i7702::i7702
     :database_   {database}
     ,stratified_ {stratified}
 {
-#if 0
-    SpreadFor7702_.assign
-        (Length
-        ,StratifiedCharges_->minimum_tiered_spread_for_7702()
+    spread_.assign
+        (database_.length()
+        ,stratified_.minimum_tiered_spread_for_7702()
         );
 
     // Monthly guar net int for 7702 is
@@ -73,25 +75,25 @@ i7702::i7702
     // GPT calculations in the 7702 class.
 
     std::vector<double> statutory7702i;
-    database().query_into(DB_AnnInterestRate7702, statutory7702i);
+    database_.query_into(DB_AnnInterestRate7702, statutory7702i);
 
     std::vector<double> guar_int;
-    database().query_into(DB_GuarInt, guar_int);
+    database_.query_into(DB_GuarInt, guar_int);
 
     // For 7702 purposes, the rate guaranteed by the contract is the
     // highest rate on any potential path, at each duration; thus,
     // it is no less than the guaranteed fixed loan rate, i.e.:
     //   (fixed rate charged on loans) - (guaranteed loan spread)
-    if(!database().query<bool>(DB_IgnoreLoanRateFor7702))
+    if(!database_.query<bool>(DB_IgnoreLoanRateFor7702))
         {
         std::vector<double> allow_fixed_loan;
-        database().query_into(DB_AllowFixedLoan, allow_fixed_loan);
+        database_.query_into(DB_AllowFixedLoan, allow_fixed_loan);
         if(!each_equal(allow_fixed_loan, false))
             {
             std::vector<double> gross_loan_rate;
-            database().query_into(DB_FixedLoanRate    , gross_loan_rate);
+            database_.query_into(DB_FixedLoanRate    , gross_loan_rate);
             std::vector<double> guar_loan_spread;
-            database().query_into(DB_GuarRegLoanSpread, guar_loan_spread);
+            database_.query_into(DB_GuarRegLoanSpread, guar_loan_spread);
             assign
                 (guar_int
                 ,apply_binary
@@ -107,24 +109,33 @@ i7702::i7702
     // the issue date constitutes a short-term guarantee that must be
     // reflected in the 7702 interest rates (excluding the GLP rate).
 
-    Mly7702iGlp.assign(Length, 0.0);
+    gross_.assign(database_.length(), 0.0);
     assign
-        (Mly7702iGlp
+        (gross_
         ,apply_unary
             (i_upper_12_over_12_from_i<double>()
-            ,apply_binary(greater_of<double>(), statutory7702i, guar_int) - 
SpreadFor7702_
+            ,apply_binary(greater_of<double>(), statutory7702i, guar_int)
             )
         );
 
-    Mly7702iGsp.assign(Length, 0.0);
+    net_glp_.assign(database_.length(), 0.0);
     assign
-        (Mly7702iGsp
+        (net_glp_
         ,apply_unary
             (i_upper_12_over_12_from_i<double>()
-            ,apply_binary(greater_of<double>(), 0.02 + statutory7702i, 
guar_int) - SpreadFor7702_
+            ,apply_binary(greater_of<double>(), statutory7702i, guar_int) - 
spread_
             )
         );
 
-    database().query_into(DB_NaarDiscount, Mly7702ig);
-#endif // 0
+    net_gsp_.assign(database_.length(), 0.0);
+    assign
+        (net_gsp_
+        ,apply_unary
+            (i_upper_12_over_12_from_i<double>()
+            ,apply_binary(greater_of<double>(), 0.02 + statutory7702i, 
guar_int) - spread_
+            )
+        );
+
+    // 7702 !! WRONG: for 7702, Eckley's 'ig' must be 'gross_' as set above
+    database_.query_into(DB_NaarDiscount, gross_);
 }
diff --git a/irc7702_interest.hpp b/irc7702_interest.hpp
index 0a5a892..89845d5 100644
--- a/irc7702_interest.hpp
+++ b/irc7702_interest.hpp
@@ -45,13 +45,20 @@ class LMI_SO i7702 final
     i7702& operator=(i7702 const&) = delete;
     ~i7702() = default;
 
+    std::vector<double> const& gross  () const {return gross_;  }
+    std::vector<double> const& net_glp() const {return net_glp_;}
+    std::vector<double> const& net_gsp() const {return net_gsp_;}
+
+    // 7702 !! ephemeral
+    std::vector<double> const& spread() const {return spread_;}
+
   private:
     product_database   const& database_;
     stratified_charges const& stratified_;
 
     std::vector<double> spread_;
 
-    std::vector<double> gross_;
+    std::vector<double> gross_  ;
     std::vector<double> net_glp_;
     std::vector<double> net_gsp_;
 };



reply via email to

[Prev in Thread] Current Thread [Next in Thread]