[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 5e372c6 9/9: Perform ledger IRR initializatio
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 5e372c6 9/9: Perform ledger IRR initialization in one place only |
Date: |
Sat, 17 Feb 2018 11:13:06 -0500 (EST) |
branch: master
commit 5e372c6747ed410e4ebc41a45f362f619447cfc0
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Perform ledger IRR initialization in one place only
---
ledger_evaluator.cpp | 18 +-----------------
ledger_invariant.cpp | 29 +++++++++++++++++++++++------
ledger_text_formats.cpp | 23 ++++-------------------
ledger_xml_io.cpp | 8 ++------
4 files changed, 30 insertions(+), 48 deletions(-)
diff --git a/ledger_evaluator.cpp b/ledger_evaluator.cpp
index 9e436da..17e4c77 100644
--- a/ledger_evaluator.cpp
+++ b/ledger_evaluator.cpp
@@ -572,24 +572,8 @@ ledger_evaluator Ledger::make_evaluator() const
// Now we add the stuff that wasn't in the invariant
// ledger's class's maps (indexable by name). Because we're
// working with maps of pointers, we need pointers here.
- //
- // The IRRs are the worst of all.
- if(!ledger_invariant_->IsInforce)
- {
- ledger_invariant_->CalculateIrrs(*this);
- }
- else
- {
- ledger_invariant_->IrrCsvGuar0 .resize(max_duration, -1.0);
- ledger_invariant_->IrrDbGuar0 .resize(max_duration, -1.0);
- ledger_invariant_->IrrCsvCurr0 .resize(max_duration, -1.0);
- ledger_invariant_->IrrDbCurr0 .resize(max_duration, -1.0);
- ledger_invariant_->IrrCsvGuarInput.resize(max_duration, -1.0);
- ledger_invariant_->IrrDbGuarInput .resize(max_duration, -1.0);
- ledger_invariant_->IrrCsvCurrInput.resize(max_duration, -1.0);
- ledger_invariant_->IrrDbCurrInput .resize(max_duration, -1.0);
- }
+ ledger_invariant_->CalculateIrrs(*this);
vectors["IrrCsv_GuaranteedZero" ] = &ledger_invariant_->IrrCsvGuar0 ;
vectors["IrrDb_GuaranteedZero" ] = &ledger_invariant_->IrrDbGuar0 ;
diff --git a/ledger_invariant.cpp b/ledger_invariant.cpp
index 7127e0e..3d3dece 100644
--- a/ledger_invariant.cpp
+++ b/ledger_invariant.cpp
@@ -1263,6 +1263,13 @@ LedgerInvariant& LedgerInvariant::PlusEq(LedgerInvariant
const& a_Addend)
/// Perform costly IRR calculations on demand only.
///
+/// IRRs are not calculated for inforce illustrations because full
+/// payment history is generally not available. It would be possible
+/// of course to calculate IRRs from the inforce date forward, but
+/// it is feared that they'd be misinterpreted: e.g., IRR columns
+/// on illustrations run in different inforce years might be taken
+/// as directly comparable when they certainly are not.
+///
/// IRRs on zero-sepacct-interest bases cannot be calculated for
/// ledger types that do not generate values on those bases (any
/// attempt to access such values as irr() arguments would throw).
@@ -1270,6 +1277,10 @@ LedgerInvariant& LedgerInvariant::PlusEq(LedgerInvariant
const& a_Addend)
/// logic (they might be avoided implicitly if IRRs were set in
/// class LedgerVariant instead).
///
+/// Post-construction invariants: All IRR vectors have the same length
+/// as any typical vector member. They contain calculated IRRs if
+/// possible, or safe initial values of -100% otherwise.
+///
/// TODO ?? This function's purpose is to let formatting routines
/// decide whether to calculate IRRs, because those calculations
/// are costly and their results might not be used. Yet pushing any
@@ -1285,13 +1296,23 @@ void LedgerInvariant::CalculateIrrs(Ledger const&
LedgerValues)
{
irr_initialized_ = false;
+ IrrCsvGuar0 .resize(Length, -1.0);
+ IrrDbGuar0 .resize(Length, -1.0);
+ IrrCsvCurr0 .resize(Length, -1.0);
+ IrrDbCurr0 .resize(Length, -1.0);
+ IrrCsvGuarInput.resize(Length, -1.0);
+ IrrDbGuarInput .resize(Length, -1.0);
+ IrrCsvCurrInput.resize(Length, -1.0);
+ IrrDbCurrInput .resize(Length, -1.0);
+
+ if(IsInforce) {irr_initialized_ = true; return;}
+
auto const& r = LedgerValues.GetRunBases();
bool const run_curr_sep_zero = contains(r, mce_run_gen_curr_sep_zero);
bool const run_guar_sep_zero = contains(r, mce_run_gen_guar_sep_zero);
LMI_ASSERT(run_curr_sep_zero == run_guar_sep_zero);
// Emphasize that one of those is used as a proxy for both:
bool const zero_sepacct_interest_bases_undefined = !run_curr_sep_zero;
- // PDF !! Initialize the '0'-suffixed IRRs regardless.
// Terse aliases for invariants.
int const m = LedgerValues.GetMaxLength();
@@ -1305,11 +1326,7 @@ void LedgerInvariant::CalculateIrrs(Ledger const&
LedgerValues)
irr(Outlay, Curr_.CSVNet, IrrCsvCurrInput, Curr_.LapseYear, m, n);
irr(Outlay, Curr_.EOYDeathBft, IrrDbCurrInput, Curr_.LapseYear, m, n);
- if(zero_sepacct_interest_bases_undefined)
- {
- irr_initialized_ = true;
- return;
- }
+ if(zero_sepacct_interest_bases_undefined) {irr_initialized_ = true;
return;}
LedgerVariant const& Curr0 = LedgerValues.GetCurrZero();
LedgerVariant const& Guar0 = LedgerValues.GetGuarZero();
diff --git a/ledger_text_formats.cpp b/ledger_text_formats.cpp
index da06996..1279d97 100644
--- a/ledger_text_formats.cpp
+++ b/ledger_text_formats.cpp
@@ -183,8 +183,6 @@ calculation_summary_formatter::calculation_summary_formatter
unsigned int const length = invar_.GetLength();
- // TODO ?? This const_cast is safe, but it's still unclean.
- LedgerInvariant& unclean = const_cast<LedgerInvariant&>(invar_);
// Calculate IRRs only when necessary, because of the palpable
// effect on responsiveness--see:
// https://lists.nongnu.org/archive/html/lmi/2018-02/msg00098.html
@@ -194,17 +192,12 @@
calculation_summary_formatter::calculation_summary_formatter
|| contains(columns_, "IrrDb_Current" )
|| contains(columns_, "IrrDb_Guaranteed" )
;
- if(want_any_irr && !invar_.is_irr_initialized() && !invar_.IsInforce)
+ if(want_any_irr && !invar_.is_irr_initialized())
{
+ // TODO ?? This const_cast is safe, but it's still unclean.
+ LedgerInvariant& unclean = const_cast<LedgerInvariant&>(invar_);
unclean.CalculateIrrs(ledger_);
}
- else
- {
- unclean.IrrCsvCurrInput.resize(length, -1.0);
- unclean.IrrCsvGuarInput.resize(length, -1.0);
- unclean.IrrDbCurrInput .resize(length, -1.0);
- unclean.IrrDbGuarInput .resize(length, -1.0);
- }
}
std::string calculation_summary_formatter::top_note
@@ -468,15 +461,7 @@ void PrintCellTabDelimited
// TODO ?? This const_cast is safe, but it's still unclean.
LedgerInvariant& unclean = const_cast<LedgerInvariant&>(Invar);
- if(!Invar.IsInforce)
- {
- unclean.CalculateIrrs(ledger_values);
- }
- else
- {
- unclean.IrrCsvCurrInput.resize(max_length, -1.0);
- unclean.IrrDbCurrInput .resize(max_length, -1.0);
- }
+ unclean.CalculateIrrs(ledger_values);
std::ofstream os(file_name.c_str(), ios_out_app_binary());
diff --git a/ledger_xml_io.cpp b/ledger_xml_io.cpp
index 46b4da4..300d721 100644
--- a/ledger_xml_io.cpp
+++ b/ledger_xml_io.cpp
@@ -560,13 +560,9 @@ void Ledger::write(xml::element& x) const
// Now we add the stuff that wasn't in the invariant
// ledger's class's maps (indexable by name). Because we're
// working with maps of pointers, we need pointers here.
- //
- // The IRRs are the worst of all.
- if(!ledger_invariant_->IsInforce)
- {
- ledger_invariant_->CalculateIrrs(*this);
- }
+ ledger_invariant_->CalculateIrrs(*this);
+
vectors["IrrCsv_GuaranteedZero" ] = &ledger_invariant_->IrrCsvGuar0 ;
vectors["IrrDb_GuaranteedZero" ] = &ledger_invariant_->IrrDbGuar0 ;
vectors["IrrCsv_CurrentZero" ] = &ledger_invariant_->IrrCsvCurr0 ;
- [lmi-commits] [lmi] master updated (422cd51 -> 5e372c6), Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master 36d5a6b 1/9: Remove unnecessary static_cast, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master 513e891 4/9: Improve documentation, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master ca32be5 3/9: Find a root of the zero polynomial, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master 3781a93 5/9: Refactor for rearrangeability, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master 0ae54b4 2/9: Refactor for terseness, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master b710396 8/9: Don't assume--assert, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master 3f1dd88 7/9: Consolidate and improve documentation, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master 060aecf 6/9: Rearrange for comprehensibility, Greg Chicares, 2018/02/17
- [lmi-commits] [lmi] master 5e372c6 9/9: Perform ledger IRR initialization in one place only,
Greg Chicares <=