interest_days 0.5.1 → 0.5.2

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: ebecc4f50f64001035dbc934d9c34db95d4d9839ca1ed2beead12a1812648d97
4
- data.tar.gz: bfc358121e3074f372fac9c28a7fd5885ab8f735c9c1164f65e387df9857a07b
3
+ metadata.gz: 2883c05efa288b06891b2aac71fca5331c723d1df471b18267f60879a9faad7f
4
+ data.tar.gz: 74379f2e234f43b03c711a26c0ad7fa3cc5ca32fce5bcfacb3ceb329a4f44448
5
5
  SHA512:
6
- metadata.gz: 5c30a8d1ad8dd5cb5c0ac71c8ec51cae52f3eb14a45beaf488f4fd2f5617ac18356328ec2e93f0492bbf0c7079349067bd5ca0d8c7460b072f9b410726b510f2
7
- data.tar.gz: 2ba3ebc474f4dcf71e165bc5270933be011cd72f33ec5ae4d15a46a0bb9ac4c86dbd9dea1da22b18b91b3d859cad2e684cacd6078f6ea2f69c1a58af6d18d953
6
+ metadata.gz: 72b9afc11e72d1f9b015d8c457187c1f9c3a4d99cf5606a4ae6279eff57df24d8b3ea6d7b659b64920edce0898c8ba5194a532b7c1797c2eef73539b7a7d11b5
7
+ data.tar.gz: b12ea6908e66b813a5d4a8567a5da45a63f612b23b66c2752377dd614e035bb5e260bb4e1595f8e2eef80d37de194ba06b7c90868fc328da8aa996edf945454b
@@ -0,0 +1,22 @@
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 ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ .history/*
13
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,24 @@
1
+ require:
2
+ - rubocop-rake
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.7
7
+ NewCops: enable
8
+
9
+ Style/StringLiterals:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Style/StringLiteralsInInterpolation:
14
+ Enabled: true
15
+ EnforcedStyle: double_quotes
16
+
17
+ Layout/LineLength:
18
+ Max: 120
19
+
20
+ Naming/VariableNumber:
21
+ EnforcedStyle: snake_case
22
+
23
+ Metrics/BlockLength:
24
+ Max: 50
data/CHANGELOG.md ADDED
@@ -0,0 +1,44 @@
1
+
2
+ ## [0.5.2] / 2022-11-11
3
+ ==================
4
+ * Fix ICMA act/act strategy for interest periods longer than one year.
5
+
6
+ ## [0.5.0] / 2022-11-07
7
+ ==================
8
+ * Add ICMA act/act strategy.
9
+
10
+ ## [0.4.1] / 2022-04-12
11
+ ==================
12
+
13
+ * Fix start_date_after_end_date method considering the case that start_date and end_date are equal.
14
+
15
+ ## [0.4.0] / 2022-03-22
16
+ ==================
17
+
18
+ * Update readme file.
19
+ * Bump version to 0.4.0.
20
+ * Add Isda act/act strategy. #11
21
+
22
+ ## [0.3.0] / 2022-02-03
23
+ ==================
24
+
25
+ * Bump version to 0.2.1
26
+ * Change the gemspec metadata.
27
+ * Setup siplecov.
28
+ * Add spec for act 364 strategy.
29
+ * Add act 364 calculation strategy.
30
+ * Tests isda 30 e 360 (#5)
31
+ * Add codecov integration.
32
+
33
+ ## [0.2.0] / 2021-10-08
34
+ ==================
35
+
36
+ * Feature/#2 30 360 bond basis (#4)
37
+ * Merge pull request #1 from eugenmueller/FIX/readme_typo
38
+ * FIX: indention in README
39
+ * FIX: fix readme typo
40
+ * add .history dir to gitignore
41
+
42
+ ## [0.1.0] - 2021-10-03
43
+
44
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,15 @@
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 ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ interest_days (0.5.2)
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.5.0)
14
+ docile (1.4.0)
15
+ json (2.6.2)
16
+ method_source (1.0.0)
17
+ parallel (1.22.1)
18
+ parser (3.1.2.1)
19
+ ast (~> 2.4.1)
20
+ pry (0.13.1)
21
+ coderay (~> 1.1)
22
+ method_source (~> 1.0)
23
+ rainbow (3.1.1)
24
+ rake (13.0.6)
25
+ regexp_parser (2.5.0)
26
+ rexml (3.2.5)
27
+ rspec (3.11.0)
28
+ rspec-core (~> 3.11.0)
29
+ rspec-expectations (~> 3.11.0)
30
+ rspec-mocks (~> 3.11.0)
31
+ rspec-core (3.11.0)
32
+ rspec-support (~> 3.11.0)
33
+ rspec-expectations (3.11.0)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.11.0)
36
+ rspec-mocks (3.11.1)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.11.0)
39
+ rspec-support (3.11.0)
40
+ rubocop (1.35.0)
41
+ json (~> 2.3)
42
+ parallel (~> 1.10)
43
+ parser (>= 3.1.2.1)
44
+ rainbow (>= 2.2.2, < 4.0)
45
+ regexp_parser (>= 1.8, < 3.0)
46
+ rexml (>= 3.2.5, < 4.0)
47
+ rubocop-ast (>= 1.20.1, < 2.0)
48
+ ruby-progressbar (~> 1.7)
49
+ unicode-display_width (>= 1.4.0, < 3.0)
50
+ rubocop-ast (1.21.0)
51
+ parser (>= 3.1.1.0)
52
+ rubocop-rake (0.6.0)
53
+ rubocop (~> 1.0)
54
+ rubocop-rspec (2.4.0)
55
+ rubocop (~> 1.0)
56
+ rubocop-ast (>= 1.1.0)
57
+ ruby-progressbar (1.11.0)
58
+ simplecov (0.21.2)
59
+ docile (~> 1.1)
60
+ simplecov-html (~> 0.11)
61
+ simplecov_json_formatter (~> 0.1)
62
+ simplecov-html (0.12.3)
63
+ simplecov_json_formatter (0.1.3)
64
+ unicode-display_width (2.2.0)
65
+
66
+ PLATFORMS
67
+ ruby
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.3.17
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,57 @@
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 ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
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", "Cassy Dodd"]
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
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://github.com/eugenmueller/interest_days"
20
+ spec.metadata["changelog_uri"] = "https://github.com/eugenmueller/interest_days/blob/v0.2.0/CHANGELOG.md"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ # spec.add_dependency "example-gem", "~> 1.0"
33
+ spec.add_development_dependency "pry", "~> 0.13.1"
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
+ spec.metadata["rubygems_mfa_required"] = "true"
41
+ end
@@ -0,0 +1,38 @@
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
@@ -0,0 +1,71 @@
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.positive?
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
@@ -0,0 +1,18 @@
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
@@ -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 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
@@ -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,45 @@
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
@@ -0,0 +1,42 @@
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
@@ -0,0 +1,30 @@
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
@@ -0,0 +1,35 @@
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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module InterestDays
4
+ VERSION = "0.5.2"
5
+ end
@@ -0,0 +1,18 @@
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interest_days
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugen Mueller
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2022-11-11 00:00:00.000000000 Z
13
+ date: 2022-11-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: pry
@@ -74,7 +74,32 @@ email:
74
74
  executables: []
75
75
  extensions: []
76
76
  extra_rdoc_files: []
77
- files: []
77
+ files:
78
+ - ".github/workflows/main.yml"
79
+ - ".gitignore"
80
+ - ".rspec"
81
+ - ".rubocop.yml"
82
+ - CHANGELOG.md
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/setup
90
+ - interest_days.gemspec
91
+ - lib/interest_days.rb
92
+ - lib/interest_days/calculation/base.rb
93
+ - lib/interest_days/calculation/icma_act_act.rb
94
+ - lib/interest_days/calculation/isda_30_e_360.rb
95
+ - lib/interest_days/calculation/isda_act_360.rb
96
+ - lib/interest_days/calculation/isda_act_364.rb
97
+ - lib/interest_days/calculation/isda_act_365.rb
98
+ - lib/interest_days/calculation/isda_act_act.rb
99
+ - lib/interest_days/calculation/thirty_threesixty_base.rb
100
+ - lib/interest_days/calculation/us_eom_30_360.rb
101
+ - lib/interest_days/calculator.rb
102
+ - lib/interest_days/version.rb
78
103
  homepage: https://github.com/eugenmueller/interest_days
79
104
  licenses:
80
105
  - MIT