ny_frb_as_dataframe 0.2.0 → 0.2.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 +4 -4
- data/.DS_Store +0 -0
- data/CHANGELOG.md +6 -0
- data/README.md +36 -1
- data/lib/ny_frb_as_dataframe/hhdc.rb +148 -102
- data/lib/ny_frb_as_dataframe/version.rb +1 -1
- data/ny_frb_as_dataframe.gemspec +2 -2
- data/reqs/executed_plans.md +3 -0
- data/reqs/explicitly_stated_requirements.md +5 -0
- data/reqs/requirements/REQ-001.md +15 -0
- metadata +7 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 162dee7d9d8406fc00799a4e7fac2cc521266d19f5654c170a53357c69498b58
|
|
4
|
+
data.tar.gz: 78b8e0adec44302459f0d8a5431d31d997802828465131a7c82f21d9af8bfff3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3c5343ba7ecfa4a5cc9ba66e0144b2554f30160dd3613a5e7d70376b7339477f10a31ec35859b0d9cc96fbf4d64b1f0862cc1e4984be47476428452db7ed7c20
|
|
7
|
+
data.tar.gz: 46a9beb59c45eb41907e63fb268ab0441e528e41d649ca7bbcb982f6c1fa6c49bbec0af98bea859f131956e5a46d46d04341157a7d8005a869cf02f1cfaa19b1
|
data/.DS_Store
CHANGED
|
Binary file
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.2.1] - 2026-09-09
|
|
4
|
+
|
|
5
|
+
- Parse HHDC workbooks with Roo instead of SimpleXlsxReader. This drops `auto_slurp` (absent on 1.0.5) and skips chart-only sheets that have no dimension node.
|
|
6
|
+
- Match sheet titles and column headers after stripping HTML, asterisks, and extra whitespace, case-insensitively (`To 90+ days late` matches `To 90+ days Late`).
|
|
7
|
+
- Merge continuation rows that carry values for the preceding quarter (Credit Limit / HE Revolving layout).
|
|
8
|
+
|
|
3
9
|
## [0.2.0] - 2026-08-28
|
|
4
10
|
|
|
5
11
|
- Required Ruby version >= 3.3
|
data/README.md
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Up to date remote economic data access for ruby, using Polars dataframes.
|
|
4
4
|
|
|
5
|
-
This package will fetch economic and financial information from the Federal Reserve Bank of NY (specifically several time series from the FRB NY's Household Credit and Debt report), and return the results as a Polars dataframe.
|
|
5
|
+
This package will fetch economic and financial information from the Federal Reserve Bank of NY (specifically several time series from the FRB NY's Household Credit and Debt report), and return the results as a Polars dataframe.
|
|
6
|
+
|
|
7
|
+
`NyFrbAsDataframe::Hhdc#fetch` downloads the latest `hhd_c_report_YYYYqN.xlsx` and parses data sheets with Roo. Sheet titles and headers are matched after stripping HTML, asterisks, and extra whitespace (case-insensitive). Chart-only sheets are skipped. The column names listed below are the names this gem emits; they are not always identical to the labels printed in the workbook.
|
|
6
8
|
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
@@ -288,12 +290,45 @@ The attributes that can be queried at this time are
|
|
|
288
290
|
* "Median Riskscore for New Car Loan"
|
|
289
291
|
* "Bottom 25%ile Riskscore for New Car Loan"
|
|
290
292
|
* "Bottom 10%ile Riskscore for New Car Loan"
|
|
293
|
+
* "CC Balance ($T)"
|
|
294
|
+
* "CC Avail Credit ($T)"
|
|
295
|
+
* "CC Limit ($T)"
|
|
296
|
+
* "HELOC Balance ($T)"
|
|
297
|
+
* "HELOC Avail Credit ($T)"
|
|
298
|
+
* "HELOC Limit ($T)"
|
|
291
299
|
* "% Balances Current"
|
|
292
300
|
* "% Balances 30d late"
|
|
293
301
|
* "% Balances 60d late"
|
|
294
302
|
* "% Balances 90d late"
|
|
295
303
|
* "% Balances 120+d late"
|
|
296
304
|
* "% Balances Severely Impair"
|
|
305
|
+
* "% Mort Bal 90d+ late"
|
|
306
|
+
* "% HELOC Bal 90d+ late"
|
|
307
|
+
* "% Car Loan Bal 90d+ late"
|
|
308
|
+
* "% CC Bal 90d+ late"
|
|
309
|
+
* "% Student Loan Bal 90d+ late"
|
|
310
|
+
* "% Other Bal 90d+ late"
|
|
311
|
+
* "% All Bal 90d+ late"
|
|
312
|
+
* "% Car Loan Bal 0d->30d+ Late"
|
|
313
|
+
* "% CC Bal 0d->30d+ Late"
|
|
314
|
+
* "% Mort Bal 0d->30d+ Late"
|
|
315
|
+
* "% HELOC Bal 0d->30d+ Late"
|
|
316
|
+
* "% Student Loan Bal 0d->30d+ Late"
|
|
317
|
+
* "% Other Bal 0d->30d+ Late"
|
|
318
|
+
* "% All Bal 0d->30d+ Late"
|
|
319
|
+
* "% Car Loan Bal ->90d+ Late"
|
|
320
|
+
* "% CC Bal ->90d+ Late"
|
|
321
|
+
* "% Mort Bal ->90d+ Late"
|
|
322
|
+
* "% HELOC Bal ->90d+ Late"
|
|
323
|
+
* "% Student Loan Bal ->90d+ Late"
|
|
324
|
+
* "% Other Bal ->90d+ Late"
|
|
325
|
+
* "% All Bal ->90d+ Late"
|
|
326
|
+
* "Qtrly % Mort 0->30-60d late"
|
|
327
|
+
* "Qtrly % Mort ->90d+ Late"
|
|
328
|
+
* "Qtrly % Mort % 30-60d->0d Late"
|
|
329
|
+
* "Qtrly % Mort 30-60d->90d+ Late"
|
|
330
|
+
* "Num Consumers w New Foreclosure"
|
|
331
|
+
* "Num Consumers w New Bankruptcy"
|
|
297
332
|
* "% Consumers w Collection"
|
|
298
333
|
* "Avg Collection Amt"
|
|
299
334
|
* "Avg Total Debt Bal for 18-29 yo ($T)"
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
require 'set'
|
|
1
2
|
require 'polars-df'
|
|
2
3
|
require 'httparty'
|
|
3
|
-
require '
|
|
4
|
+
require 'roo'
|
|
4
5
|
require 'csv'
|
|
6
|
+
require 'tempfile'
|
|
5
7
|
require 'active_support/core_ext/date/calculations'
|
|
8
|
+
require 'active_support/core_ext/object/blank'
|
|
9
|
+
require 'active_support/core_ext/object/try'
|
|
6
10
|
require 'active_support/core_ext/string/conversions'
|
|
7
11
|
|
|
8
12
|
|
|
@@ -12,6 +16,36 @@ module NyFrbAsDataframe
|
|
|
12
16
|
include ::HTTParty
|
|
13
17
|
base_uri 'https://www.newyorkfed.org/medialibrary/interactives/householdcredit/data/xls/'
|
|
14
18
|
|
|
19
|
+
SHEET_COLUMNS =
|
|
20
|
+
{
|
|
21
|
+
'Total Debt Balance and Its Composition' => {'Mortgage' => 'Mort Debt Balance ($T)', 'HE Revolving' => 'HELOC Debt Balance ($T)', 'Auto Loan' => 'Car Loan Debt Balance ($T)', 'Credit Card' => 'CC Debt Balance ($T)', 'Student Loan' => 'Student Debt Balance ($T)', 'Other' => 'Other Debt Balance ($T)', 'Total' => 'Total Debt Balance ($T)'},
|
|
22
|
+
'Number of Accounts by Loan Type' => {'Auto Loan' => 'Num Car Loan Accts (M)', 'Credit Card' => 'Num CC Accts (M)', 'Mortgage' => 'Num Mort Accts (M)', 'HE Revolving' => 'Num HELOC Accts (M)'},
|
|
23
|
+
'Total Number of New and Closed Accounts and Consumer Credit Inquiries' => {'inquiry within 6 mo' => 'Num Credit Inquiries and New Accts', 'closed within 12 mo' => 'Num New Credit Accts Closed in 12 mo', 'open within 12 mo' => 'Num New Credit Accts Open after 12 mo'},
|
|
24
|
+
'Mortgage Origination Volume by Riskscore' => {'<620' => 'New Mort w Riskscore <620 ($B)','620-659' => 'New Mort w Riskscore 620-659 ($B)','660-719' => 'New Mort w Riskscore 660-719 ($B)','720-759' => 'New Mort w Riskscore 720-759 ($B)','760+' => 'New Mort w Riskscore 760+ ($B)','TOTAL' => 'New Mort ($B)'},
|
|
25
|
+
'Distribution of Riskscore of Mortgage Originations' => {'Median' => 'Median Riskscore for New Mort', '25th percentile' => 'Bottom 25%ile Riskscore for New Mort', '10th percentile' => 'Bottom 10%ile Riskscore for New Mort'},
|
|
26
|
+
'Auto Loan Origination Volume by Riskscore' => {'<620' => 'New Car Loans w Riskscore <620 ($B)','620-659' => 'New Car Loans w Riskscore 620-659 ($B)','660-719' => 'New Car Loans w Riskscore 660-719 ($B)','720-759' => 'New Car Loans w Riskscore 720-759 ($B)','760+' => 'New Car Loans w Riskscore 760+ ($B)','TOTAL' => 'All New Car Loans ($B)'},
|
|
27
|
+
'Distribution of Riskscore of Auto Loan Originations' => {'Median' => 'Median Riskscore for New Car Loan', '25th percentile' => 'Bottom 25%ile Riskscore for New Car Loan', '10th percentile' => 'Bottom 10%ile Riskscore for New Car Loan'},
|
|
28
|
+
'Credit Limit and Balance for Credit Cards and HE Revolving' => {'Credit Card Balance' => 'CC Balance ($T)', 'Credit Card Available Credit' => 'CC Avail Credit ($T)', 'Credit Card Limit' => 'CC Limit ($T)', 'HE Revolving Balance' => 'HELOC Balance ($T)', 'HE Revolving Available Credit' => 'HELOC Avail Credit ($T)', 'HE Revolving Limit' => 'HELOC Limit ($T)'},
|
|
29
|
+
'Total Balance by Delinquency Status' => {'Current' => '% Balances Current', '30 days late' => '% Balances 30d late', '60 days late' => '% Balances 60d late', '90 days late' => '% Balances 90d late', '120+ days late' => '% Balances 120+d late', 'Severely Derogatory' => '% Balances Severely Impair'},
|
|
30
|
+
'Percent of Balance 90+ Days Delinquent by Loan Type' => {'MORTGAGE' => '% Mort Bal 90d+ late', 'HELOC' => '% HELOC Bal 90d+ late', 'AUTO' => '% Car Loan Bal 90d+ late', 'CC' => '% CC Bal 90d+ late', 'STUDENT LOAN' => '% Student Loan Bal 90d+ late', 'OTHER' => '% Other Bal 90d+ late', 'ALL' => '% All Bal 90d+ late'},
|
|
31
|
+
'New Delinquent* Balances by Loan Type' => {'AUTO' => '% Car Loan Bal 0d->30d+ Late', 'CC' => '% CC Bal 0d->30d+ Late', 'MORTGAGE' => '% Mort Bal 0d->30d+ Late', 'HELOC' => '% HELOC Bal 0d->30d+ Late', 'STUDENT LOAN' => '% Student Loan Bal 0d->30d+ Late', 'OTHER' => '% Other Bal 0d->30d+ Late', 'Total' => '% All Bal 0d->30d+ Late'},
|
|
32
|
+
'New Seriously Delinquent* Balances by Loan Type' => {'AUTO' => '% Car Loan Bal ->90d+ Late', 'CC' => '% CC Bal ->90d+ Late', 'MORTGAGE' => '% Mort Bal ->90d+ Late', 'HELOC' => '% HELOC Bal ->90d+ Late', 'STUDENT LOAN' => '% Student Loan Bal ->90d+ Late', 'OTHER' => '% Other Bal ->90d+ Late', 'ALL' => '% All Bal ->90d+ Late'},
|
|
33
|
+
'Quarterly Transition Rates for Current Mortgage Accounts' => {'To 30-60 days late' => 'Qtrly % Mort 0->30-60d late', 'To 90+ days Late' => 'Qtrly % Mort ->90d+ Late'},
|
|
34
|
+
'Quarterly Transition Rates for 30-60 Day Late Mortgage Accounts' => {'To current' => 'Qtrly % Mort % 30-60d->0d Late', 'To 90+ days Late' => 'Qtrly % Mort 30-60d->90d+ Late'},
|
|
35
|
+
'Number of Consumers with New Foreclosures and Bankruptcies' => {'foreclosure' => 'Num Consumers w New Foreclosure', 'bankruptcy' => 'Num Consumers w New Bankruptcy'},
|
|
36
|
+
'Third Party Collections' => {'proportion of consumers with collection' => '% Consumers w Collection', 'average collection amount per person with item' => 'Avg Collection Amt'},
|
|
37
|
+
'Total Debt Balance by Age' => {'18-29' => 'Avg Total Debt Bal for 18-29 yo ($T)', '30-39' => 'Avg Total Debt Bal for 30-39 yo ($T)', '40-49' => 'Avg Total Debt Bal for 40-49 yo ($T)', '50-59' => 'Avg Total Debt Bal for 50-59 yo ($T)', '60-69' => 'Avg Total Debt Bal for 60-69 yo ($T)', '70+' => 'Avg Total Debt Bal for 70+ yo ($T)'},
|
|
38
|
+
'Auto Loan Originations By Age' => {'18-29' => 'New Car Loans for 18-29 yo ($B)', '30-39' => 'New Car Loans for 30-39 yo ($B)', '40-49' => 'New Car Loans for 40-49 yo ($B)', '50-59' => 'New Car Loans for 50-59 yo ($B)', '60-69' => 'New Car Loans for 60-69 yo ($B)', '70+' => 'New Car Loans for 70+ yo ($B)'},
|
|
39
|
+
'Total Mortgage Orginations by Age' => {'18-29' => 'New Mort for 18-29 yo ($B)', '30-39' => 'New Mort for 30-39 yo ($B)', '40-49' => 'New Mort for 40-49 yo ($B)', '50-59' => 'New Mort for 50-59 yo ($B)', '60-69' => 'New Mort for 60-69 yo ($B)', '70+' => 'New Mort for 70+ yo ($B)'},
|
|
40
|
+
'Transition into Serious Delinquency (90+) by Age' => {'18-29' => 'Qtrly % ->90d+ late for 18-29 yo', '30-39' => 'Qtrly % ->90d+ late for 30-39 yo', '40-49' => 'Qtrly % ->90d+ late for 40-49 yo', '50-59' => 'Qtrly % ->90d+ late for 50-59 yo', '60-69' => 'Qtrly % ->90d+ late for 60-69 yo', '70+' => 'Qtrly % ->90d+ late for 70+ yo', 'all' => 'Qtrly % ->90d+ late'},
|
|
41
|
+
'Transition into Serious Delinquency (90+) for Mortgages by Age' => {'18-29' => 'Qtrly % Mort ->90d+ late for 18-29 yo', '30-39' => 'Qtrly % Mort ->90d+ late for 30-39 yo', '40-49' => 'Qtrly % Mort ->90d+ late for 40-49 yo', '50-59' => 'Qtrly % Mort ->90d+ late for 50-59 yo', '60-69' => 'Qtrly % Mort ->90d+ late for 60-69 yo', '70+' => 'Qtrly % Mort ->90d+ late for 70+ yo', 'all' => 'Qtrly % Mort ->90d+ late'},
|
|
42
|
+
'Transition into Serious Delinquency (90+) for Auto Loans by Age' => {'18-29' => 'Qtrly % Car Loans ->90d+ late for 18-29 yo', '30-39' => 'Qtrly % Car Loans ->90d+ late for 30-39 yo', '40-49' => 'Qtrly % Car Loans ->90d+ late for 40-49 yo', '50-59' => 'Qtrly % Car Loans ->90d+ late for 50-59 yo', '60-69' => 'Qtrly % Car Loans ->90d+ late for 60-69 yo', '70+' => 'Qtrly % Car Loans ->90d+ late for 70+ yo', 'all' => 'Qtrly % Car Loans ->90d+ late'},
|
|
43
|
+
'Transition into Serious Delinquency (90+) for Credit Cards by Age' => {'18-29' => 'Qtrly % CC ->90d+ late for 18-29 yo', '30-39' => 'Qtrly % CC ->90d+ late for 30-39 yo', '40-49' => 'Qtrly % CC ->90d+ late for 40-49 yo', '50-59' => 'Qtrly % CC ->90d+ late for 50-59 yo', '60-69' => 'Qtrly % CC ->90d+ late for 60-69 yo', '70+' => 'Qtrly % CC ->90d+ late for 70+ yo', 'all' => 'Qtrly % CC ->90d+ late'},
|
|
44
|
+
'Transition into Serious Delinquency (90+) for Student Loans by Age' => {'18-29' => 'Qtrly % Student Loan ->90d+ late for 18-29 yo', '30-39' => 'Qtrly % Student Loan ->90d+ late for 30-39 yo', '40-49' => 'Qtrly % Student Loan ->90d+ late for 40-49 yo', 'all' => 'Qtrly % Student Loan ->90d+ late'},
|
|
45
|
+
'New Foreclosures By Age' => {'18-29' => 'New Foreclosures for 18-29 yo (000)', '30-39' => 'New Foreclosures for 30-39 yo (000)', '40-49' => 'New Foreclosures for 40-49 yo (000)', '50-59' => 'New Foreclosures for 50-59 yo (000)', '60-69' => 'New Foreclosures for 60-69 yo (000)', '70+' => 'New Foreclosures for 70+ yo (000)'},
|
|
46
|
+
'New Bankruptcy By Age' => {'18-29' => 'New Bankruptcies for 18-29 yo (000)', '30-39' => 'New Bankruptcies for 30-39 yo (000)', '40-49' => 'New Bankruptcies for 40-49 yo (000)', '50-59' => 'New Bankruptcies for 50-59 yo (000)', '60-69' => 'New Bankruptcies for 60-69 yo (000)', '70+' => 'New Bankruptcies for 70+ yo (000)'}
|
|
47
|
+
}.freeze
|
|
48
|
+
|
|
15
49
|
attr_reader :tag
|
|
16
50
|
|
|
17
51
|
def initialize(series = nil)
|
|
@@ -21,8 +55,6 @@ module NyFrbAsDataframe
|
|
|
21
55
|
def fetch(start: nil, fin: nil)
|
|
22
56
|
df = nil
|
|
23
57
|
|
|
24
|
-
SimpleXlsxReader.configuration.auto_slurp = true
|
|
25
|
-
|
|
26
58
|
Tempfile.open(['foo', '.xlsx'], '/tmp', binmode: true) do |f|
|
|
27
59
|
qtr = Date.today.year * 4 + (Date.today.month.div(3)+1)
|
|
28
60
|
dta = nil
|
|
@@ -38,139 +70,153 @@ module NyFrbAsDataframe
|
|
|
38
70
|
f.write(resp)
|
|
39
71
|
f.rewind
|
|
40
72
|
|
|
41
|
-
xlsx_file =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
'Total Debt Balance and Its Composition' => {'Mortgage' => 'Mort Debt Balance ($T)', 'HE Revolving' => 'HELOC Debt Balance ($T)', 'Auto Loan' => 'Car Loan Debt Balance ($T)', 'Credit Card' => 'CC Debt Balance ($T)', 'Student Loan' => 'Student Debt Balance ($T)', 'Other' => 'Other Debt Balance ($T)', 'Total' => 'Total Debt Balance ($T)'},
|
|
46
|
-
'Number of Accounts by Loan Type' => {'Auto Loan' => 'Num Car Loan Accts (M)', 'Credit Card' => 'Num CC Accts (M)', 'Mortgage' => 'Num Mort Accts (M)', 'HE Revolving' => 'Num HELOC Accts (M)'},
|
|
47
|
-
'Total Number of New and Closed Accounts and Consumer Credit Inquiries' => {'inquiry within 6 mo' => 'Num Credit Inquiries and New Accts', 'closed within 12 mo' => 'Num New Credit Accts Closed in 12 mo', 'open within 12 mo' => 'Num New Credit Accts Open after 12 mo'},
|
|
48
|
-
'Mortgage Origination Volume by Riskscore' => {'<620' => 'New Mort w Riskscore <620 ($B)','620-659' => 'New Mort w Riskscore 620-659 ($B)','660-719' => 'New Mort w Riskscore 660-719 ($B)','720-759' => 'New Mort w Riskscore 720-759 ($B)','760+' => 'New Mort w Riskscore 760+ ($B)','TOTAL' => 'New Mort ($B)'},
|
|
49
|
-
'Distribution of Riskscore of Mortgage Originations' => {'Median' => 'Median Riskscore for New Mort', '25th percentile' => 'Bottom 25%ile Riskscore for New Mort', '10th percentile' => 'Bottom 10%ile Riskscore for New Mort'},
|
|
50
|
-
'Auto Loan Origination Volume by Riskscore' => {'<620' => 'New Car Loans w Riskscore <620 ($B)','620-659' => 'New Car Loans w Riskscore 620-659 ($B)','660-719' => 'New Car Loans w Riskscore 660-719 ($B)','720-759' => 'New Car Loans w Riskscore 720-759 ($B)','760+' => 'New Car Loans w Riskscore 760+ ($B)','TOTAL' => 'All New Car Loans ($B)'},
|
|
51
|
-
'Distribution of Riskscore of Auto Loan Originations' => {'Median' => 'Median Riskscore for New Car Loan', '25th percentile' => 'Bottom 25%ile Riskscore for New Car Loan', '10th percentile' => 'Bottom 10%ile Riskscore for New Car Loan'},
|
|
52
|
-
'Credit Limit and Balance for Credit Cards and HE Revolving' => {'Credit Card Balance' => 'CC Balance ($T)', 'Credit Card Available Credit' => 'CC Avail Credit ($T)', 'Credit Card Limit' => 'CC Limit ($T)', 'HE Revolving Balance' => 'HELOC Balance ($T)', 'HE Revolving Available Credit' => 'HELOC Avail Credit ($T)', 'HE Revolving Limit' => 'HELOC Limit ($T)'},
|
|
53
|
-
'Total Balance by Delinquency Status' => {'Current' => '% Balances Current', '30 days late' => '% Balances 30d late', '60 days late' => '% Balances 60d late', '90 days late' => '% Balances 90d late', '120+ days late' => '% Balances 120+d late', 'Severely Derogatory' => '% Balances Severely Impair'},
|
|
54
|
-
'Percent of Balance 90+ Days Delinquent by Loan Type' => {'MORTGAGE' => '% Mort Bal 90d+ late', 'HELOC' => '% HELOC Bal 90d+ late', 'AUTO' => '% Car Loan Bal 90d+ late', 'CC' => '% CC Bal 90d+ late', 'STUDENT LOAN' => '% Student Loan Bal 90d+ late', 'OTHER' => '% Other Bal 90d+ late', 'ALL' => '% All Bal 90d+ late'},
|
|
55
|
-
'New Delinquent* Balances by Loan Type' => {'AUTO' => '% Car Loan Bal 0d->30d+ Late', 'CC' => '% CC Bal 0d->30d+ Late', 'MORTGAGE' => '% Mort Bal 0d->30d+ Late', 'HELOC' => '% HELOC Bal 0d->30d+ Late', 'STUDENT LOAN' => '% Student Loan Bal 0d->30d+ Late', 'OTHER' => '% Other Bal 0d->30d+ Late', 'Total' => '% All Bal 0d->30d+ Late'},
|
|
56
|
-
'New Seriously Delinquent* Balances by Loan Type' => {'AUTO' => '% Car Loan Bal ->90d+ Late', 'CC' => '% CC Bal ->90d+ Late', 'MORTGAGE' => '% Mort Bal ->90d+ Late', 'HELOC' => '% HELOC Bal ->90d+ Late', 'STUDENT LOAN' => '% Student Loan Bal ->90d+ Late', 'OTHER' => '% Other Bal ->90d+ Late', 'ALL' => '% All Bal ->90d+ Late'},
|
|
57
|
-
'Quarterly Transition Rates for Current Mortgage Accounts' => {'To 30-60 days late' => 'Qtrly % Mort 0->30-60d late', 'To 90+ days Late' => 'Qtrly % Mort ->90d+ Late'},
|
|
58
|
-
'Quarterly Transition Rates for 30-60 Day Late Mortgage Accounts' => {'To current' => 'Qtrly % Mort % 30-60d->0d Late', 'To 90+ days Late' => 'Qtrly % Mort 30-60d->90d+ Late'},
|
|
59
|
-
'Number of Consumers with New Foreclosures and Bankruptcies' => {'foreclosure' => 'Num Consumers w New Foreclosure', 'bankruptcy' => 'Num Consumers w New Bankruptcy'},
|
|
60
|
-
'Third Party Collections' => {'proportion of consumers with collection' => '% Consumers w Collection', 'average collection amount per person with item' => 'Avg Collection Amt'},
|
|
61
|
-
'Total Debt Balance by Age' => {'18-29' => 'Avg Total Debt Bal for 18-29 yo ($T)', '30-39' => 'Avg Total Debt Bal for 30-39 yo ($T)', '40-49' => 'Avg Total Debt Bal for 40-49 yo ($T)', '50-59' => 'Avg Total Debt Bal for 50-59 yo ($T)', '60-69' => 'Avg Total Debt Bal for 60-69 yo ($T)', '70+' => 'Avg Total Debt Bal for 70+ yo ($T)'},
|
|
62
|
-
'Auto Loan Originations By Age' => {'18-29' => 'New Car Loans for 18-29 yo ($B)', '30-39' => 'New Car Loans for 30-39 yo ($B)', '40-49' => 'New Car Loans for 40-49 yo ($B)', '50-59' => 'New Car Loans for 50-59 yo ($B)', '60-69' => 'New Car Loans for 60-69 yo ($B)', '70+' => 'New Car Loans for 70+ yo ($B)'},
|
|
63
|
-
'Total Mortgage Orginations by Age' => {'18-29' => 'New Mort for 18-29 yo ($B)', '30-39' => 'New Mort for 30-39 yo ($B)', '40-49' => 'New Mort for 40-49 yo ($B)', '50-59' => 'New Mort for 50-59 yo ($B)', '60-69' => 'New Mort for 60-69 yo ($B)', '70+' => 'New Mort for 70+ yo ($B)'},
|
|
64
|
-
'Transition into Serious Delinquency (90+) by Age' => {'18-29' => 'Qtrly % ->90d+ late for 18-29 yo', '30-39' => 'Qtrly % ->90d+ late for 30-39 yo', '40-49' => 'Qtrly % ->90d+ late for 40-49 yo', '50-59' => 'Qtrly % ->90d+ late for 50-59 yo', '60-69' => 'Qtrly % ->90d+ late for 60-69 yo', '70+' => 'Qtrly % ->90d+ late for 70+ yo', 'all' => 'Qtrly % ->90d+ late'},
|
|
65
|
-
'Transition into Serious Delinquency (90+) for Mortgages by Age' => {'18-29' => 'Qtrly % Mort ->90d+ late for 18-29 yo', '30-39' => 'Qtrly % Mort ->90d+ late for 30-39 yo', '40-49' => 'Qtrly % Mort ->90d+ late for 40-49 yo', '50-59' => 'Qtrly % Mort ->90d+ late for 50-59 yo', '60-69' => 'Qtrly % Mort ->90d+ late for 60-69 yo', '70+' => 'Qtrly % Mort ->90d+ late for 70+ yo', 'all' => 'Qtrly % Mort ->90d+ late'},
|
|
66
|
-
'Transition into Serious Delinquency (90+) for Auto Loans by Age' => {'18-29' => 'Qtrly % Car Loans ->90d+ late for 18-29 yo', '30-39' => 'Qtrly % Car Loans ->90d+ late for 30-39 yo', '40-49' => 'Qtrly % Car Loans ->90d+ late for 40-49 yo', '50-59' => 'Qtrly % Car Loans ->90d+ late for 50-59 yo', '60-69' => 'Qtrly % Car Loans ->90d+ late for 60-69 yo', '70+' => 'Qtrly % Car Loans ->90d+ late for 70+ yo', 'all' => 'Qtrly % Car Loans ->90d+ late'},
|
|
67
|
-
'Transition into Serious Delinquency (90+) for Credit Cards by Age' => {'18-29' => 'Qtrly % CC ->90d+ late for 18-29 yo', '30-39' => 'Qtrly % CC ->90d+ late for 30-39 yo', '40-49' => 'Qtrly % CC ->90d+ late for 40-49 yo', '50-59' => 'Qtrly % CC ->90d+ late for 50-59 yo', '60-69' => 'Qtrly % CC ->90d+ late for 60-69 yo', '70+' => 'Qtrly % CC ->90d+ late for 70+ yo', 'all' => 'Qtrly % CC ->90d+ late'},
|
|
68
|
-
'Transition into Serious Delinquency (90+) for Student Loans by Age' => {'18-29' => 'Qtrly % Student Loan ->90d+ late for 18-29 yo', '30-39' => 'Qtrly % Student Loan ->90d+ late for 30-39 yo', '40-49' => 'Qtrly % Student Loan ->90d+ late for 40-49 yo', '50-59' => 'Qtrly % Student Loan ->90d+ late for 50-59 yo', 'all' => 'Qtrly % Student Loan ->90d+ late'},
|
|
69
|
-
'New Foreclosures By Age' => {'18-29' => 'New Foreclosures for 18-29 yo (000)', '30-39' => 'New Foreclosures for 30-39 yo (000)', '40-49' => 'New Foreclosures for 40-49 yo (000)', '50-59' => 'New Foreclosures for 50-59 yo (000)', '60-69' => 'New Foreclosures for 60-69 yo (000)', '70+' => 'New Foreclosures for 70+ yo (000)'},
|
|
70
|
-
'New Bankruptcy By Age' => {'18-29' => 'New Bankruptcies for 18-29 yo (000)', '30-39' => 'New Bankruptcies for 30-39 yo (000)', '40-49' => 'New Bankruptcies for 40-49 yo (000)', '50-59' => 'New Bankruptcies for 50-59 yo (000)', '60-69' => 'New Bankruptcies for 60-69 yo (000)', '70+' => 'New Bankruptcies for 70+ yo (000)'}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
# Polars::Config.set_tbl_cols(-1)
|
|
73
|
+
xlsx_file = Roo::Excelx.new(f.path)
|
|
74
|
+
title_index = _index_by_normalized_key(SHEET_COLUMNS)
|
|
75
|
+
remaining = title_index.keys.to_set
|
|
76
|
+
|
|
74
77
|
Polars::Config.set_tbl_rows(-1)
|
|
75
78
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
nm = sht.name
|
|
79
|
-
|
|
80
|
-
begin
|
|
81
|
-
_ = sht.rows
|
|
82
|
-
pg_nm_text = sht.rows
|
|
83
|
-
pg_nm_text = pg_nm_text.first
|
|
84
|
-
rescue
|
|
85
|
-
begin
|
|
86
|
-
pg_nm_text = sht.rows.first
|
|
87
|
-
rescue
|
|
88
|
-
done = true
|
|
89
|
-
end
|
|
90
|
-
end
|
|
79
|
+
xlsx_file.sheets.each do |sheet_name|
|
|
80
|
+
break if remaining.empty?
|
|
91
81
|
|
|
92
|
-
|
|
82
|
+
rows = _sheet_rows(xlsx_file, sheet_name)
|
|
83
|
+
next if rows.nil? || rows.empty?
|
|
93
84
|
|
|
94
|
-
pg_nm_text =
|
|
95
|
-
next
|
|
85
|
+
pg_nm_text = title_index[_normalize_key(rows.first&.first)]
|
|
86
|
+
next if pg_nm_text.nil?
|
|
87
|
+
|
|
88
|
+
remaining.delete(_normalize_key(pg_nm_text))
|
|
89
|
+
header_norm_to_out = _index_by_normalized_key(SHEET_COLUMNS[pg_nm_text])
|
|
96
90
|
|
|
97
91
|
header_found = false
|
|
98
92
|
csv_txt = []
|
|
93
|
+
pending = nil
|
|
99
94
|
|
|
100
|
-
|
|
101
|
-
r = row
|
|
102
|
-
|
|
103
|
-
if header_found == false
|
|
104
|
-
if r.length > (r - col_nm_hsh[pg_nm_text].keys).length
|
|
105
|
-
header_found = true
|
|
106
|
-
0.upto(r.length-1).to_a.each do |ndex|
|
|
107
|
-
if ndex.zero?
|
|
108
|
-
r[ndex] = 'Timestamps_'
|
|
109
|
-
else
|
|
110
|
-
col_nm_hsh[pg_nm_text].keys.each do |k|
|
|
111
|
-
r[ndex] = col_nm_hsh[pg_nm_text][k] if r[ndex] == k
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|
|
95
|
+
rows.each do |row|
|
|
96
|
+
r = row.dup
|
|
116
97
|
|
|
117
|
-
|
|
118
|
-
|
|
98
|
+
unless header_found
|
|
99
|
+
if _header_row?(r, header_norm_to_out)
|
|
100
|
+
header_found = true
|
|
101
|
+
csv_txt << _csv_line(_rename_header_row(r, header_norm_to_out))
|
|
102
|
+
end
|
|
103
|
+
next
|
|
104
|
+
end
|
|
119
105
|
|
|
120
106
|
break if r.compact.length.zero?
|
|
121
107
|
|
|
122
|
-
|
|
123
|
-
if
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
r[0] = r[0].to_date.beginning_of_quarter
|
|
108
|
+
date = _parse_quarter_date(r[0])
|
|
109
|
+
if date
|
|
110
|
+
csv_txt << _csv_line(_filled_row(pending)) if pending
|
|
111
|
+
r[0] = date
|
|
112
|
+
pending = r
|
|
113
|
+
elsif pending
|
|
114
|
+
r.each_index { |i| pending[i] = r[i] if pending[i].nil? && !r[i].nil? }
|
|
130
115
|
end
|
|
116
|
+
end
|
|
131
117
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
rr = rr.reverse.drop_while(&:nil?).reverse
|
|
135
|
-
next if rr.compact.length.zero?
|
|
136
|
-
csv_txt << rr.join(',')
|
|
137
|
-
|
|
138
|
-
end # End per-line analysis
|
|
118
|
+
csv_txt << _csv_line(_filled_row(pending)) if pending
|
|
119
|
+
next if csv_txt.length < 2
|
|
139
120
|
|
|
140
121
|
csv_dta = CSV.parse(csv_txt.join("\n"), headers: true, converters: [:numeric])
|
|
141
122
|
csv_dta.delete(nil)
|
|
142
123
|
|
|
143
|
-
keys = csv_dta.headers.compact.intersection(['Timestamps_'] +
|
|
124
|
+
keys = csv_dta.headers.compact.intersection(['Timestamps_'] + SHEET_COLUMNS[pg_nm_text].values)
|
|
144
125
|
vals = csv_dta.to_a[1..-1].map{|r| (r + [''] * keys.length)[0..keys.length-1] }.transpose
|
|
145
126
|
|
|
146
127
|
tmp_df = {}; (0..(keys.length-1)).to_a.each{|i| tmp_df[keys[i]] = vals[i]}
|
|
147
128
|
|
|
148
129
|
tmp_df = Polars::DataFrame.new(tmp_df)
|
|
149
|
-
|
|
150
|
-
|
|
130
|
+
fin_date = fin.try(:to_date)
|
|
131
|
+
start_date = start.try(:to_date)
|
|
132
|
+
tmp_df = tmp_df.filter(Polars.col('Timestamps_') <= fin_date.to_s) unless fin_date.nil?
|
|
133
|
+
tmp_df = tmp_df.filter(Polars.col('Timestamps_') >= start_date.to_s) unless start_date.nil?
|
|
151
134
|
tmp_df.sort!('Timestamps_')
|
|
152
135
|
|
|
153
136
|
if df.nil?
|
|
154
|
-
df = tmp_df.dup
|
|
155
|
-
else
|
|
137
|
+
df = tmp_df.dup
|
|
138
|
+
else
|
|
156
139
|
df = df.join(tmp_df, on: 'Timestamps_', how: 'full')
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
tmp_timestamps.length.times.each {|ndex| tmp_timestamps[ndex] ||= tmp_timestamps__[ndex] }
|
|
161
|
-
df.replace('Timestamps_', Polars::Series.new(tmp_timestamps))
|
|
162
|
-
df = df.drop(['Timestamps__right'])
|
|
140
|
+
df = df.with_columns(
|
|
141
|
+
Polars.coalesce(Polars.col('Timestamps_'), Polars.col('Timestamps__right')).alias('Timestamps_')
|
|
142
|
+
).drop('Timestamps__right')
|
|
163
143
|
end
|
|
164
144
|
df = df.sort('Timestamps_')
|
|
165
|
-
|
|
166
|
-
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
raise 'HHDC workbook contained no recognized data sheets' if df.nil?
|
|
167
148
|
|
|
168
149
|
s = Polars::Series.new('Timestamps', df['Timestamps_'].to_a)
|
|
169
|
-
df = df.insert_column(0,s).drop(
|
|
150
|
+
df = df.insert_column(0, s).drop('Timestamps_')
|
|
170
151
|
end
|
|
171
152
|
|
|
172
|
-
df = df.drop(df.columns - ['Timestamps', @tag]) unless @tag.nil? || !df.columns.include?(@tag)
|
|
153
|
+
df = df.drop(*(df.columns - ['Timestamps', @tag])) unless @tag.nil? || !df.columns.include?(@tag)
|
|
173
154
|
df
|
|
174
155
|
end
|
|
156
|
+
|
|
157
|
+
private
|
|
158
|
+
|
|
159
|
+
def _normalize_label(text)
|
|
160
|
+
return '' if text.nil?
|
|
161
|
+
|
|
162
|
+
text.to_s
|
|
163
|
+
.gsub(/<[^>]+>/, '')
|
|
164
|
+
.gsub(/[[:space:]]+/, ' ')
|
|
165
|
+
.delete('*')
|
|
166
|
+
.strip
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def _normalize_key(text)
|
|
170
|
+
_normalize_label(text).downcase
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def _index_by_normalized_key(hsh)
|
|
174
|
+
hsh.each_with_object({}) { |(key, value), acc| acc[_normalize_key(key)] = value.is_a?(Hash) ? key : value }
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
def _sheet_rows(xlsx_file, sheet_name)
|
|
178
|
+
sheet = xlsx_file.sheet(sheet_name)
|
|
179
|
+
last_row = sheet.last_row
|
|
180
|
+
return nil if last_row.nil?
|
|
181
|
+
|
|
182
|
+
(1..last_row).map { |idx| sheet.row(idx) }
|
|
183
|
+
rescue StandardError
|
|
184
|
+
nil
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def _header_row?(row, header_norm_to_out)
|
|
188
|
+
row.any? { |cell| header_norm_to_out.key?(_normalize_key(cell)) }
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def _rename_header_row(row, header_norm_to_out)
|
|
192
|
+
row.each_index do |ndex|
|
|
193
|
+
if ndex.zero?
|
|
194
|
+
row[ndex] = 'Timestamps_'
|
|
195
|
+
else
|
|
196
|
+
mapped = header_norm_to_out[_normalize_key(row[ndex])]
|
|
197
|
+
row[ndex] = mapped if mapped
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
row
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def _parse_quarter_date(value)
|
|
204
|
+
if /(?<yr>\d{2}):Q(?<qtr>\d)/ =~ value.to_s
|
|
205
|
+
yr = yr.to_i + 2000
|
|
206
|
+
yr -= 100 if yr > Date.today.year
|
|
207
|
+
Date.new(yr, qtr.to_i * 3 - 2, 1)
|
|
208
|
+
elsif (parsed = (value.to_date rescue nil))
|
|
209
|
+
parsed.beginning_of_quarter
|
|
210
|
+
end
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def _filled_row(row)
|
|
214
|
+
row.map { |cell| cell.nil? ? '' : cell }
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
def _csv_line(row)
|
|
218
|
+
trimmed = row.reverse.drop_while { |cell| cell.nil? || cell == '' }.reverse
|
|
219
|
+
trimmed.join(',')
|
|
220
|
+
end
|
|
175
221
|
end
|
|
176
222
|
end
|
data/ny_frb_as_dataframe.gemspec
CHANGED
|
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
|
|
|
33
33
|
# For more information and examples about making a new gem, checkout our
|
|
34
34
|
# guide at: https://bundler.io/guides/creating_gem.html
|
|
35
35
|
spec.add_dependency 'polars-df', '0.27.1'
|
|
36
|
-
spec.add_dependency 'httparty'
|
|
37
|
-
spec.add_dependency '
|
|
36
|
+
spec.add_dependency 'httparty'
|
|
37
|
+
spec.add_dependency 'roo'
|
|
38
38
|
spec.add_dependency 'activesupport'
|
|
39
39
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# REQ-001 — Parse the current NY Fed HHDC workbook
|
|
2
|
+
|
|
3
|
+
**Source:** user report of consumer-app failures against `NyFrbAsDataframe::Hhdc#fetch` (2026-09-09).
|
|
4
|
+
|
|
5
|
+
## Statement
|
|
6
|
+
|
|
7
|
+
`NyFrbAsDataframe::Hhdc#fetch` must download the current NY Fed `hhd_c_report_YYYYqN.xlsx` and return a Polars frame. The published workbook is chart-heavy and its printed titles/headers do not match the gem’s historical exact strings.
|
|
8
|
+
|
|
9
|
+
## Required behavior
|
|
10
|
+
|
|
11
|
+
- Do not set `SimpleXlsxReader.configuration.auto_slurp`. That attribute does not exist on `simple_xlsx_reader` 1.0.5 (`NoMethodError: undefined method 'auto_slurp='`).
|
|
12
|
+
- Do not use SimpleXlsxReader on this workbook. Chart sheets have no dimension node; 1.0.5 assumes every sheet has one and raises `NoMethodError: undefined method 'at_xpath' for nil` in `Mapper#last_cell_label`. Parse data sheets with Roo instead.
|
|
13
|
+
- Match sheet titles after normalizing HTML, trailing `*`, and extra spaces. Current titles include markup such as `<html>New Delinquent<sup>*</sup> Balances by Loan Type </html>`.
|
|
14
|
+
- Match headers after the same normalize, case-insensitively. The workbook uses `To 90+ days late`; the gem’s map has `To 90+ days Late`.
|
|
15
|
+
- Keep the column names this gem emits. Do not assume README names still match the xlsx labels (example: gem `Qtrly % Mort 0->30-60d late` vs a consumer’s `Qtrly % Mort Current->30-60d`).
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ny_frb_as_dataframe
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bill McKinnon
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-09-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: polars-df
|
|
@@ -39,7 +39,7 @@ dependencies:
|
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
42
|
+
name: roo
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
45
|
- - ">="
|
|
@@ -89,6 +89,9 @@ files:
|
|
|
89
89
|
- lib/ny_frb_as_dataframe/hhdc.rb
|
|
90
90
|
- lib/ny_frb_as_dataframe/version.rb
|
|
91
91
|
- ny_frb_as_dataframe.gemspec
|
|
92
|
+
- reqs/executed_plans.md
|
|
93
|
+
- reqs/explicitly_stated_requirements.md
|
|
94
|
+
- reqs/requirements/REQ-001.md
|
|
92
95
|
- test_basic.rb
|
|
93
96
|
homepage: https://github.com/bmck/ny_frb_as_dataframe
|
|
94
97
|
licenses:
|
|
@@ -112,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
112
115
|
- !ruby/object:Gem::Version
|
|
113
116
|
version: '0'
|
|
114
117
|
requirements: []
|
|
115
|
-
rubygems_version: 3.5.
|
|
118
|
+
rubygems_version: 3.5.10
|
|
116
119
|
signing_key:
|
|
117
120
|
specification_version: 4
|
|
118
121
|
summary: Alternative economic and financial data from the NY FRB
|