fast_xirr 1.1.0 → 1.1.1

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: 1e37e2d5d8077b1a7c54797002518552bd0c9baf733186de6ce0d0107855282f
4
- data.tar.gz: c5311eda41684c75763a272eb26007c0a5abd86ca9843f610a1ee4c9acd29836
3
+ metadata.gz: f240b5f7c4ffe72a091fea47502e7bf16a206502eb7b498131f68489698353a4
4
+ data.tar.gz: 541df15f67a6e62dc1d8c2a07db6673bd8b806b98a22dc7832a743824add6078
5
5
  SHA512:
6
- metadata.gz: c06564852a4e64033f3b2a15b45f724921e4eeb5711f196177d7efa94602affc9f76fc97b90133ed9f6c61e11cea70f20f45d50d8a32b79be7d7824d33a97daf
7
- data.tar.gz: cbba39344f6917161f08d7e06cd9a33ff6a4261db9ac2026b905b6481a1be4815e93f760c2fd0269cd58fb26dd4926c06de2db2e4ec0e4cd82104ff1c96ac2b5
6
+ metadata.gz: 15e8c80e533662528318fa0bd4a488c27c1fe30532d6b483acaf05e7407a67a17d899cad206d455d4d13a7ddcec929f7a265ba926222fe07881c9034f6718c89
7
+ data.tar.gz: deb52dffd457cab0bf5a730d75b26ed61cd0e87c6dc27708f2a515b61fd08edaeece7e09d365b3e08748cfab53f9bff87a404e7d8aa92ff091ed328769316336
@@ -127,14 +127,19 @@ double brent_method(CashFlow *cashflows, long long count, double tol,
127
127
  VALUE calculate_xirr_with_brent(VALUE self, VALUE rb_cashflows, VALUE rb_tol,
128
128
  VALUE rb_max_iter, VALUE rb_brackets) {
129
129
  // Get the number of cash flows
130
- long long count = (long long)RARRAY_LEN(rb_cashflows);
131
- CashFlow cashflows[count];
130
+ long long total_count = (long long)RARRAY_LEN(rb_cashflows);
131
+ CashFlow cashflows[total_count];
132
+ long long filtered_count = 0;
132
133
 
133
- // Convert Ruby cash flows array to C array
134
- for (long long i = 0; i < count; i++) {
134
+ // Convert Ruby cash flows array to C array, filtering out zero amounts
135
+ for (long long i = 0; i < total_count; i++) {
135
136
  VALUE rb_cashflow = rb_ary_entry(rb_cashflows, i);
136
- cashflows[i].amount = NUM2DBL(rb_ary_entry(rb_cashflow, 0));
137
- cashflows[i].date = (int64_t)NUM2LL(rb_ary_entry(rb_cashflow, 1));
137
+ double amount = NUM2DBL(rb_ary_entry(rb_cashflow, 0));
138
+ if (amount != 0.0) {
139
+ cashflows[filtered_count].amount = amount;
140
+ cashflows[filtered_count].date = (int64_t)NUM2LL(rb_ary_entry(rb_cashflow, 1));
141
+ filtered_count++;
142
+ }
138
143
  }
139
144
 
140
145
  // Convert tolerance and max iterations to C types
@@ -154,7 +159,7 @@ VALUE calculate_xirr_with_brent(VALUE self, VALUE rb_cashflows, VALUE rb_tol,
154
159
  high = NUM2DBL(rb_ary_entry(rb_brackets, 1));
155
160
  }
156
161
 
157
- result = brent_method(cashflows, count, tol, max_iter, low, high);
162
+ result = brent_method(cashflows, filtered_count, tol, max_iter, low, high);
158
163
  if (!isnan(result)) {
159
164
  return rb_float_new(result);
160
165
  }
@@ -162,8 +167,8 @@ VALUE calculate_xirr_with_brent(VALUE self, VALUE rb_cashflows, VALUE rb_tol,
162
167
  // If the standard interval fails, try to find a better bracketing interval
163
168
  low = -0.9999999;
164
169
  high = 100.0;
165
- if (find_bracketing_interval(cashflows, count, &low, &high)) {
166
- result = brent_method(cashflows, count, tol, max_iter, low, high);
170
+ if (find_bracketing_interval(cashflows, filtered_count, &low, &high)) {
171
+ result = brent_method(cashflows, filtered_count, tol, max_iter, low, high);
167
172
  return rb_float_new(result);
168
173
  }
169
174
 
@@ -1,4 +1,4 @@
1
1
  module FastXirr
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
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.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matias Martini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-13 00:00:00.000000000 Z
11
+ date: 2025-02-19 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: