interest_days 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +2 -2
- data/README.md +1 -0
- data/lib/interest_days/calculation/base.rb +13 -0
- data/lib/interest_days/calculation/isda_act_act.rb +45 -0
- data/lib/interest_days/calculator.rb +1 -0
- data/lib/interest_days/version.rb +1 -1
- data/lib/interest_days.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97730e964a0b67a09476d0b44df33c0aecd8a81025f4e7892a375806938b1796
|
4
|
+
data.tar.gz: 5782b2a88733b57f74bb892a9c187807993ee07bd7f4445831284c281e54a808
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70e35e27e4b0716f331fd537359e102b44459eaca401e8591f6c7d978d82cf79f10192fb899cc305faa15c1ec31b51c2a1d4d1bccf7a881275d611f8069bdcb2
|
7
|
+
data.tar.gz: b76ea900e8087b538da8829c745b899bb861a93e7ee6441816bee1f4a11e4716a4f434d11ed7bf36d5a9b3df96fd5307714e0310ece92aaaec029d5b0f4d2ed5
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
module InterestDays
|
4
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
|
+
|
5
12
|
# Base calculation class
|
6
13
|
class Base
|
7
14
|
attr_reader :start_date, :end_date
|
@@ -9,6 +16,8 @@ module InterestDays
|
|
9
16
|
def initialize(start_date:, end_date:)
|
10
17
|
@start_date = start_date
|
11
18
|
@end_date = end_date
|
19
|
+
|
20
|
+
raise StartDateBeforeEndDateError if start_date_after_end_date?
|
12
21
|
end
|
13
22
|
|
14
23
|
def day_count_factor
|
@@ -17,6 +26,10 @@ module InterestDays
|
|
17
26
|
|
18
27
|
private
|
19
28
|
|
29
|
+
def start_date_after_end_date?
|
30
|
+
start_date >= end_date
|
31
|
+
end
|
32
|
+
|
20
33
|
def days
|
21
34
|
@end_date - @start_date
|
22
35
|
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
|
@@ -24,6 +24,7 @@ module InterestDays
|
|
24
24
|
isda_act_360: InterestDays::Calculation::IsdaAct360,
|
25
25
|
isda_act_364: InterestDays::Calculation::IsdaAct364,
|
26
26
|
isda_act_365: InterestDays::Calculation::IsdaAct365,
|
27
|
+
isda_act_act: InterestDays::Calculation::IsdaActAct,
|
27
28
|
isda_30_e_360: InterestDays::Calculation::Isda30e360,
|
28
29
|
bond_basis_30_360: InterestDays::Calculation::Isda30e360,
|
29
30
|
us_eom_30_360: InterestDays::Calculation::UsEom30360
|
data/lib/interest_days.rb
CHANGED
@@ -8,6 +8,7 @@ require "interest_days/calculation/us_eom_30_360"
|
|
8
8
|
require "interest_days/calculation/isda_act_360"
|
9
9
|
require "interest_days/calculation/isda_act_364"
|
10
10
|
require "interest_days/calculation/isda_act_365"
|
11
|
+
require "interest_days/calculation/isda_act_act"
|
11
12
|
require "interest_days/calculation/isda_30_e_360"
|
12
13
|
|
13
14
|
module InterestDays
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eugen Mueller
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2022-
|
12
|
+
date: 2022-03-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/interest_days/calculation/isda_act_360.rb
|
81
81
|
- lib/interest_days/calculation/isda_act_364.rb
|
82
82
|
- lib/interest_days/calculation/isda_act_365.rb
|
83
|
+
- lib/interest_days/calculation/isda_act_act.rb
|
83
84
|
- lib/interest_days/calculation/thirty_threesixty_base.rb
|
84
85
|
- lib/interest_days/calculation/us_eom_30_360.rb
|
85
86
|
- lib/interest_days/calculator.rb
|