econ_data_reader 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c39231152157e0dc59a738be8287486fbd3459892ae02cf00e6b1d4b9f50075c
|
4
|
+
data.tar.gz: 54fce78785df4142f8de8789d26433a24bbf4b5301bb3ceb5470ea2f7707c16d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a487dfd3da7a84be980d7c9c7546cd861a0d1d6763c1d9a1c891c5d3d2e14ad985124d82916c6db4295b0075d88c486d620596a9d247291c28b88d316c45d8f3
|
7
|
+
data.tar.gz: cf9ee4f7aa4c9683e161b91aa7f46c8344a6b90a9990330b10c09b30d7a7e1d597ada8b636da7bbfe52328fc192ed5f6cdc765aaf072eb9cbd4a6d40a339e820
|
data/lib/econ_data_reader/bls.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
+
require 'polars-df'
|
1
2
|
require 'httparty'
|
2
3
|
require 'csv'
|
3
4
|
|
4
5
|
module EconDataReader
|
5
6
|
class Fred
|
6
7
|
# Get data for the given name from the St. Louis FED (FRED).
|
7
|
-
extend ActiveSupport::Concern
|
8
8
|
|
9
9
|
include ::HTTParty
|
10
10
|
attr_reader :tag
|
@@ -24,7 +24,7 @@ module EconDataReader
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def fetch(start: nil, fin: nil, interval: '1d')
|
27
|
-
data = _fetch_data(
|
27
|
+
data = _fetch_data(interval)
|
28
28
|
i = interval[0..-2].to_i
|
29
29
|
|
30
30
|
begin
|
@@ -43,19 +43,22 @@ module EconDataReader
|
|
43
43
|
|
44
44
|
private
|
45
45
|
|
46
|
-
def _url(n, i = '
|
47
|
-
"https://api.stlouisfed.org/fred/series/observations?series_id=#{n}&api_key=#{@api_key}&frequency=#{i}"
|
46
|
+
def _url(n, i = 'm');
|
47
|
+
"https://api.stlouisfed.org/fred/series/observations?series_id=#{n}&api_key=#{@api_key}#{i != 'd' ? "&frequency=#{i}" : ''}"
|
48
48
|
end
|
49
49
|
|
50
50
|
|
51
|
-
def _fetch_data(
|
51
|
+
def _fetch_data(interval)
|
52
52
|
# Utility to fetch data
|
53
53
|
i = interval.strip[-1]
|
54
|
+
nm = tag
|
54
55
|
resp = nil
|
56
|
+
|
55
57
|
if nm == 'SP500' && i == 'm'
|
56
58
|
resp = sp500
|
57
59
|
else
|
58
|
-
resp = self.class.get(_url(nm, interval[-1]))
|
60
|
+
resp = self.class.get(_url(nm, interval[-1]))
|
61
|
+
resp = resp.parsed_response['observations']['observation'] #.map{|a| a.join(',')}.join("\n")
|
59
62
|
resp = "date, #{nm}\n" + resp.map{|r| "#{r['date']},#{r['value']}" }.join("\n")
|
60
63
|
end
|
61
64
|
data = CSV.parse(resp, headers: true, header_converters: :symbol, converters: [:date, :float])
|
data/lib/econ_data_reader.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: econ_data_reader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill McKinnon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: polars-df
|