[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] odd/eraseme_error 05e74a5 3/9: Clean up
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] odd/eraseme_error 05e74a5 3/9: Clean up |
Date: |
Thu, 8 Jul 2021 16:26:47 -0400 (EDT) |
branch: odd/eraseme_error
commit 05e74a59148202dcce8776c49836140556e7a078
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Clean up
---
Speed_gcc_i686-w64-mingw32 | 12 +++++-----
Speed_gcc_x86_64-pc-linux-gnu | 12 +++++-----
Speed_gcc_x86_64-w64-mingw32 | 12 +++++-----
financial.hpp | 51 +++++--------------------------------------
financial_test.cpp | 32 +++++++++------------------
zero.hpp | 18 +++++++--------
6 files changed, 43 insertions(+), 94 deletions(-)
diff --git a/Speed_gcc_i686-w64-mingw32 b/Speed_gcc_i686-w64-mingw32
index 370a7eb..7d2c660 100644
--- a/Speed_gcc_i686-w64-mingw32
+++ b/Speed_gcc_i686-w64-mingw32
@@ -1,7 +1,7 @@
Test speed:
- naic, no solve : 2.238e-02 s mean; 22081 us least of 45 runs
- naic, specamt solve : 4.625e-02 s mean; 45685 us least of 22 runs
- naic, ee prem solve : 4.159e-02 s mean; 41076 us least of 25 runs
- finra, no solve : 1.102e-02 s mean; 10819 us least of 91 runs
- finra, specamt solve: 3.371e-02 s mean; 33262 us least of 30 runs
- finra, ee prem solve: 3.014e-02 s mean; 29787 us least of 34 runs
+ naic, no solve : 2.358e-02 s mean; 22622 us least of 43 runs
+ naic, specamt solve : 4.835e-02 s mean; 47274 us least of 21 runs
+ naic, ee prem solve : 4.611e-02 s mean; 42212 us least of 22 runs
+ finra, no solve : 1.133e-02 s mean; 10727 us least of 89 runs
+ finra, specamt solve: 3.478e-02 s mean; 33837 us least of 29 runs
+ finra, ee prem solve: 3.128e-02 s mean; 30300 us least of 32 runs
diff --git a/Speed_gcc_x86_64-pc-linux-gnu b/Speed_gcc_x86_64-pc-linux-gnu
index f9e4b59..e34cf18 100644
--- a/Speed_gcc_x86_64-pc-linux-gnu
+++ b/Speed_gcc_x86_64-pc-linux-gnu
@@ -1,7 +1,7 @@
Test speed:
- naic, no solve : 1.577e-02 s mean; 14775 us least of 64 runs
- naic, specamt solve : 3.090e-02 s mean; 30354 us least of 33 runs
- naic, ee prem solve : 2.763e-02 s mean; 27169 us least of 37 runs
- finra, no solve : 5.386e-03 s mean; 5260 us least of 100 runs
- finra, specamt solve: 2.033e-02 s mean; 19904 us least of 50 runs
- finra, ee prem solve: 1.802e-02 s mean; 17614 us least of 56 runs
+ naic, no solve : 1.627e-02 s mean; 15173 us least of 62 runs
+ naic, specamt solve : 3.149e-02 s mean; 31162 us least of 32 runs
+ naic, ee prem solve : 2.812e-02 s mean; 27641 us least of 36 runs
+ finra, no solve : 5.426e-03 s mean; 5173 us least of 100 runs
+ finra, specamt solve: 2.064e-02 s mean; 20336 us least of 49 runs
+ finra, ee prem solve: 1.834e-02 s mean; 17864 us least of 55 runs
diff --git a/Speed_gcc_x86_64-w64-mingw32 b/Speed_gcc_x86_64-w64-mingw32
index 5c04e51..57fd4a5 100644
--- a/Speed_gcc_x86_64-w64-mingw32
+++ b/Speed_gcc_x86_64-w64-mingw32
@@ -1,7 +1,7 @@
Test speed:
- naic, no solve : 2.184e-02 s mean; 21525 us least of 46 runs
- naic, specamt solve : 4.088e-02 s mean; 40442 us least of 25 runs
- naic, ee prem solve : 3.682e-02 s mean; 36469 us least of 28 runs
- finra, no solve : 9.607e-03 s mean; 9400 us least of 100 runs
- finra, specamt solve: 2.760e-02 s mean; 27214 us least of 37 runs
- finra, ee prem solve: 2.481e-02 s mean; 24489 us least of 41 runs
+ naic, no solve : 2.222e-02 s mean; 21981 us least of 45 runs
+ naic, specamt solve : 4.191e-02 s mean; 41536 us least of 24 runs
+ naic, ee prem solve : 3.782e-02 s mean; 37471 us least of 27 runs
+ finra, no solve : 9.594e-03 s mean; 9439 us least of 100 runs
+ finra, specamt solve: 2.811e-02 s mean; 27780 us least of 36 runs
+ finra, ee prem solve: 2.535e-02 s mean; 25060 us least of 40 runs
diff --git a/financial.hpp b/financial.hpp
index 5d5bc89..ada1e9a 100644
--- a/financial.hpp
+++ b/financial.hpp
@@ -24,10 +24,8 @@
#include "config.hpp"
-#include "alert.hpp"
#include "assert_lmi.hpp"
#include "bourn_cast.hpp"
-#include "materially_equal.hpp"
#include "mc_enum_type_enums.hpp" // mcenum_mode
#include "miscellany.hpp" // ios_out_app_binary()
#include "zero.hpp"
@@ -63,49 +61,17 @@ long double fv
{
return 0.0L;
}
- long double const v = 1.0L / (1.0L + i);
- long double vn = 1.0L;
- long double z = 0.0L;
- for(InputIterator j = first; j != last; ++j)
- {
- z += *j * (vn *= v);
- }
- return z / (vn * v);
-}
-
-template<typename InputIterator>
-long double future_value
- (InputIterator first
- ,InputIterator last
- ,long double i
- )
-{
- if(first == last)
- {
- return 0.0L;
- }
- // v = 1/(1+i) is standard; u = 1+i should be, too
- // For i=-100%, this deliberately returns zero!
long double const u = 1.0L + i;
- long double un = 1.0L;
long double z = 0.0L;
- for(InputIterator j = last; j != first;)
+ for(InputIterator j = first; j != last; ++j)
{
- --j;
- un *= u;
- z += *j * un;
+ z += *j;
+ z *= u;
}
- warning().precision(21);
-#if 0
- auto y = fv(first, last, i);
- if(1.0e-10 < std::fabs(z - y) || !materially_equal(z, y))
- warning() << "UNEQUAL:\n " << z << "\n " << y << LMI_FLUSH;
-// LMI_ASSERT(std::fabs(z - y) < 1.0e-13);
- LMI_ASSERT(materially_equal(z, y));
-#endif // 0
return z;
}
+// rename; note the -100% NaN issue
template<typename InputIterator>
long double npv
(InputIterator first
@@ -147,7 +113,7 @@ class irr_helper
long double operator()(long double i)
{
- return future_value(first_, last_, i) - x_;
+ return fv(first_, last_, i) - x_;
}
long double operator()()
@@ -169,12 +135,7 @@ class irr_helper
{return z.root;}
// Return -100% if NPVs of a priori bounds have same sign.
case root_not_bracketed:
-// {return -1.0L;}
- {
- os_trace << "ROOT NOT BRACKETED\n" << std::endl;
-// return z.root;
- return 1234.5678;
- }
+ {return -1.0L;}
case improper_bounds:
{throw "IRR: improper bounds.";}
}
diff --git a/financial_test.cpp b/financial_test.cpp
index e4a1a63..6ee234e 100644
--- a/financial_test.cpp
+++ b/financial_test.cpp
@@ -39,14 +39,9 @@ int test_main(int, char*[])
double pmts[3] = {100.0, 200.0, 300.0};
double bfts[3] = {300.0, 1500.0, 5400.0};
- std::cout << fv(pmts + 0, pmts + 1, 0.04) << std::endl;
- std::cout << future_value(pmts + 0, pmts + 1, 0.04) << std::endl;
-
- std::cout << fv(pmts + 0, pmts + 2, 0.04) << std::endl;
- std::cout << future_value(pmts + 0, pmts + 2, 0.04) << std::endl;
-
- std::cout << fv(pmts + 0, pmts + 3, 0.04) << std::endl;
- std::cout << future_value(pmts + 0, pmts + 3, 0.04) << std::endl;
+ LMI_TEST(materially_equal(104.0000L, fv(pmts + 0, pmts + 1, 0.04)));
+ LMI_TEST(materially_equal(316.1600L, fv(pmts + 0, pmts + 2, 0.04)));
+ LMI_TEST(materially_equal(640.8064L, fv(pmts + 0, pmts + 3, 0.04)));
// The next few tests compare floating-point quantities for exact
// equality. Often that's inappropriate; however, the quantities
@@ -65,21 +60,14 @@ int test_main(int, char*[])
// Test with arrays.
double cash_flows[4] = {pmts[0], pmts[1], pmts[2], -bfts[2]};
LMI_TEST_EQUAL(2.0, irr(cash_flows, 4 + cash_flows, 5));
- std::cout
- << cash_flows[0] << "\n"
- << cash_flows[1] << "\n"
- << cash_flows[2] << "\n"
- << cash_flows[3] << "\n"
- << std::endl
- ;
- std::cout << fv(cash_flows + 0, cash_flows + 4, 0.04) << std::endl;
- std::cout << future_value(cash_flows + 0, cash_flows + 4, 0.04) <<
std::endl;
- std::cout << "fv of 'cash_flows' at i = -1, 0, 1:" << std::endl;
- std::cout << future_value(cash_flows + 0, cash_flows + 4, -1.0 ) <<
std::endl;
- std::cout << future_value(cash_flows + 0, cash_flows + 4, 0.0 ) <<
std::endl;
- std::cout << future_value(cash_flows + 0, cash_flows + 4, 1.0 ) <<
std::endl;
-//return 0;
+ LMI_TEST_EQUAL( 882.8125, fv(cash_flows + 0, cash_flows + 3, 0.25));
+ LMI_TEST_EQUAL( 2200.0 , fv(cash_flows + 0, cash_flows + 3, 1.0 ));
+
+ LMI_TEST_EQUAL( 0.0 , fv(cash_flows + 0, cash_flows + 4, -1.0 ));
+ LMI_TEST_EQUAL(-4800.0 , fv(cash_flows + 0, cash_flows + 4, 0.0 ));
+ LMI_TEST_EQUAL(-6400.0 , fv(cash_flows + 0, cash_flows + 4, 1.0 ));
+
// Test with vectors.
std::vector<double> v(cash_flows, 4 + cash_flows);
// The next test is begging to fail. It was designed so that 200%
diff --git a/zero.hpp b/zero.hpp
index 2dcdea8..8e8fc06 100644
--- a/zero.hpp
+++ b/zero.hpp
@@ -249,7 +249,7 @@ root_type lmi_root
,detail::RoundT round_dec = std::identity()
)
{
-os_trace << "Entering lmi_root() line " << __LINE__ << std::endl;
+//os_trace << "Entering lmi_root() line " << __LINE__ << std::endl;
constexpr double epsilon {std::numeric_limits<double>::epsilon()};
int n_iter {0};
@@ -290,7 +290,7 @@ os_trace << "Entering lmi_root() line " << __LINE__ <<
std::endl;
if(a == b)
{
-os_trace << "Returning from lmi_root() line " << __LINE__ << std::endl;
+//os_trace << "Returning from lmi_root() line " << __LINE__ << std::endl;
return {a, improper_bounds, n_iter};
}
@@ -298,7 +298,7 @@ os_trace << "Returning from lmi_root() line " << __LINE__
<< std::endl;
++n_iter;
if(0.0 == fa) // Note 0.
{
-os_trace << "Returning from lmi_root() line " << __LINE__ << std::endl;
+//os_trace << "Returning from lmi_root() line " << __LINE__ << std::endl;
return {a, root_is_valid, n_iter};
}
@@ -307,14 +307,14 @@ os_trace << "Returning from lmi_root() line " << __LINE__
<< std::endl;
expatiate();
if(0.0 == fb) // Note 0 [bis].
{
-os_trace << "Returning from lmi_root() line " << __LINE__ << std::endl;
+//os_trace << "Returning from lmi_root() line " << __LINE__ << std::endl;
return {b, root_is_valid, n_iter};
}
// f(a) and f(b) must have different signs.
if((0.0 < fa) == (0.0 < fb))
{
-os_trace << "Returning from lmi_root() line " << __LINE__ << std::endl;
+//os_trace << "Returning from lmi_root() line " << __LINE__ << std::endl;
return {0.0, root_not_bracketed, n_iter};
}
@@ -352,12 +352,12 @@ os_trace << "Returning from lmi_root() line " << __LINE__
<< std::endl;
|| bias_higher == bias && 0.0 <= fb
)
{
-os_trace << "Returning from lmi_root() line " << __LINE__ << std::endl;
+//os_trace << "Returning from lmi_root() line " << __LINE__ << std::endl;
return {b, root_is_valid, n_iter};
}
else if(std::fabs(m) <= 2.0 * epsilon * std::fabs(c) + t)
{
-os_trace << "Returning from lmi_root() line " << __LINE__ << std::endl;
+//os_trace << "Returning from lmi_root() line " << __LINE__ << std::endl;
return {c, root_is_valid, n_iter};
}
else
@@ -486,7 +486,7 @@ root_type decimal_root
,std::ostream& os_trace = null_stream()
)
{
-os_trace << "Entering decimal_root()" << std::endl;
+//os_trace << "Entering decimal_root()" << std::endl;
round_to<double> const round_dec {decimals, r_to_nearest};
auto z = lmi_root
@@ -498,7 +498,7 @@ os_trace << "Entering decimal_root()" << std::endl;
,bias
,detail::RoundT(round_dec)
);
-os_trace << "Returning from decimal_root()" << std::endl;
+//os_trace << "Returning from decimal_root()" << std::endl;
return z;
}
- [lmi-commits] [lmi] odd/eraseme_error updated (69d06e9 -> 58863bf), Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error 35f8824 1/9: Trace IRR calculations, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error 7b5c07f 6/9: Move and rename a function, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error 6c0d108 4/9: Add a couple obvious tests, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error 95690a5 5/9: Remove a confusing overload, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error cf5cced 7/9: Re-break; fail better, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error 273f15b 8/9: Restore un-breakage, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error 58863bf 9/9: Improve speed measurements, Greg Chicares, 2021/07/08
- [lmi-commits] [lmi] odd/eraseme_error 05e74a5 3/9: Clean up,
Greg Chicares <=
- [lmi-commits] [lmi] odd/eraseme_error ee0dc1c 2/9: Fix the problem in a slapdash manner, Greg Chicares, 2021/07/08