interest_days 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +4 -28
- data/.github/workflows/main.yml +0 -22
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.rubocop.yml +0 -20
- data/CHANGELOG.md +0 -40
- data/Gemfile +0 -15
- data/Gemfile.lock +0 -81
- data/LICENSE.txt +0 -21
- data/README.md +0 -57
- data/Rakefile +0 -12
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/interest_days.gemspec +0 -42
- data/lib/interest_days/calculation/base.rb +0 -38
- data/lib/interest_days/calculation/icma_act_act.rb +0 -71
- data/lib/interest_days/calculation/isda_30_e_360.rb +0 -18
- data/lib/interest_days/calculation/isda_act_360.rb +0 -14
- data/lib/interest_days/calculation/isda_act_364.rb +0 -14
- data/lib/interest_days/calculation/isda_act_365.rb +0 -14
- data/lib/interest_days/calculation/isda_act_act.rb +0 -45
- data/lib/interest_days/calculation/thirty_threesixty_base.rb +0 -42
- data/lib/interest_days/calculation/us_eom_30_360.rb +0 -30
- data/lib/interest_days/calculator.rb +0 -35
- data/lib/interest_days/version.rb +0 -5
- data/lib/interest_days.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebecc4f50f64001035dbc934d9c34db95d4d9839ca1ed2beead12a1812648d97
|
4
|
+
data.tar.gz: bfc358121e3074f372fac9c28a7fd5885ab8f735c9c1164f65e387df9857a07b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c30a8d1ad8dd5cb5c0ac71c8ec51cae52f3eb14a45beaf488f4fd2f5617ac18356328ec2e93f0492bbf0c7079349067bd5ca0d8c7460b072f9b410726b510f2
|
7
|
+
data.tar.gz: 2ba3ebc474f4dcf71e165bc5270933be011cd72f33ec5ae4d15a46a0bb9ac4c86dbd9dea1da22b18b91b3d859cad2e684cacd6078f6ea2f69c1a58af6d18d953
|
metadata
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: interest_days
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugen Mueller
|
8
8
|
- Kevin Liebholz
|
9
|
+
- Cassy Dodd
|
9
10
|
autorequire:
|
10
11
|
bindir: exe
|
11
12
|
cert_chain: []
|
12
|
-
date: 2022-11-
|
13
|
+
date: 2022-11-11 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: pry
|
@@ -73,32 +74,7 @@ email:
|
|
73
74
|
executables: []
|
74
75
|
extensions: []
|
75
76
|
extra_rdoc_files: []
|
76
|
-
files:
|
77
|
-
- ".github/workflows/main.yml"
|
78
|
-
- ".gitignore"
|
79
|
-
- ".rspec"
|
80
|
-
- ".rubocop.yml"
|
81
|
-
- CHANGELOG.md
|
82
|
-
- Gemfile
|
83
|
-
- Gemfile.lock
|
84
|
-
- LICENSE.txt
|
85
|
-
- README.md
|
86
|
-
- Rakefile
|
87
|
-
- bin/console
|
88
|
-
- bin/setup
|
89
|
-
- interest_days.gemspec
|
90
|
-
- lib/interest_days.rb
|
91
|
-
- lib/interest_days/calculation/base.rb
|
92
|
-
- lib/interest_days/calculation/icma_act_act.rb
|
93
|
-
- lib/interest_days/calculation/isda_30_e_360.rb
|
94
|
-
- lib/interest_days/calculation/isda_act_360.rb
|
95
|
-
- lib/interest_days/calculation/isda_act_364.rb
|
96
|
-
- lib/interest_days/calculation/isda_act_365.rb
|
97
|
-
- lib/interest_days/calculation/isda_act_act.rb
|
98
|
-
- lib/interest_days/calculation/thirty_threesixty_base.rb
|
99
|
-
- lib/interest_days/calculation/us_eom_30_360.rb
|
100
|
-
- lib/interest_days/calculator.rb
|
101
|
-
- lib/interest_days/version.rb
|
77
|
+
files: []
|
102
78
|
homepage: https://github.com/eugenmueller/interest_days
|
103
79
|
licenses:
|
104
80
|
- MIT
|
data/.github/workflows/main.yml
DELETED
@@ -1,22 +0,0 @@
|
|
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: COVERAGE=true bundle exec rake
|
17
|
-
env:
|
18
|
-
token: ${{ secrets.CODECOV_TOKEN }}
|
19
|
-
- name: Upload coverage to Codecov
|
20
|
-
uses: codecov/codecov-action@v2
|
21
|
-
with:
|
22
|
-
token: ${{ secrets.CODECOV_TOKEN }}
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
@@ -1,20 +0,0 @@
|
|
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
|
18
|
-
|
19
|
-
Metrics/BlockLength:
|
20
|
-
Max: 50
|
data/CHANGELOG.md
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
|
2
|
-
## [0.5.0] / 2022-11-07
|
3
|
-
==================
|
4
|
-
* Add ICMA act/act strategy.
|
5
|
-
|
6
|
-
## [0.4.1] / 2022-04-12
|
7
|
-
==================
|
8
|
-
|
9
|
-
* Fix start_date_after_end_date method considering the case that start_date and end_date are equal.
|
10
|
-
|
11
|
-
## [0.4.0] / 2022-03-22
|
12
|
-
==================
|
13
|
-
|
14
|
-
* Update readme file.
|
15
|
-
* Bump version to 0.4.0.
|
16
|
-
* Add Isda act/act strategy. #11
|
17
|
-
|
18
|
-
## [0.3.0] / 2022-02-03
|
19
|
-
==================
|
20
|
-
|
21
|
-
* Bump version to 0.2.1
|
22
|
-
* Change the gemspec metadata.
|
23
|
-
* Setup siplecov.
|
24
|
-
* Add spec for act 364 strategy.
|
25
|
-
* Add act 364 calculation strategy.
|
26
|
-
* Tests isda 30 e 360 (#5)
|
27
|
-
* Add codecov integration.
|
28
|
-
|
29
|
-
## [0.2.0] / 2021-10-08
|
30
|
-
==================
|
31
|
-
|
32
|
-
* Feature/#2 30 360 bond basis (#4)
|
33
|
-
* Merge pull request #1 from eugenmueller/FIX/readme_typo
|
34
|
-
* FIX: indention in README
|
35
|
-
* FIX: fix readme typo
|
36
|
-
* add .history dir to gitignore
|
37
|
-
|
38
|
-
## [0.1.0] - 2021-10-03
|
39
|
-
|
40
|
-
- Initial release
|
data/Gemfile
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in interest_days.gemspec
|
6
|
-
gemspec
|
7
|
-
|
8
|
-
gem "rake", "~> 13.0"
|
9
|
-
|
10
|
-
group :test, :development do
|
11
|
-
gem "codecov", "~> 0.6.0", require: false
|
12
|
-
gem "rspec", "~> 3.0"
|
13
|
-
gem "rubocop", "~> 1.7"
|
14
|
-
gem "simplecov", "~> 0.21.2", require: false
|
15
|
-
end
|
data/Gemfile.lock
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
interest_days (0.5.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
ast (2.4.2)
|
10
|
-
codecov (0.6.0)
|
11
|
-
simplecov (>= 0.15, < 0.22)
|
12
|
-
coderay (1.1.3)
|
13
|
-
diff-lcs (1.4.4)
|
14
|
-
docile (1.4.0)
|
15
|
-
method_source (1.0.0)
|
16
|
-
parallel (1.20.1)
|
17
|
-
parser (3.0.2.0)
|
18
|
-
ast (~> 2.4.1)
|
19
|
-
pry (0.13.1)
|
20
|
-
coderay (~> 1.1)
|
21
|
-
method_source (~> 1.0)
|
22
|
-
rainbow (3.0.0)
|
23
|
-
rake (13.0.6)
|
24
|
-
regexp_parser (2.1.1)
|
25
|
-
rexml (3.2.5)
|
26
|
-
rspec (3.10.0)
|
27
|
-
rspec-core (~> 3.10.0)
|
28
|
-
rspec-expectations (~> 3.10.0)
|
29
|
-
rspec-mocks (~> 3.10.0)
|
30
|
-
rspec-core (3.10.1)
|
31
|
-
rspec-support (~> 3.10.0)
|
32
|
-
rspec-expectations (3.10.1)
|
33
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
-
rspec-support (~> 3.10.0)
|
35
|
-
rspec-mocks (3.10.2)
|
36
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.10.0)
|
38
|
-
rspec-support (3.10.2)
|
39
|
-
rubocop (1.18.3)
|
40
|
-
parallel (~> 1.10)
|
41
|
-
parser (>= 3.0.0.0)
|
42
|
-
rainbow (>= 2.2.2, < 4.0)
|
43
|
-
regexp_parser (>= 1.8, < 3.0)
|
44
|
-
rexml
|
45
|
-
rubocop-ast (>= 1.7.0, < 2.0)
|
46
|
-
ruby-progressbar (~> 1.7)
|
47
|
-
unicode-display_width (>= 1.4.0, < 3.0)
|
48
|
-
rubocop-ast (1.7.0)
|
49
|
-
parser (>= 3.0.1.1)
|
50
|
-
rubocop-rake (0.6.0)
|
51
|
-
rubocop (~> 1.0)
|
52
|
-
rubocop-rspec (2.4.0)
|
53
|
-
rubocop (~> 1.0)
|
54
|
-
rubocop-ast (>= 1.1.0)
|
55
|
-
ruby-progressbar (1.11.0)
|
56
|
-
simplecov (0.21.2)
|
57
|
-
docile (~> 1.1)
|
58
|
-
simplecov-html (~> 0.11)
|
59
|
-
simplecov_json_formatter (~> 0.1)
|
60
|
-
simplecov-html (0.12.3)
|
61
|
-
simplecov_json_formatter (0.1.3)
|
62
|
-
unicode-display_width (2.0.0)
|
63
|
-
|
64
|
-
PLATFORMS
|
65
|
-
x86_64-darwin-19
|
66
|
-
x86_64-darwin-20
|
67
|
-
x86_64-linux
|
68
|
-
|
69
|
-
DEPENDENCIES
|
70
|
-
codecov (~> 0.6.0)
|
71
|
-
interest_days!
|
72
|
-
pry (~> 0.13.1)
|
73
|
-
rake (~> 13.0)
|
74
|
-
rspec (~> 3.0)
|
75
|
-
rubocop (~> 1.7)
|
76
|
-
rubocop-rake
|
77
|
-
rubocop-rspec
|
78
|
-
simplecov (~> 0.21.2)
|
79
|
-
|
80
|
-
BUNDLED WITH
|
81
|
-
2.2.33
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
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
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# InterestDays
|
2
|
-
|
3
|
-
This gem provides interest day factor calculation based on ISDA conventions e.g. Isda Act 360.
|
4
|
-
- Since version 0.2 interest_day gem supported 30/360 US EOM and 30/360 Bond Basis conventions.
|
5
|
-
- Since version 0.3 the gem also supports Isda Act 364
|
6
|
-
|
7
|
-
## Installation
|
8
|
-
|
9
|
-
Add this line to your application's Gemfile:
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'interest_days'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle install
|
18
|
-
|
19
|
-
Or install it yourself as:
|
20
|
-
|
21
|
-
$ gem install interest_days
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
You can simply use the InterestDays::Calculator like:
|
26
|
-
|
27
|
-
```ruby
|
28
|
-
calculator = InterestDays::Calculator.new(start_date: start, end_date: end, strategy: :isda_act_360)
|
29
|
-
|
30
|
-
calculator.interest_day_count_factor
|
31
|
-
```
|
32
|
-
|
33
|
-
currently, there are five supported conventions:
|
34
|
-
- :isda_act_360
|
35
|
-
- :isda_act_364
|
36
|
-
- :isda_act_365
|
37
|
-
- :isda_act_act
|
38
|
-
- :isda_30_e_360
|
39
|
-
- :us_eom_30_360
|
40
|
-
- :bond_basis_30_360
|
41
|
-
- :icma_act_act
|
42
|
-
|
43
|
-
As often, [Wikipedia](https://en.wikipedia.org/wiki/Day_count_convention) is the best resource, so check it out to get more insights into these conventions.
|
44
|
-
|
45
|
-
## Development
|
46
|
-
|
47
|
-
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.
|
48
|
-
|
49
|
-
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).
|
50
|
-
|
51
|
-
## Contributing
|
52
|
-
|
53
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/eugenmueller/interest_days. ;)
|
54
|
-
|
55
|
-
## License
|
56
|
-
|
57
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
DELETED
data/bin/console
DELETED
@@ -1,15 +0,0 @@
|
|
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
DELETED
data/interest_days.gemspec
DELETED
@@ -1,42 +0,0 @@
|
|
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", "Kevin Liebholz"]
|
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/blob/v0.2.0/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 "pry", "~> 0.13.1"
|
35
|
-
spec.add_development_dependency "rspec", "~> 3.2"
|
36
|
-
spec.add_development_dependency "rubocop-rake"
|
37
|
-
spec.add_development_dependency "rubocop-rspec"
|
38
|
-
|
39
|
-
# For more information and examples about making a new gem, checkout our
|
40
|
-
# guide at: https://bundler.io/guides/creating_gem.html
|
41
|
-
spec.metadata["rubygems_mfa_required"] = "true"
|
42
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module InterestDays
|
4
|
-
module Calculation
|
5
|
-
# StartDateBeforeEndDateError class
|
6
|
-
class StartDateBeforeEndDateError < StandardError
|
7
|
-
def initialize(msg = "End date have to be after start date!")
|
8
|
-
super(msg)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
# Base calculation class
|
13
|
-
class Base
|
14
|
-
attr_reader :start_date, :end_date
|
15
|
-
|
16
|
-
def initialize(start_date:, end_date:)
|
17
|
-
@start_date = start_date
|
18
|
-
@end_date = end_date
|
19
|
-
|
20
|
-
raise StartDateBeforeEndDateError if start_date_after_end_date?
|
21
|
-
end
|
22
|
-
|
23
|
-
def day_count_factor
|
24
|
-
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}"
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
def start_date_after_end_date?
|
30
|
-
start_date > end_date
|
31
|
-
end
|
32
|
-
|
33
|
-
def days
|
34
|
-
@end_date - @start_date
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,71 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module InterestDays
|
4
|
-
module Calculation
|
5
|
-
# ISDA Act Act Convention calculation
|
6
|
-
class IcmaActAct < Base
|
7
|
-
DAYS_IN_YEAR = 365
|
8
|
-
DAYS_IN_LEAP_YEAR = 366
|
9
|
-
|
10
|
-
def day_count_factor
|
11
|
-
return days.fdiv(start_date_days_in_year) if start_date_and_end_date_in_same_year?
|
12
|
-
|
13
|
-
if years_in_between_factor > 1
|
14
|
-
return start_date_period_factor + years_in_between_factor + end_date_period_factor
|
15
|
-
end
|
16
|
-
|
17
|
-
days.fdiv(year_days_in_period)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def year_days_in_period
|
23
|
-
period_contains_leap_day? ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR
|
24
|
-
end
|
25
|
-
|
26
|
-
def period_contains_leap_day?
|
27
|
-
!leap_day.nil? && leap_day.between?(start_date, end_date)
|
28
|
-
end
|
29
|
-
|
30
|
-
def leap_day
|
31
|
-
@leap_day ||= if start_date.leap?
|
32
|
-
Date.new(start_date.year, 2, 29)
|
33
|
-
elsif end_date.leap?
|
34
|
-
Date.new(end_date.year, 2, 29)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def start_date_period_factor
|
39
|
-
(start_date_days_in_year - start_date.yday).fdiv(start_date_days_in_year)
|
40
|
-
end
|
41
|
-
|
42
|
-
def end_date_period_factor
|
43
|
-
end_date.yday.fdiv(end_date_days_in_year)
|
44
|
-
end
|
45
|
-
|
46
|
-
def years_in_between_factor
|
47
|
-
(end_date.year - start_date.year) - 1
|
48
|
-
end
|
49
|
-
|
50
|
-
def start_date_period_with_leap_date?
|
51
|
-
start_date.leap? && start_date.month < 3
|
52
|
-
end
|
53
|
-
|
54
|
-
def end_date_period_with_leap_date?
|
55
|
-
end_date.leap? && end_date >= Date.new(end_date.year, 2, 29)
|
56
|
-
end
|
57
|
-
|
58
|
-
def start_date_and_end_date_in_same_year?
|
59
|
-
start_date.year.eql?(end_date.year)
|
60
|
-
end
|
61
|
-
|
62
|
-
def start_date_days_in_year
|
63
|
-
start_date_period_with_leap_date? ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR
|
64
|
-
end
|
65
|
-
|
66
|
-
def end_date_days_in_year
|
67
|
-
end_date_period_with_leap_date? ? DAYS_IN_LEAP_YEAR : DAYS_IN_YEAR
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module InterestDays
|
4
|
-
module Calculation
|
5
|
-
# ISDA 30 E 360 Convention calculation
|
6
|
-
class Isda30e360 < ThirtyThreesixtyBase
|
7
|
-
private
|
8
|
-
|
9
|
-
def end_date_days
|
10
|
-
[@end_date.day, RELEVANT_DAY_IN_MONTH].min
|
11
|
-
end
|
12
|
-
|
13
|
-
def start_date_days
|
14
|
-
[@start_date.day, RELEVANT_DAY_IN_MONTH].min
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,14 +0,0 @@
|
|
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
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module InterestDays
|
4
|
-
module Calculation
|
5
|
-
# ISDA 30 E 365 Convention calculation
|
6
|
-
class IsdaAct364 < Base
|
7
|
-
RELEVANT_DAYS_IN_YEAR = 364
|
8
|
-
|
9
|
-
def day_count_factor
|
10
|
-
days.fdiv(RELEVANT_DAYS_IN_YEAR)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,14 +0,0 @@
|
|
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
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module InterestDays
|
4
|
-
module Calculation
|
5
|
-
# ISDA Act Act Convention calculation
|
6
|
-
class IsdaActAct < Base
|
7
|
-
RELEVANT_DAYS_IN_YEAR = 365
|
8
|
-
RELEVANT_DAYS_IN_LEAP_YEAR = 366
|
9
|
-
|
10
|
-
def day_count_factor
|
11
|
-
return days.fdiv(stard_date_days_in_year) if start_date_and_end_date_in_same_year?
|
12
|
-
|
13
|
-
end_date_days.fdiv(end_date_days_in_year) +
|
14
|
-
start_date_days.fdiv(stard_date_days_in_year) +
|
15
|
-
full_years_between_start_and_end_date
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def full_years_between_start_and_end_date
|
21
|
-
(end_date.year - start_date.year) - 1
|
22
|
-
end
|
23
|
-
|
24
|
-
def start_date_and_end_date_in_same_year?
|
25
|
-
start_date.year.eql?(end_date.year)
|
26
|
-
end
|
27
|
-
|
28
|
-
def stard_date_days_in_year
|
29
|
-
start_date.leap? ? RELEVANT_DAYS_IN_LEAP_YEAR : RELEVANT_DAYS_IN_YEAR
|
30
|
-
end
|
31
|
-
|
32
|
-
def end_date_days_in_year
|
33
|
-
end_date.leap? ? RELEVANT_DAYS_IN_LEAP_YEAR : RELEVANT_DAYS_IN_YEAR
|
34
|
-
end
|
35
|
-
|
36
|
-
def start_date_days
|
37
|
-
stard_date_days_in_year - start_date.yday
|
38
|
-
end
|
39
|
-
|
40
|
-
def end_date_days
|
41
|
-
end_date.yday
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module InterestDays
|
4
|
-
module Calculation
|
5
|
-
# ISDA 30 E 360 Convention calculation
|
6
|
-
class ThirtyThreesixtyBase < Base
|
7
|
-
RELEVANT_DAYS_IN_YEAR = 360
|
8
|
-
RELEVANT_DAY_IN_MONTH = 30
|
9
|
-
|
10
|
-
def day_count_factor
|
11
|
-
(year_interval_in_days + month_interval_in_days + day_interval).fdiv(RELEVANT_DAYS_IN_YEAR)
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def year_interval_in_days
|
17
|
-
RELEVANT_DAYS_IN_YEAR * (@end_date.year - @start_date.year)
|
18
|
-
end
|
19
|
-
|
20
|
-
def month_interval_in_days
|
21
|
-
RELEVANT_DAY_IN_MONTH * (@end_date.month - @start_date.month)
|
22
|
-
end
|
23
|
-
|
24
|
-
def day_interval
|
25
|
-
end_date_days - start_date_days
|
26
|
-
# [@end_date.day, 30].min - [@start_date.day, 30].min
|
27
|
-
end
|
28
|
-
|
29
|
-
def end_date_days
|
30
|
-
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}"
|
31
|
-
end
|
32
|
-
|
33
|
-
def start_date_days
|
34
|
-
raise NotImplementedError, "#{self.class} has not implemented method '#{__method__}"
|
35
|
-
end
|
36
|
-
|
37
|
-
def days_in_month_for(date)
|
38
|
-
Date.new(date.year, date.month, -1).day
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module InterestDays
|
4
|
-
module Calculation
|
5
|
-
# ISDA 30 E 360 Convention calculation
|
6
|
-
class UsEom30360 < ThirtyThreesixtyBase
|
7
|
-
private
|
8
|
-
|
9
|
-
# D2 day
|
10
|
-
def end_date_days
|
11
|
-
if ((@start_date.month == 2 && @start_date.day == days_in_month_for(@start_date)) &&
|
12
|
-
(@end_date.month == 2 && @end_date.day == days_in_month_for(@end_date))) ||
|
13
|
-
(@end_date.day == 31 && @start_date.day >= 30)
|
14
|
-
RELEVANT_DAY_IN_MONTH
|
15
|
-
else
|
16
|
-
@end_date.day
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# D1 day
|
21
|
-
def start_date_days
|
22
|
-
if (@start_date.month == 2 && @start_date.day == days_in_month_for(@start_date)) || @start_date.day == 31
|
23
|
-
RELEVANT_DAY_IN_MONTH
|
24
|
-
else
|
25
|
-
@start_date.day
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,35 +0,0 @@
|
|
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_364: InterestDays::Calculation::IsdaAct364,
|
26
|
-
isda_act_365: InterestDays::Calculation::IsdaAct365,
|
27
|
-
isda_act_act: InterestDays::Calculation::IsdaActAct,
|
28
|
-
isda_30_e_360: InterestDays::Calculation::Isda30e360,
|
29
|
-
bond_basis_30_360: InterestDays::Calculation::Isda30e360,
|
30
|
-
us_eom_30_360: InterestDays::Calculation::UsEom30360,
|
31
|
-
icma_act_act: InterestDays::Calculation::IcmaActAct
|
32
|
-
}
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
data/lib/interest_days.rb
DELETED
@@ -1,18 +0,0 @@
|
|
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/thirty_threesixty_base"
|
7
|
-
require "interest_days/calculation/us_eom_30_360"
|
8
|
-
require "interest_days/calculation/isda_act_360"
|
9
|
-
require "interest_days/calculation/isda_act_364"
|
10
|
-
require "interest_days/calculation/isda_act_365"
|
11
|
-
require "interest_days/calculation/isda_act_act"
|
12
|
-
require "interest_days/calculation/icma_act_act"
|
13
|
-
require "interest_days/calculation/isda_30_e_360"
|
14
|
-
|
15
|
-
module InterestDays
|
16
|
-
class Error < StandardError; end
|
17
|
-
# Your code goes here...
|
18
|
-
end
|