[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [5628] Refactor for concinnity
From: |
Greg Chicares |
Subject: |
[lmi-commits] [5628] Refactor for concinnity |
Date: |
Wed, 19 Dec 2012 14:09:19 +0000 |
Revision: 5628
http://svn.sv.gnu.org/viewvc/?view=rev&root=lmi&revision=5628
Author: chicares
Date: 2012-12-19 14:09:19 +0000 (Wed, 19 Dec 2012)
Log Message:
-----------
Refactor for concinnity
Modified Paths:
--------------
lmi/trunk/ChangeLog
lmi/trunk/ihs_mortal.cpp
lmi/trunk/interest_rates.cpp
lmi/trunk/loads.cpp
lmi/trunk/math_functors.hpp
lmi/trunk/mortality_rates.cpp
Modified: lmi/trunk/ChangeLog
===================================================================
--- lmi/trunk/ChangeLog 2012-12-19 00:47:33 UTC (rev 5627)
+++ lmi/trunk/ChangeLog 2012-12-19 14:09:19 UTC (rev 5628)
@@ -31133,3 +31133,18 @@
version.hpp
Designate release candidate.
+20121219T0047Z <address@hidden> [549]
+
+ lmi.cpp
+ lmi.hpp
+Eliminate dead code.
+
+20121219T1409Z <address@hidden> [546]
+
+ ihs_mortal.cpp
+ interest_rates.cpp
+ loads.cpp
+ math_functors.hpp
+ mortality_rates.cpp
+Refactor for concinnity.
+
Modified: lmi/trunk/ihs_mortal.cpp
===================================================================
--- lmi/trunk/ihs_mortal.cpp 2012-12-19 00:47:33 UTC (rev 5627)
+++ lmi/trunk/ihs_mortal.cpp 2012-12-19 14:09:19 UTC (rev 5628)
@@ -31,9 +31,9 @@
#include "alert.hpp"
#include "assert_lmi.hpp"
#include "basic_values.hpp"
-#include "math_functors.hpp"
+#include "math_functors.hpp" // assign_midpoint()
-#include <algorithm>
+#include <algorithm> // std::min()
#include <functional>
//============================================================================
@@ -80,27 +80,9 @@
MakeCoiRateSubstandard(MonthlyGuaranteedCoiRates_);
}
- LMI_ASSERT(0 == MonthlyMidpointCoiRatesBand0_.size());
- LMI_ASSERT(0 == MonthlyMidpointCoiRatesBand1_.size());
- LMI_ASSERT(0 == MonthlyMidpointCoiRatesBand2_.size());
- for(int j = 0; j < Length_; ++j)
- {
- // Here we take midpoint as average of monthly curr and guar.
- // Other approaches are possible.
- // TODO ?? Use mean() instead.
- MonthlyMidpointCoiRatesBand0_.push_back
- ( 0.5
- * (MonthlyCurrentCoiRatesBand0_[j] + MonthlyGuaranteedCoiRates_[j])
- );
- MonthlyMidpointCoiRatesBand1_.push_back
- ( 0.5
- * (MonthlyCurrentCoiRatesBand1_[j] + MonthlyGuaranteedCoiRates_[j])
- );
- MonthlyMidpointCoiRatesBand2_.push_back
- ( 0.5
- * (MonthlyCurrentCoiRatesBand2_[j] + MonthlyGuaranteedCoiRates_[j])
- );
- }
+ assign_midpoint(MonthlyMidpointCoiRatesBand0_, MonthlyGuaranteedCoiRates_,
MonthlyCurrentCoiRatesBand0_);
+ assign_midpoint(MonthlyMidpointCoiRatesBand1_, MonthlyGuaranteedCoiRates_,
MonthlyCurrentCoiRatesBand1_);
+ assign_midpoint(MonthlyMidpointCoiRatesBand2_, MonthlyGuaranteedCoiRates_,
MonthlyCurrentCoiRatesBand2_);
/*
input from database and input classes
@@ -222,20 +204,7 @@
{
MakeCoiRateSubstandard(MonthlyCurrentTermCoiRates_);
MakeCoiRateSubstandard(MonthlyGuaranteedTermCoiRates_);
-
- LMI_ASSERT(0 == MonthlyMidpointTermCoiRates_.size());
- for(int j = 0; j < Length_; ++j)
- {
- // Here we take midpoint as average of monthly curr and guar.
- // Other approaches are possible.
- // TODO ?? Use mean() instead.
- MonthlyMidpointTermCoiRates_.push_back
- ( 0.5
- * ( MonthlyCurrentTermCoiRates_[j]
- + MonthlyGuaranteedTermCoiRates_[j]
- )
- );
- }
+ assign_midpoint(MonthlyMidpointTermCoiRates_,
MonthlyGuaranteedTermCoiRates_, MonthlyCurrentTermCoiRates_);
}
else
{
@@ -257,19 +226,7 @@
if(AllowSpouse_)
{
// Spouse rider can't be substandard--spouse not underwritten.
- LMI_ASSERT(0 == MidpointSpouseRiderRates_.size());
- for(int j = 0; j < Length_; ++j)
- {
- // Here we take midpoint as average of monthly curr and guar.
- // Other approaches are possible.
- // TODO ?? Use mean() instead.
- MidpointSpouseRiderRates_.push_back
- ( 0.5
- * ( CurrentSpouseRiderRates_[j]
- + GuaranteedSpouseRiderRates_[j]
- )
- );
- }
+ assign_midpoint(MidpointSpouseRiderRates_,
GuaranteedSpouseRiderRates_, CurrentSpouseRiderRates_);
}
else
{
@@ -279,6 +236,7 @@
if(AllowChild_)
{
// Child rider can't be substandard--child not underwritten.
+ // Midpoint needn't be calculated--guaranteed equals current.
}
if(IsTgtPremTabular_)
Modified: lmi/trunk/interest_rates.cpp
===================================================================
--- lmi/trunk/interest_rates.cpp 2012-12-19 00:47:33 UTC (rev 5627)
+++ lmi/trunk/interest_rates.cpp 2012-12-19 14:09:19 UTC (rev 5628)
@@ -33,15 +33,13 @@
#include "basic_values.hpp"
#include "database.hpp"
#include "dbnames.hpp"
-#include "math_functors.hpp"
-#include "miscellany.hpp" // each_equal()
+#include "math_functors.hpp" // assign_midpoint()
+#include "miscellany.hpp" // each_equal()
#include "yare_input.hpp"
-#include <algorithm>
-#include <cmath>
+#include <algorithm> // std::max(), std::copy()
#include <functional>
-#include <iterator>
-#include <utility>
+#include <iterator> // std::back_inserter()
#include <vector>
// TODO ?? Future enhancements:
@@ -473,14 +471,7 @@
GenAcctGrossRate_[mce_gen_mdpt] = Zero_;
if(NeedMidpointRates_)
{
- // ET !! GenAcctGrossRate_[mce_gen_mdpt] =
mean(GenAcctGrossRate_[mce_gen_guar], GenAcctGrossRate_[mce_gen_curr]);
- std::transform
- (GenAcctGrossRate_[mce_gen_guar].begin()
- ,GenAcctGrossRate_[mce_gen_guar].end()
- ,GenAcctGrossRate_[mce_gen_curr].begin()
- ,GenAcctGrossRate_[mce_gen_mdpt].begin()
- ,mean<double>()
- );
+ assign_midpoint(GenAcctGrossRate_[mce_gen_mdpt],
GenAcctGrossRate_[mce_gen_guar], GenAcctGrossRate_[mce_gen_curr]);
}
else
{
@@ -641,22 +632,8 @@
PrfLoanSpread_[mce_gen_mdpt] = Zero_;
if(NeedMidpointRates_)
{
- // ET !! RegLoanSpread_[mce_gen_mdpt] =
mean(RegLoanSpread_[mce_gen_guar], RegLoanSpread_[mce_gen_curr]);
- std::transform
- (RegLoanSpread_[mce_gen_guar].begin()
- ,RegLoanSpread_[mce_gen_guar].end()
- ,RegLoanSpread_[mce_gen_curr].begin()
- ,RegLoanSpread_[mce_gen_mdpt].begin()
- ,mean<double>()
- );
- // ET !! PrfLoanSpread_[mce_gen_mdpt] =
mean(PrfLoanSpread_[mce_gen_guar], PrfLoanSpread_[mce_gen_curr]);
- std::transform
- (PrfLoanSpread_[mce_gen_guar].begin()
- ,PrfLoanSpread_[mce_gen_guar].end()
- ,PrfLoanSpread_[mce_gen_curr].begin()
- ,PrfLoanSpread_[mce_gen_mdpt].begin()
- ,mean<double>()
- );
+ assign_midpoint(RegLoanSpread_[mce_gen_mdpt],
RegLoanSpread_[mce_gen_guar], RegLoanSpread_[mce_gen_curr]);
+ assign_midpoint(PrfLoanSpread_[mce_gen_mdpt],
PrfLoanSpread_[mce_gen_guar], PrfLoanSpread_[mce_gen_curr]);
}
for(int j = mce_gen_curr; j < mc_n_gen_bases; j++)
@@ -714,18 +691,25 @@
}
}
- // RegLnDueRate_ cannot vary by basis for fixed loan rate, but
- // may for VLR--in which case these assertions will fire,
- // indicating that this code should be reviewed.
- //
- LMI_ASSERT
- ( RegLnDueRate_[mce_annual_rate ][mce_gen_guar]
- == RegLnDueRate_[mce_annual_rate ][mce_gen_curr]
- );
- LMI_ASSERT
- ( RegLnDueRate_[mce_monthly_rate][mce_gen_guar]
- == RegLnDueRate_[mce_monthly_rate][mce_gen_curr]
- );
+ // RegLnDueRate_ cannot vary by basis for fixed loan rate, but
+ // may for VLR--in which case these assertions will fire,
+ // indicating that this code should be reviewed.
+ //
+ // PETE causes an 'ambiguous overload' error for vector 'v0==v1',
+ // but not if std::operator==(v0,v1) is called explicitly.
+
+ LMI_ASSERT
+ (std::operator==
+ (RegLnDueRate_[mce_annual_rate ][mce_gen_guar]
+ ,RegLnDueRate_[mce_annual_rate ][mce_gen_curr]
+ )
+ );
+ LMI_ASSERT
+ (std::operator==
+ (RegLnDueRate_[mce_monthly_rate][mce_gen_guar]
+ ,RegLnDueRate_[mce_monthly_rate][mce_gen_curr]
+ )
+ );
}
void InterestRates::InitializeHoneymoonRates()
Modified: lmi/trunk/loads.cpp
===================================================================
--- lmi/trunk/loads.cpp 2012-12-19 00:47:33 UTC (rev 5627)
+++ lmi/trunk/loads.cpp 2012-12-19 14:09:19 UTC (rev 5628)
@@ -35,13 +35,10 @@
#include "database.hpp"
#include "dbnames.hpp"
#include "et_vector.hpp"
-#include "math_functors.hpp"
-#include "mc_enum_types_aux.hpp" // mc_n_ enumerators
+#include "math_functors.hpp" // assign_midpoint()
+#include "mc_enum_types_aux.hpp" // mc_n_ enumerators
#include "premium_tax.hpp"
-#include <algorithm>
-#include <functional>
-
/// Ctor for unit testing.
Loads::Loads()
@@ -303,20 +300,18 @@
}
}
- // Calculate midpoint as mean of current and guaranteed.
- // A different average might be used instead.
if(details.NeedMidpointRates_)
{
- assign(monthly_policy_fee_ [mce_gen_mdpt],
apply_binary(mean<double>(), monthly_policy_fee_ [mce_gen_guar],
monthly_policy_fee_ [mce_gen_curr]));
- assign(annual_policy_fee_ [mce_gen_mdpt],
apply_binary(mean<double>(), annual_policy_fee_ [mce_gen_guar],
annual_policy_fee_ [mce_gen_curr]));
- assign(specified_amount_load_[mce_gen_mdpt],
apply_binary(mean<double>(), specified_amount_load_[mce_gen_guar],
specified_amount_load_[mce_gen_curr]));
- assign(separate_account_load_[mce_gen_mdpt],
apply_binary(mean<double>(), separate_account_load_[mce_gen_guar],
separate_account_load_[mce_gen_curr]));
- assign(target_premium_load_ [mce_gen_mdpt],
apply_binary(mean<double>(), target_premium_load_ [mce_gen_guar],
target_premium_load_ [mce_gen_curr]));
- assign(excess_premium_load_ [mce_gen_mdpt],
apply_binary(mean<double>(), excess_premium_load_ [mce_gen_guar],
excess_premium_load_ [mce_gen_curr]));
- assign(target_sales_load_ [mce_gen_mdpt],
apply_binary(mean<double>(), target_sales_load_ [mce_gen_guar],
target_sales_load_ [mce_gen_curr]));
- assign(excess_sales_load_ [mce_gen_mdpt],
apply_binary(mean<double>(), excess_sales_load_ [mce_gen_guar],
excess_sales_load_ [mce_gen_curr]));
- assign(target_total_load_ [mce_gen_mdpt],
apply_binary(mean<double>(), target_total_load_ [mce_gen_guar],
target_total_load_ [mce_gen_curr]));
- assign(excess_total_load_ [mce_gen_mdpt],
apply_binary(mean<double>(), excess_total_load_ [mce_gen_guar],
excess_total_load_ [mce_gen_curr]));
+ assign_midpoint(monthly_policy_fee_ [mce_gen_mdpt],
monthly_policy_fee_ [mce_gen_guar], monthly_policy_fee_ [mce_gen_curr]);
+ assign_midpoint(annual_policy_fee_ [mce_gen_mdpt],
annual_policy_fee_ [mce_gen_guar], annual_policy_fee_ [mce_gen_curr]);
+ assign_midpoint(specified_amount_load_[mce_gen_mdpt],
specified_amount_load_[mce_gen_guar], specified_amount_load_[mce_gen_curr]);
+ assign_midpoint(separate_account_load_[mce_gen_mdpt],
separate_account_load_[mce_gen_guar], separate_account_load_[mce_gen_curr]);
+ assign_midpoint(target_premium_load_ [mce_gen_mdpt],
target_premium_load_ [mce_gen_guar], target_premium_load_ [mce_gen_curr]);
+ assign_midpoint(excess_premium_load_ [mce_gen_mdpt],
excess_premium_load_ [mce_gen_guar], excess_premium_load_ [mce_gen_curr]);
+ assign_midpoint(target_sales_load_ [mce_gen_mdpt],
target_sales_load_ [mce_gen_guar], target_sales_load_ [mce_gen_curr]);
+ assign_midpoint(excess_sales_load_ [mce_gen_mdpt],
excess_sales_load_ [mce_gen_guar], excess_sales_load_ [mce_gen_curr]);
+ assign_midpoint(target_total_load_ [mce_gen_mdpt],
target_total_load_ [mce_gen_guar], target_total_load_ [mce_gen_curr]);
+ assign_midpoint(excess_total_load_ [mce_gen_mdpt],
excess_total_load_ [mce_gen_guar], excess_total_load_ [mce_gen_curr]);
}
}
@@ -364,18 +359,12 @@
// This ctor ignores tabular specified-amount loads.
- // Calculate midpoint as mean of current and guaranteed.
- // A different average might be used instead.
if(NeedMidpointRates)
{
- monthly_policy_fee_ [mce_gen_mdpt].resize(database.length());
- assign(monthly_policy_fee_ [mce_gen_mdpt],
apply_binary(mean<double>(), monthly_policy_fee_ [mce_gen_guar],
monthly_policy_fee_ [mce_gen_curr]));
- target_premium_load_ [mce_gen_mdpt].resize(database.length());
- assign(target_premium_load_ [mce_gen_mdpt],
apply_binary(mean<double>(), target_premium_load_ [mce_gen_guar],
target_premium_load_ [mce_gen_curr]));
- excess_premium_load_ [mce_gen_mdpt].resize(database.length());
- assign(excess_premium_load_ [mce_gen_mdpt],
apply_binary(mean<double>(), excess_premium_load_ [mce_gen_guar],
excess_premium_load_ [mce_gen_curr]));
- specified_amount_load_[mce_gen_mdpt].resize(database.length());
- assign(specified_amount_load_[mce_gen_mdpt],
apply_binary(mean<double>(), specified_amount_load_[mce_gen_guar],
specified_amount_load_[mce_gen_curr]));
+ assign_midpoint(monthly_policy_fee_ [mce_gen_mdpt],
monthly_policy_fee_ [mce_gen_guar], monthly_policy_fee_ [mce_gen_curr]);
+ assign_midpoint(target_premium_load_ [mce_gen_mdpt],
target_premium_load_ [mce_gen_guar], target_premium_load_ [mce_gen_curr]);
+ assign_midpoint(excess_premium_load_ [mce_gen_mdpt],
excess_premium_load_ [mce_gen_guar], excess_premium_load_ [mce_gen_curr]);
+ assign_midpoint(specified_amount_load_[mce_gen_mdpt],
specified_amount_load_[mce_gen_guar], specified_amount_load_[mce_gen_curr]);
}
premium_tax_load_.push_back(0.0);
Modified: lmi/trunk/math_functors.hpp
===================================================================
--- lmi/trunk/math_functors.hpp 2012-12-19 00:47:33 UTC (rev 5627)
+++ lmi/trunk/math_functors.hpp 2012-12-19 14:09:19 UTC (rev 5628)
@@ -26,6 +26,9 @@
#include "config.hpp"
+#include "assert_lmi.hpp"
+#include "et_vector.hpp"
+
#if !defined __BORLANDC__
# include <boost/static_assert.hpp>
# include <boost/type_traits/is_float.hpp>
@@ -33,10 +36,11 @@
# define BOOST_STATIC_ASSERT(deliberately_ignored) class IgNoRe
#endif // Defined __BORLANDC__ .
-#include <algorithm>
-#include <cmath>
+#include <algorithm> // std::max(), std::min()
+#include <cmath> // C99 expm1(), log1p()
#include <functional>
#include <stdexcept>
+#include <vector>
// For Comeau, implement expm1l() and log1pl() using type double, not
// long double, because of an apparent incompatibility in the way
@@ -86,6 +90,8 @@
}
};
+/// Arithmetic mean.
+///
/// Calculate mean as
/// (half of x) plus (half of y)
/// instead of
@@ -326,5 +332,25 @@
}
};
+/// Midpoint for illustration reg.
+///
+/// Section 7(C)(1)(c)(ii) prescribes an "average" without specifying
+/// which average to use. The arithmetic mean is used here because
+/// that seems to be the most common practice. On the other hand, a
+/// strong case can be made for using the geometric mean, at least
+/// with interest and mortality rates.
+
+template<typename T>
+void assign_midpoint
+ (std::vector<T> & out
+ ,std::vector<T> const& in_0
+ ,std::vector<T> const& in_1
+ )
+{
+ LMI_ASSERT(in_0.size() == in_1.size());
+ out.resize(in_0.size());
+ assign(out, apply_binary(mean<T>(), in_0, in_1));
+}
+
#endif // math_functors_hpp
Modified: lmi/trunk/mortality_rates.cpp
===================================================================
--- lmi/trunk/mortality_rates.cpp 2012-12-19 00:47:33 UTC (rev 5627)
+++ lmi/trunk/mortality_rates.cpp 2012-12-19 14:09:19 UTC (rev 5628)
@@ -33,9 +33,9 @@
#include "basic_values.hpp"
#include "database.hpp"
#include "dbnames.hpp"
-#include "math_functors.hpp" // mean()
+#include "math_functors.hpp" // assign_midpoint()
-#include <algorithm> // std::min()
+#include <algorithm> // std::min()
//============================================================================
MortalityRates::MortalityRates(BasicValues const& basic_values)
@@ -73,17 +73,7 @@
);
}
- MonthlyMidpointCoiRatesBand0_.resize(length);
- // Calculate midpoint as mean of current and guaranteed.
- // A different average might be used instead.
- // ET !! MonthlyMidpointCoiRatesBand0_ =
mean(MonthlyCurrentCoiRatesBand0_, MonthlyGuaranteedCoiRates_);
- std::transform
- (MonthlyCurrentCoiRatesBand0_.begin()
- ,MonthlyCurrentCoiRatesBand0_.end()
- ,MonthlyGuaranteedCoiRates_.begin()
- ,MonthlyMidpointCoiRatesBand0_.begin()
- ,mean<double>()
- );
+ assign_midpoint(MonthlyMidpointCoiRatesBand0_, MonthlyGuaranteedCoiRates_,
MonthlyCurrentCoiRatesBand0_);
CvatCorridorFactors_ = actuarial_table_rates
(CurrentTableFile()
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [5628] Refactor for concinnity,
Greg Chicares <=