sahm_as_dataframe 0.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.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/sahm_as_dataframe/client.rb +40 -0
- data/lib/sahm_as_dataframe/version.rb +3 -0
- data/lib/sahm_as_dataframe.rb +3 -0
- data/sahm_as_dataframe.gemspec +34 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 529b67c1458210458ced19c9cddfd31f6923c9e63ac4618f4e0afb7988be8186
|
4
|
+
data.tar.gz: 8cc6890f65f3b9bb4941ff30e944b17eeb00014c965b3084b1777d6a1ae0e76e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 23002c91231e76df43a3947ebbf5fd9a07c8148ab7285a5e4e7bfed285dec6ddb57af631641e3f7106b250aa54821e7d215a46145133afa3d49fd1b9493086b7
|
7
|
+
data.tar.gz: 2203947f92ec02601b80d8b1948513b7b0866c0755526b84e550759b74de23a219fe4200511720afa6dc1b5f4f9e50381e424d98debe7d27ca8df1b50cdb7456
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Bill McKinnon
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# EconDataReader
|
2
|
+
|
3
|
+
Up to date remote economic data access for ruby, using Polars dataframes.
|
4
|
+
|
5
|
+
This package will fetch economic and financial information from several different sources.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'sahm_as_dataframe'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install sahm_as_dataframe
|
22
|
+
|
23
|
+
|
24
|
+
### Configuration
|
25
|
+
|
26
|
+
This gem does not require configuration on its own, but it does require the fred_as_dataframe gem, which does require an API key from the Federal Reserve Economic Database. See that gem's homepage for details on its configuration.
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
``` ruby
|
31
|
+
SahmAsDataframe::Client.new.fetch
|
32
|
+
```
|
33
|
+
|
34
|
+
## Documentation
|
35
|
+
|
36
|
+
TBD
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Others are welcome to contribute to the project.
|
41
|
+
|
42
|
+
The following conventions are intended for this project.
|
43
|
+
* Different sources are intended to reside in different classes.
|
44
|
+
* API keys (if needed) should be able to be set in the single configuration file.
|
45
|
+
* Series should be able to be identified via a single unique string, provided in the constructor.
|
46
|
+
* When fetched, the dataset may be filtered based on optional (hash) arguments.
|
47
|
+
* Output should be provided in a consistent DataFrame format (currently Polars::DataFrame).
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/bmck/sahm_as_dataframe.
|
50
|
+
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "sahm_as_dataframe"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'polars-df'
|
2
|
+
require 'csv'
|
3
|
+
require 'fred_as_dataframe'
|
4
|
+
|
5
|
+
module SahmAsDataframe
|
6
|
+
class Client
|
7
|
+
attr_reader :unrate_reader
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@unrate_reader = FredAsDataframe::Client.new('UNRATE')
|
11
|
+
end
|
12
|
+
|
13
|
+
def fetch(start: nil, fin: nil, interval: '1d')
|
14
|
+
unrate = @unrate_reader.fetch(start: start, fin: fin, interval: interval)
|
15
|
+
# Rails.logger.info { "#{__FILE__}:#{__LINE__} unrate = #{unrate.inspect}"}
|
16
|
+
unrate['row_num'] = 1.upto(unrate.length).to_a
|
17
|
+
unrate = unrate.set_sorted('row_num')
|
18
|
+
|
19
|
+
# Rails.logger.info { "#{__FILE__}:#{__LINE__} unrate = #{unrate.inspect}"}
|
20
|
+
unrate['3m rolling avg'] = unrate.rolling(index_column: "row_num", period: "3i").agg(
|
21
|
+
[
|
22
|
+
Polars.mean("UNRATE").alias("3m rolling avg")
|
23
|
+
]
|
24
|
+
)['3m rolling avg']
|
25
|
+
unrate['12m rolling_min'] = unrate.rolling(index_column: "row_num", period: "12i").agg(
|
26
|
+
[
|
27
|
+
Polars.min("UNRATE").alias("12m rolling_min")
|
28
|
+
]
|
29
|
+
)['12m rolling_min']
|
30
|
+
unrate['SAHM indicator'] = unrate['3m rolling avg'] - unrate['12m rolling_min']
|
31
|
+
|
32
|
+
unrate = unrate.drop('3m rolling avg', 'row_num', '12m rolling_min')
|
33
|
+
# Rails.logger.info { "#{__FILE__}:#{__LINE__} unrate = #{unrate.inspect}"}
|
34
|
+
# unrate = unrate.drop_nulls
|
35
|
+
unrate['SAHM recession'] = (unrate['SAHM indicator'] >= 0.5)
|
36
|
+
# Rails.logger.info { "#{__FILE__}:#{__LINE__} unrate = #{unrate.inspect}"}
|
37
|
+
unrate
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require_relative 'lib/sahm_as_dataframe/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "sahm_as_dataframe"
|
5
|
+
spec.version = SahmAsDataframe::VERSION
|
6
|
+
spec.authors = ["Bill McKinnon"]
|
7
|
+
spec.email = ["bill.mckinnon@bmck.org"]
|
8
|
+
|
9
|
+
spec.summary = "Sahm economic criteria using fred_as_dataframe"
|
10
|
+
spec.description = "Sahm economic indicator using fred_as_dataframe"
|
11
|
+
spec.homepage = "https://github.com/bmck/sahm_as_dataframe"
|
12
|
+
spec.license = "MIT"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/bmck/sahm_as_dataframe"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/bmck/sahm_as_dataframe/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
# Uncomment to register a new dependency of your gem
|
31
|
+
# spec.add_dependency "typhoeus-gem", "~> 0.6.9"
|
32
|
+
spec.add_dependency 'polars-df'
|
33
|
+
spec.add_dependency 'fred_as_dataframe'
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sahm_as_dataframe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bill McKinnon
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-08-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: polars-df
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fred_as_dataframe
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Sahm economic indicator using fred_as_dataframe
|
42
|
+
email:
|
43
|
+
- bill.mckinnon@bmck.org
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- lib/sahm_as_dataframe.rb
|
57
|
+
- lib/sahm_as_dataframe/client.rb
|
58
|
+
- lib/sahm_as_dataframe/version.rb
|
59
|
+
- sahm_as_dataframe.gemspec
|
60
|
+
homepage: https://github.com/bmck/sahm_as_dataframe
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata:
|
64
|
+
homepage_uri: https://github.com/bmck/sahm_as_dataframe
|
65
|
+
source_code_uri: https://github.com/bmck/sahm_as_dataframe
|
66
|
+
changelog_uri: https://github.com/bmck/sahm_as_dataframe/CHANGELOG.md
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.3.0
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubygems_version: 3.1.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Sahm economic criteria using fred_as_dataframe
|
86
|
+
test_files: []
|