fast_xirr 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffedd74eba94cee0cb84e526c4cfa95b130e4a825cf2c364b2d40ee76a4b2465
4
- data.tar.gz: 645c4fa612bee6386e150f94d761567897c705aab9f6903c4e269828721a2f5d
3
+ metadata.gz: 4836e4f3499607c058d627e0718c1415bc7bfd23f750f9df413dc6c4527ee6a7
4
+ data.tar.gz: 9331bdb84b707c270c5e29d914dd9e6eeb814d102a1e0b3a25322e3e67435c73
5
5
  SHA512:
6
- metadata.gz: 6f9d2c6941ad9147f16f3bc60b1b8c21e4387531d42601caa4ac9e8bf311d2a3103e5d894883829e61f439f2144e28be4486b580d01099fc9a73906817bacf53
7
- data.tar.gz: 6e75a9452dd542a4f766e1252929e43dce5502b173b7fb70a37e4ccbb0b4b89bb76e16f042ec1fe20c6f3c03d57050afa1be76649df468f07103365935872f36
6
+ metadata.gz: e130e92d55d75e71b706ece17b6318c36924c69aae09b1b34320369a912b2ead4dc76caded2446ebe93389a3f6db9a55f65979a108a68feefadfe1511b87b39f
7
+ data.tar.gz: fed653b1893283b35d72846300995bee86e7fb452fcb66cda23d2285bcf97fda3b99c7c2a83719ed275336944e7aed712051b1d6f2031db64624705ef35256b7
data/README.md CHANGED
@@ -107,12 +107,12 @@ To build the gem from the source code, follow these steps:
107
107
  gem build fast_xirr.gemspec
108
108
  ```
109
109
 
110
- This will create a `.gem` file in the directory, such as `fast_xirr-1.0.0.gem`.
110
+ This will create a `.gem` file in the directory, such as `fast_xirr-1.x.x.gem`.
111
111
 
112
112
  3. **Install the Gem Locally**:
113
113
 
114
114
  ```bash
115
- gem install ./fast_xirr-1.0.0.gem
115
+ gem install ./fast_xirr*.gem
116
116
  ```
117
117
 
118
118
  ### Testing the Gem
@@ -20,6 +20,11 @@
20
20
  double bisection_method(CashFlow *cashflows, long long count, double tol, long long max_iter, double low, double high) {
21
21
  double mid, f_low, f_mid, f_high;
22
22
 
23
+ //If cashflows are empty, return 0
24
+ if (count == 0) {
25
+ return 0.0;
26
+ }
27
+
23
28
  // Calculate the NPV at the boundaries of the interval
24
29
  f_low = npv(low, cashflows, count, cashflows[0].date);
25
30
  f_high = npv(high, cashflows, count, cashflows[0].date);
@@ -18,6 +18,11 @@
18
18
  * @return The estimated root (XIRR) or NAN if it fails to converge.
19
19
  */
20
20
  double brent_method(CashFlow *cashflows, long long count, double tol, long long max_iter, double low, double high) {
21
+ //If cashflows are empty, return 0
22
+ if (count == 0) {
23
+ return 0.0;
24
+ }
25
+
21
26
  // Calculate the NPV at the boundaries of the interval
22
27
  double fa = npv(low, cashflows, count, cashflows[0].date);
23
28
  double fb = npv(high, cashflows, count, cashflows[0].date);
@@ -66,13 +66,12 @@ int find_bracketing_interval(CashFlow *cashflows, long long count, double *low,
66
66
  }
67
67
 
68
68
  // Extend the search range if no interval is found within the initial range
69
- step = 10.0;
70
- for (double rate = max_rate + step; rate <= 10000.0; rate += step) {
69
+ for (double rate = max_rate; rate <= 1e300; rate *= 1.5) {
71
70
  double npv_rate = npv(rate, cashflows, count, min_date);
72
71
 
73
72
  // Check if the function values at consecutive rates have opposite signs
74
73
  if (npv_min_rate * npv_rate < 0) {
75
- *low = rate - step;
74
+ *low = rate / 1.5;
76
75
  *high = rate;
77
76
  return 1;
78
77
  }
@@ -1,4 +1,4 @@
1
1
  module FastXirr
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.2"
3
3
  end
4
4
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_xirr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matias Martini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-03 00:00:00.000000000 Z
11
+ date: 2024-08-21 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A gem to calculate the XIRR using a C extension for performance.
14
14
  email: