amortizy 1.0.0 → 2.1.0

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.
data/tasks/todo.md ADDED
@@ -0,0 +1,203 @@
1
+ # Amortizy v2.1 — Commercial Financing Disclosure Module
2
+
3
+ ## Goal
4
+
5
+ Add a `Disclosure` class that computes California SB 1235 disclosure data elements
6
+ for closed-end commercial loan transactions. The gem exposes jurisdiction-agnostic
7
+ numbers — APR (Reg Z actuarial method), finance charge, amount financed, recipient
8
+ funds, term, average monthly cost, and prepayment info — queryable via a clean API.
9
+
10
+ **Design decisions:**
11
+ - `Amortizy::Disclosure` is a separate class that wraps an `AmortizationSchedule`
12
+ - Origination fee is treated as a prepaid finance charge by default (deducted from
13
+ amount financed, included in finance charge) — must be documented
14
+ - No state/jurisdiction parameters — data elements are universal
15
+ - No document formatting — the gem computes numbers, not PDFs
16
+ - Scoped to closed-end transactions only (no MCA, factoring, leases, open-end)
17
+
18
+ **Regulatory references:**
19
+ - Section 910: Closed-end transaction disclosure contents
20
+ - Section 940: APR calculation (Appendix J, 12 CFR Part 1026 — actuarial method)
21
+ - Section 943: Finance charge definition
22
+ - Section 900(a)(1)(B): Amount financed for closed-end transactions
23
+ - Section 900(a)(26): Recipient funds
24
+ - Section 955: APR tolerance (1/8 of 1 percentage point)
25
+
26
+ ---
27
+
28
+ ## Phase 1: Disclosure Class Skeleton
29
+
30
+ ### 1.1 Create `lib/amortizy/disclosure.rb`
31
+ - [ ] Define `Amortizy::Disclosure` class
32
+ - [ ] Accept `AmortizationSchedule` as first argument
33
+ - [ ] Accept keyword args: `third_party_payments: 0`, `prepayment_penalty_max: 0`,
34
+ `additional_prepayment_fees: []`
35
+ - [ ] Validate that schedule argument is an `AmortizationSchedule`
36
+ - [ ] Store schedule reference and disclosure-specific params
37
+
38
+ ### 1.2 Wire into gem
39
+ - [ ] Add `require_relative 'amortizy/disclosure'` to `lib/amortizy.rb`
40
+ - [ ] Create `spec/disclosure_spec.rb` with basic instantiation tests
41
+
42
+ ---
43
+
44
+ ## Phase 2: Simple Computed Properties
45
+
46
+ These derive directly from existing schedule data with minimal new logic.
47
+
48
+ ### 2.1 Finance Charge (§943)
49
+ - [ ] `#finance_charge` — total dollar cost of financing
50
+ - [ ] Calculation: `total_interest + origination_fee + additional_fee`
51
+ - [ ] All charges that would be included under 12 CFR 1026.4 if this were consumer credit
52
+ - [ ] Spec: verify against known loan (e.g., $50K, 12%, 36mo, $500 orig fee, $250 addl fee)
53
+
54
+ ### 2.2 Amount Financed (§900(a)(1)(B))
55
+ - [ ] `#amount_financed` — principal + financed amounts - prepaid finance charges
56
+ - [ ] For closed-end: `principal + additional_fee (if add_to_principal) - origination_fee`
57
+ - [ ] Origination fee treated as prepaid finance charge (deducted)
58
+ - [ ] Additional fee treatment depends on `additional_fee_treatment` setting:
59
+ - `:distributed` or `:separate_payment` → not added to amount financed
60
+ - `:add_to_principal` → added to amount financed
61
+ - [ ] Spec: test all three fee treatment scenarios
62
+
63
+ ### 2.3 Total Payment Amount (§910(a)(5))
64
+ - [ ] `#total_payment_amount` — delegates to `schedule.total_paid`
65
+ - [ ] Spec: verify matches schedule total
66
+
67
+ ### 2.4 Recipient Funds (§900(a)(26))
68
+ - [ ] `#recipient_funds` — net amount given directly to the borrower
69
+ - [ ] Calculation: `amount_financed - third_party_payments`
70
+ - [ ] Spec: with and without third-party payments
71
+
72
+ ### 2.5 Term Display (§901(a)(4))
73
+ - [ ] `#term_days` — total days from start to last payment
74
+ - [ ] `#term_display` — formatted per regulation:
75
+ - Term <= 1 year: display in days (e.g., "270 days")
76
+ - Term > 1 year: display in years and months, remainder as decimal
77
+ (e.g., "2 years, 3.15 months")
78
+ - [ ] Spec: test boundary at exactly 365 days, and multi-year terms
79
+
80
+ ### 2.6 Average Monthly Cost (§910(a)(12))
81
+ - [ ] `#average_monthly_cost` — total payments / (term_days / 30.4)
82
+ - [ ] Returns `nil` for monthly frequency (only required for non-monthly)
83
+ - [ ] Spec: weekly and biweekly loans, verify nil for monthly
84
+
85
+ ---
86
+
87
+ ## Phase 3: APR Calculation (§940)
88
+
89
+ The core engineering work. APR per Appendix J of Regulation Z (12 CFR Part 1026).
90
+
91
+ ### 3.1 Actuarial method solver
92
+ - [ ] Implement APR calculation using the actuarial method
93
+ - [ ] The APR is the rate `i` that satisfies:
94
+ `Amount Financed = Σ (Payment_k / (1 + i)^(t_k / 365))`
95
+ where `t_k` is the number of days from disbursement to payment k
96
+ - [ ] Use Newton-Raphson iteration to solve for `i`
97
+ - [ ] Convergence tolerance: 1/8 of 1 percentage point (0.00125) per §955
98
+ - [ ] Maximum iterations: 100 (with fallback to bisection if Newton diverges)
99
+ - [ ] Cash flows: amount financed is the initial advance (positive);
100
+ each scheduled payment is an outflow (negative)
101
+ - [ ] Include all finance charge components in the payment stream
102
+
103
+ ### 3.2 Cash flow extraction
104
+ - [ ] Extract payment dates and amounts from the schedule
105
+ - [ ] Include separate_payment additional fees in the stream
106
+ - [ ] Include grace period payments if any
107
+ - [ ] Disbursement date = schedule start_date
108
+ - [ ] Each payment: { date:, amount: } from schedule rows
109
+
110
+ ### 3.3 APR formatting
111
+ - [ ] `#apr` — returns APR as a percentage rounded to nearest 10 basis points (§901(a)(5))
112
+ e.g., 14.8, 14.85, not 14.8532
113
+ - [ ] Spec: verify against known Reg Z examples
114
+ - [ ] Spec: tolerance check — result within 1/8 percentage point of exact
115
+
116
+ ### 3.4 Edge cases
117
+ - [ ] Zero-interest loans (APR should reflect fees only)
118
+ - [ ] Loans with grace periods (disbursement date vs first payment date gap)
119
+ - [ ] Interest-only periods followed by amortizing payments
120
+ - [ ] Precomputed interest method
121
+ - [ ] Very short terms (< 30 days)
122
+ - [ ] Very long terms (> 10 years)
123
+
124
+ ---
125
+
126
+ ## Phase 4: Prepayment Information (§910(a)(8-10))
127
+
128
+ ### 4.1 Prepayment hash
129
+ - [ ] `#prepayment` — returns hash:
130
+ ```ruby
131
+ {
132
+ has_non_interest_charges: true/false,
133
+ max_non_interest_finance_charge: Float or nil,
134
+ has_additional_fees: true/false,
135
+ additional_fees: [] # array of { amount:, description: } hashes
136
+ }
137
+ ```
138
+ - [ ] Derived from `prepayment_penalty_max` and `additional_prepayment_fees` inputs
139
+ - [ ] Spec: all four combinations (charges/no charges x fees/no fees)
140
+
141
+ ---
142
+
143
+ ## Phase 5: Output Methods
144
+
145
+ ### 5.1 `#to_h`
146
+ - [ ] Returns flat hash of all computed values:
147
+ ```ruby
148
+ {
149
+ amount_financed:, apr:, finance_charge:, total_payment_amount:,
150
+ payment_amount:, payment_frequency:, term_days:, term_display:,
151
+ average_monthly_cost:, recipient_funds:, prepayment:
152
+ }
153
+ ```
154
+ - [ ] All monetary values as Float, rounded to 2 decimal places
155
+ - [ ] Spec: verify all keys present, types correct
156
+
157
+ ### 5.2 `#to_labeled_h`
158
+ - [ ] Returns hash with regulation-correct labels:
159
+ ```ruby
160
+ {
161
+ amount_financed: { label: "Funding Provided", value: 50_250.00 },
162
+ apr: { label: "Annual Percentage Rate (APR)", value: 14.85 },
163
+ finance_charge: { label: "Finance Charge", value: 10_432.50 },
164
+ ...
165
+ }
166
+ ```
167
+ - [ ] Labels follow §910 column 1 text for fixed-rate closed-end transactions
168
+ - [ ] Spec: verify exact label strings match regulation text
169
+
170
+ ---
171
+
172
+ ## Phase 6: Documentation & Polish
173
+
174
+ ### 6.1 README updates
175
+ - [ ] Add Disclosure section to README with usage examples
176
+ - [ ] Document the origination fee = prepaid finance charge assumption
177
+ - [ ] Document regulatory references (CA SB 1235, sections 910/940/943)
178
+ - [ ] Note that labels follow California regulation but values are jurisdiction-agnostic
179
+
180
+ ### 6.2 CHANGELOG
181
+ - [ ] Add v2.1.0 entry documenting the disclosure module
182
+
183
+ ### 6.3 Version bump
184
+ - [ ] Bump version to 2.1.0 in `version.rb`
185
+
186
+ ### 6.4 Final spec run
187
+ - [ ] Full suite green — existing specs unaffected
188
+ - [ ] Disclosure specs comprehensive — all nine data elements tested
189
+ - [ ] APR accuracy verified against at least 3 known Reg Z examples
190
+
191
+ ---
192
+
193
+ ## Out of Scope
194
+
195
+ - MCA / sales-based financing disclosures (§914)
196
+ - Factoring disclosures (§912, §913)
197
+ - Open-end credit plan disclosures (§911)
198
+ - Lease financing disclosures (§915)
199
+ - Asset-based lending disclosures (§916)
200
+ - Disclosure document generation (PDF/HTML formatting)
201
+ - Jurisdiction detection or state-specific logic
202
+ - Adjustable rate APR estimation (amortizy only does fixed-rate)
203
+ - Retrospective APR auditing (§931)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amortizy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rich Zapata
@@ -23,26 +23,28 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '8.0'
26
- description: A comprehensive Ruby gem for generating loan amortization schedules with
27
- advanced features including grace periods, interest-only payments, federal bank
28
- holidays, and multiple interest calculation methods
26
+ description: Generate loan amortization schedules with monthly, bi-weekly, weekly,
27
+ or daily payments. Supports grace periods, interest-only payments, federal bank
28
+ holidays, and multiple interest calculation methods.
29
29
  email:
