interest_days 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +16 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +17 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/interest_days.gemspec +40 -0
- data/lib/interest_days/calculation/base.rb +25 -0
- data/lib/interest_days/calculation/isda_30_e_360.rb +28 -0
- data/lib/interest_days/calculation/isda_act_360.rb +14 -0
- data/lib/interest_days/calculation/isda_act_365.rb +14 -0
- data/lib/interest_days/calculator.rb +30 -0
- data/lib/interest_days/version.rb +5 -0
- data/lib/interest_days.rb +13 -0
- metadata +108 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 68382b7fbcf8795d417cef0017b8c77cf3169d0e7b14aad979afc82003f80a31
|
4
|
+
data.tar.gz: 0e283cb94a33ec8d073ba0c3ea38b95309e8ca95c18a655b0c6d9772bce152bc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8b30317b93074457dd25bf20968a533d051d91fdb757a8de6db2a3e1b25c352a2f40ef6e91cc05b42457b58bde54167a408a2e62155d1f569ebb6f751ba17b25
|
7
|
+
data.tar.gz: 3d4fbecfdd70fc6b051545d3c1cf6dc126ae3278f28ff276d999da7dc37060eefc6387f8df73e31e922121df1cf97207cd3a5410c5e508bfe0e61b0436c112e4
|
@@ -0,0 +1,16 @@
|
|
1
|
+
name: Interest days CI
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: '2.7.3'
|
14
|
+
bundler-cache: true
|
15
|
+
- name: Run the default task
|
16
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.7
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Style/StringLiterals:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
|
9
|
+
Style/StringLiteralsInInterpolation:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: double_quotes
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Max: 120
|
15
|
+
|
16
|
+
Naming/VariableNumber:
|
17
|
+
EnforcedStyle: snake_case
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
interest_days (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
diff-lcs (1.4.4)
|
11
|
+
parallel (1.20.1)
|
12
|
+
parser (3.0.2.0)
|
13
|
+
ast (~> 2.4.1)
|
14
|
+
rainbow (3.0.0)
|
15
|
+
rake (13.0.6)
|
16
|
+
regexp_parser (2.1.1)
|
17
|
+
rexml (3.2.5)
|
18
|
+
rspec (3.10.0)
|
19
|
+
rspec-core (~> 3.10.0)
|
20
|
+
rspec-expectations (~> 3.10.0)
|
21
|
+
rspec-mocks (~> 3.10.0)
|
22
|
+
rspec-core (3.10.1)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-expectations (3.10.1)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-mocks (3.10.2)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-support (3.10.2)
|
31
|
+
rubocop (1.18.3)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 3.0.0.0)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
regexp_parser (>= 1.8, < 3.0)
|
36
|
+
rexml
|
37
|
+
rubocop-ast (>= 1.7.0, < 2.0)
|
38
|
+
ruby-progressbar (~> 1.7)
|
39
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
40
|
+
rubocop-ast (1.7.0)
|
41
|
+
parser (>= 3.0.1.1)
|
42
|
+
rubocop-rake (0.6.0)
|
43
|
+
rubocop (~> 1.0)
|
44
|
+
rubocop-rspec (2.4.0)
|
45
|
+
rubocop (~> 1.0)
|
46
|
+
rubocop-ast (>= 1.1.0)
|
47
|
+
ruby-progressbar (1.11.0)
|
48
|
+
unicode-display_width (2.0.0)
|
49
|
+
|
50
|
+
PLATFORMS
|
51
|
+
x86_64-darwin-20
|
52
|
+
x86_64-linux
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
interest_days!
|
56
|
+
rake (~> 13.0)
|
57
|
+
rspec (~> 3.0)
|
58
|
+
rubocop (~> 1.7)
|
59
|
+
rubocop-rake
|
60
|
+
rubocop-rspec
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
2.2.21
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Eugen Mueller
|
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,47 @@
|
|
1
|
+
# InterestDays
|
2
|
+
|
3
|
+
This gem provide interest day factor calculation based on ISDA conventions e.g. Isda Act 360.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'interest_days'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install interest_days
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
You can simple use the InterestDays::Calculator like:
|
24
|
+
|
25
|
+
’’’
|
26
|
+
InterestDays::Calculator.new(start_date: start, end_date: end, strategy: :isda_act_360)
|
27
|
+
’’’
|
28
|
+
|
29
|
+
current there a three supported conventions:
|
30
|
+
- :isda_act_360
|
31
|
+
- :isda_act_365
|
32
|
+
- :isda_30_e_360
|
33
|
+
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/eugenmueller/interest_days.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
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,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "interest_days"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/interest_days/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "interest_days"
|
7
|
+
spec.version = InterestDays::VERSION
|
8
|
+
spec.authors = ["Eugen Mueller"]
|
9
|
+
spec.email = ["eugen.mllr@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Interest day calculation"
|
12
|
+
spec.description = "Interest days gem calculate interest days depends on desired method."
|
13
|
+
spec.homepage = "https://github.com/eugenmueller/interest_days"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.7.0"
|
16
|
+
|
17
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/eugenmueller/interest_days"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/eugenmueller/interest_days/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
35
|
+
spec.add_development_dependency "rubocop-rake"
|
36
|
+
spec.add_development_dependency "rubocop-rspec"
|
37
|
+
|
38
|
+
# For more information and examples about making a new gem, checkout our
|
39
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
40
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InterestDays
|
4
|
+
module Calculation
|
5
|
+
# Base calculation class
|
6
|
+
class Base
|
7
|
+
attr_reader :start_date, :end_date
|
8
|
+
|
9
|
+
def initialize(start_date:, end_date:)
|
10
|
+
@start_date = start_date
|
11
|
+
@end_date = end_date
|
12
|
+
end
|
13
|
+
|
14
|
+
def day_count_factor
|
15
|
+
raise NotImplementedError, "#{self.class} has nit implemented method '#{__method__}"
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def days
|
21
|
+
@end_date - @start_date
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InterestDays
|
4
|
+
module Calculation
|
5
|
+
# ISDA 30 E 360 Convention calculation
|
6
|
+
class Isda30e360 < Base
|
7
|
+
RELEVANT_DAYS_IN_YEAR = 360
|
8
|
+
|
9
|
+
def day_count_factor
|
10
|
+
(year_interval_in_days + month_interval_in_days + day_interval).fdiv(RELEVANT_DAYS_IN_YEAR)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def year_interval_in_days
|
16
|
+
360 * (@end_date.year - @start_date.year)
|
17
|
+
end
|
18
|
+
|
19
|
+
def month_interval_in_days
|
20
|
+
30 * (@end_date.month - @start_date.month)
|
21
|
+
end
|
22
|
+
|
23
|
+
def day_interval
|
24
|
+
[@end_date.day, 30].min - [@start_date.day, 30].min
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InterestDays
|
4
|
+
module Calculation
|
5
|
+
# ISDA Act 360 Convention calculation
|
6
|
+
class IsdaAct360 < Base
|
7
|
+
RELEVANT_DAYS_IN_YEAR = 360
|
8
|
+
|
9
|
+
def day_count_factor
|
10
|
+
days.fdiv(RELEVANT_DAYS_IN_YEAR)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InterestDays
|
4
|
+
module Calculation
|
5
|
+
# ISDA 30 E 365 Convention calculation
|
6
|
+
class IsdaAct365 < Base
|
7
|
+
RELEVANT_DAYS_IN_YEAR = 365
|
8
|
+
|
9
|
+
def day_count_factor
|
10
|
+
days.fdiv(RELEVANT_DAYS_IN_YEAR)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InterestDays
|
4
|
+
# Main calculator class
|
5
|
+
class Calculator
|
6
|
+
attr_accessor :strategy, :start_date, :end_date
|
7
|
+
|
8
|
+
def initialize(start_date:, end_date:, strategy:)
|
9
|
+
@start_date = start_date
|
10
|
+
@end_date = end_date
|
11
|
+
@strategy = strategies[strategy.to_sym]
|
12
|
+
end
|
13
|
+
|
14
|
+
def interest_day_count_factor
|
15
|
+
raise StandardError, "Strategy is not set" if @strategy.nil?
|
16
|
+
|
17
|
+
@strategy.new(start_date: @start_date, end_date: @end_date).day_count_factor
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def strategies
|
23
|
+
@strategies ||= {
|
24
|
+
isda_act_360: InterestDays::Calculation::IsdaAct360,
|
25
|
+
isda_act_365: InterestDays::Calculation::IsdaAct365,
|
26
|
+
isda_30_e_360: InterestDays::Calculation::Isda30e360
|
27
|
+
}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "interest_days/version"
|
4
|
+
require "interest_days/calculator"
|
5
|
+
require "interest_days/calculation/base"
|
6
|
+
require "interest_days/calculation/isda_act_360"
|
7
|
+
require "interest_days/calculation/isda_act_365"
|
8
|
+
require "interest_days/calculation/isda_30_e_360"
|
9
|
+
|
10
|
+
module InterestDays
|
11
|
+
class Error < StandardError; end
|
12
|
+
# Your code goes here...
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: interest_days
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eugen Mueller
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rubocop-rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Interest days gem calculate interest days depends on desired method.
|
56
|
+
email:
|
57
|
+
- eugen.mllr@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".github/workflows/main.yml"
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".rubocop.yml"
|
66
|
+
- CHANGELOG.md
|
67
|
+
- Gemfile
|
68
|
+
- Gemfile.lock
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- interest_days.gemspec
|
75
|
+
- lib/interest_days.rb
|
76
|
+
- lib/interest_days/calculation/base.rb
|
77
|
+
- lib/interest_days/calculation/isda_30_e_360.rb
|
78
|
+
- lib/interest_days/calculation/isda_act_360.rb
|
79
|
+
- lib/interest_days/calculation/isda_act_365.rb
|
80
|
+
- lib/interest_days/calculator.rb
|
81
|
+
- lib/interest_days/version.rb
|
82
|
+
homepage: https://github.com/eugenmueller/interest_days
|
83
|
+
licenses:
|
84
|
+
- MIT
|
85
|
+
metadata:
|
86
|
+
homepage_uri: https://github.com/eugenmueller/interest_days
|
87
|
+
source_code_uri: https://github.com/eugenmueller/interest_days
|
88
|
+
changelog_uri: https://github.com/eugenmueller/interest_days/CHANGELOG.md
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 2.7.0
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubygems_version: 3.1.6
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: Interest day calculation
|
108
|
+
test_files: []
|