Class: Rupee::DayCount
- Inherits:
-
Object
- Object
- Rupee::DayCount
- Extended by:
- FindInstance
- Defined in:
- lib/rupee/day_count.rb,
lib/rupee/day_count/30_360.rb,
lib/rupee/day_count/30e_360.rb,
lib/rupee/day_count/act_360.rb,
lib/rupee/day_count/act_365.rb,
lib/rupee/day_count/act_act.rb,
lib/rupee/day_count/30e+_360.rb,
lib/rupee/day_count/30e_360_isda.rb
Overview
A class representing a day count convention used to determine cash flow and accrual dates for fixed income products
Constant Summary collapse
- THIRTY_360 =
Standard US 30/360
DayCount.new "30/360, typical pay-fixed convention" do |from, to| m1 = from.month m2 = to.month d1 = from.day d2 = to.day if end_of_month?(from) d1 = 30 d2 = 30 if m1 == 2 && end_of_month?(to) && m2 == 2 end d2 = 30 if d2 == 31 && d1 == 30 (360 * (to.year - from.year) + 30 * (m2 - m1) + (d2 - d1)) / 360.0 end
- THIRTY_E_360 =
Standard European 30/360
DayCount.new "30E/360" do |from, to| d1 = from.day d2 = to.day d1 = 30 if d1 == 31 d2 = 30 if d2 == 31 (360 * (to.year - from.year) + 30 * (to.month - from.month) + (d2 - d1)) / 360.0 end
- ACT_360 =
Actual/360
DayCount.new "Actual/360, typical LIBOR convention" do |from, to| (to - from) / 360.0 end
- ACT_365 =
Actual/365
DayCount.new "Actual/365" do |from, to| (to - from) / 365.0 end
- ACT_ACT =
Actual/Actual
DayCount.new "Actual/actual" do |from, to| 1 - from.yday / days_in_year(from) + (to.year - from.year - 1) + to.yday / days_in_year(to) end
- THIRTY_E_PLUS_360 =
30E+/360
DayCount.new "30E+/360" do |from, to| m = to.month - from.month d1 = from.day d2 = to.day d1 = 30 if d1 == 31 if d2 == 31 m += 1 d2 = 1 end (360 * (to.year - from.year) + 30 * m + (d2 - d1)) / 360.0 end
- THIRTY_E_360_ISDA =
30E/360 ISDA, typical for Eurobonds
DayCount.new "30E/360 ISDA" do |from, to| d1 = from.day d2 = to.day d1 = 30 if end_of_month?(from) d2 = 30 if end_of_month?(to) # && (d2 != maturity_date || to.month != 2) (360 * (to.year - from.year) + 30 * (to.month - from.month) + (d2 - d1)) / 360.0 end
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
The formula for determining a day count factor (days divided by years).
-
#description ⇒ Object
readonly
A description of the day count convention.
Instance Method Summary collapse
-
#initialize(description, &block) ⇒ DayCount
constructor
Create a new DayCount object.
-
#period(from, to) ⇒ Object
Calculates the period in years between the
from
andtrue
dates.
Methods included from FindInstance
Constructor Details
#initialize(description, &block) ⇒ DayCount
Create a new DayCount object
21 22 23 24 |
# File 'lib/rupee/day_count.rb', line 21 def initialize(description, &block) @description = description @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
The formula for determining a day count factor (days divided by years)
18 19 20 |
# File 'lib/rupee/day_count.rb', line 18 def block @block end |
#description ⇒ Object (readonly)
A description of the day count convention
16 17 18 |
# File 'lib/rupee/day_count.rb', line 16 def description @description end |
Instance Method Details
#period(from, to) ⇒ Object
Calculates the period in years between the from
and true
dates
28 29 30 |
# File 'lib/rupee/day_count.rb', line 28 def period(from, to) block.call from, to end |