30
30
  - rzapata@gmail.com
31
31
  executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - ".DS_Store"
36
35
  - CHANGELOG.md
37
- - CODE_OF_CONDUCT.md
36
+ - CONTRIBUTING.md
38
37
  - LICENSE.txt
39
38
  - README.md
40
39
  - Rakefile
41
- - lib/.DS_Store
42
40
  - lib/amortizy.rb
41
+ - lib/amortizy/console_formatter.rb
42
+ - lib/amortizy/csv_formatter.rb
43
+ - lib/amortizy/disclosure.rb
43
44
  - lib/amortizy/engine.rb
44
45
  - lib/amortizy/version.rb
45
46
  - sig/amortizy.rbs
47
+ - tasks/todo.md
46
48
  homepage: https://github.com/zapatify/amortizy
47
49
  licenses:
48
50
  - MIT
@@ -51,6 +53,7 @@ metadata:
51
53
  homepage_uri: https://github.com/zapatify/amortizy
52
54
  source_code_uri: https://github.com/zapatify/amortizy
53
55
  changelog_uri: https://github.com/zapatify/amortizy/blob/main/CHANGELOG.md
56
+ rubygems_mfa_required: 'true'
54
57
  rdoc_options: []
55
58
  require_paths:
56
59
  - lib
@@ -58,14 +61,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
61
  requirements:
59
62
  - - ">="
60
63
  - !ruby/object:Gem::Version
61
- version: 2.7.0
64
+ version: 3.0.0
62
65
  required_rubygems_version: !ruby/object:Gem::Requirement
63
66
  requirements:
64
67
  - - ">="
65
68
  - !ruby/object:Gem::Version
66
69
  version: '0'
67
70
  requirements: []
68
- rubygems_version: 3.7.2
71
+ rubygems_version: 4.0.6
69
72
  specification_version: 4
70
73
  summary: A gem to generate amortization schedules
71
74
  test_files: []
data/.DS_Store DELETED
Binary file
data/CODE_OF_CONDUCT.md DELETED
@@ -1,132 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our
6
- community a harassment-free experience for everyone, regardless of age, body
7
- size, visible or invisible disability, ethnicity, sex characteristics, gender
8
- identity and expression, level of experience, education, socio-economic status,
9
- nationality, personal appearance, race, caste, color, religion, or sexual
10
- identity and orientation.
11
-
12
- We pledge to act and interact in ways that contribute to an open, welcoming,
13
- diverse, inclusive, and healthy community.
14
-
15
- ## Our Standards
16
-
17
- Examples of behavior that contributes to a positive environment for our
18
- community include:
19
-
20
- * Demonstrating empathy and kindness toward other people
21
- * Being respectful of differing opinions, viewpoints, and experiences
22
- * Giving and gracefully accepting constructive feedback
23
- * Accepting responsibility and apologizing to those affected by our mistakes,
24
- and learning from the experience
25
- * Focusing on what is best not just for us as individuals, but for the overall
26
- community
27
-
28
- Examples of unacceptable behavior include:
29
-
30
- * The use of sexualized language or imagery, and sexual attention or advances of
31
- any kind
32
- * Trolling, insulting or derogatory comments, and personal or political attacks
33
- * Public or private harassment
34
- * Publishing others' private information, such as a physical or email address,
35
- without their explicit permission
36
- * Other conduct which could reasonably be considered inappropriate in a
37
- professional setting
38
-
39
- ## Enforcement Responsibilities
40
-
41
- Community leaders are responsible for clarifying and enforcing our standards of
42
- acceptable behavior and will take appropriate and fair corrective action in
43
- response to any behavior that they deem inappropriate, threatening, offensive,
44
- or harmful.
45
-
46
- Community leaders have the right and responsibility to remove, edit, or reject
47
- comments, commits, code, wiki edits, issues, and other contributions that are
48
- not aligned to this Code of Conduct, and will communicate reasons for moderation
49
- decisions when appropriate.
50
-
51
- ## Scope
52
-
53
- This Code of Conduct applies within all community spaces, and also applies when
54
- an individual is officially representing the community in public spaces.
55
- Examples of representing our community include using an official email address,
56
- posting via an official social media account, or acting as an appointed
57
- representative at an online or offline event.
58
-
59
- ## Enforcement
60
-
61
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
- reported to the community leaders responsible for enforcement at
63
- [INSERT CONTACT METHOD].
64
- All complaints will be reviewed and investigated promptly and fairly.
65
-
66
- All community leaders are obligated to respect the privacy and security of the
67
- reporter of any incident.
68
-
69
- ## Enforcement Guidelines
70
-
71
- Community leaders will follow these Community Impact Guidelines in determining
72
- the consequences for any action they deem in violation of this Code of Conduct:
73
-
74
- ### 1. Correction
75
-
76
- **Community Impact**: Use of inappropriate language or other behavior deemed
77
- unprofessional or unwelcome in the community.
78
-
79
- **Consequence**: A private, written warning from community leaders, providing
80
- clarity around the nature of the violation and an explanation of why the
81
- behavior was inappropriate. A public apology may be requested.
82
-
83
- ### 2. Warning
84
-
85
- **Community Impact**: A violation through a single incident or series of
86
- actions.
87
-
88
- **Consequence**: A warning with consequences for continued behavior. No
89
- interaction with the people involved, including unsolicited interaction with
90
- those enforcing the Code of Conduct, for a specified period of time. This
91
- includes avoiding interactions in community spaces as well as external channels
92
- like social media. Violating these terms may lead to a temporary or permanent
93
- ban.
94
-
95
- ### 3. Temporary Ban
96
-
97
- **Community Impact**: A serious violation of community standards, including
98
- sustained inappropriate behavior.
99
-
100
- **Consequence**: A temporary ban from any sort of interaction or public
101
- communication with the community for a specified period of time. No public or
102
- private interaction with the people involved, including unsolicited interaction
103
- with those enforcing the Code of Conduct, is allowed during this period.
104
- Violating these terms may lead to a permanent ban.
105
-
106
- ### 4. Permanent Ban
107
-
108
- **Community Impact**: Demonstrating a pattern of violation of community
109
- standards, including sustained inappropriate behavior, harassment of an
110
- individual, or aggression toward or disparagement of classes of individuals.
111
-
112
- **Consequence**: A permanent ban from any sort of public interaction within the
113
- community.
114
-
115
- ## Attribution
116
-
117
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
- version 2.1, available at
119
- [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
-
121
- Community Impact Guidelines were inspired by
122
- [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
-
124
- For answers to common questions about this code of conduct, see the FAQ at
125
- [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
- [https://www.contributor-covenant.org/translations][translations].
127
-
128
- [homepage]: https://www.contributor-covenant.org
129
- [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
- [Mozilla CoC]: https://github.com/mozilla/diversity
131
- [FAQ]: https://www.contributor-covenant.org/faq
132
- [translations]: https://www.contributor-covenant.org/translations
data/lib/.DS_Store DELETED
Binary file