Skip to content

Commit 325c3af

Browse files
authored
Merge pull request #12 from lungben/multiple_joint_calendars
Multiple joint calendars
2 parents 8a74419 + b4845ae commit 325c3af

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/time/BusinessCalendar.jl

+14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ mutable struct JointCalendar{B <: BusinessCalendar, C <: BusinessCalendar} <: Bu
1717
cal2::C
1818
end
1919

20+
"""
21+
support more than 2 calendars for joint calendar
22+
"""
23+
function JointCalendar(cals...)
24+
length(cals) >= 2 || error("at least 2 calendars must be specified for JointCalendar")
25+
cal = JointCalendar(cals[1], cals[2])
26+
if length(cals) > 2
27+
for i=3:length(cals)
28+
cal = JointCalendar(cal, cals[i])
29+
end
30+
end
31+
return cal
32+
end
33+
2034
# US Calendars
2135
abstract type UnitedStatesCalendar <: WesternCalendar end
2236

test/curves.jl

+12
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,15 @@ dx = (test_curve_linear.dates[5]-test_curve_linear.dates[4]).value
2424
dy = (test_curve_linear.data[5]) - (test_curve_linear.data[4])
2525
df_recalc = ((test_curve_linear.data[4]) + x1*dy/dx)
2626
@test disc_factor == df_recalc
27+
28+
# test joint calendars
29+
const calendar_nyc = QuantLib.Time.USNYSECalendar()
30+
const calendar_target = QuantLib.Time.TargetCalendar()
31+
const calendar_lon = QuantLib.Time.UKLSECalendar()
32+
33+
calendar_nyc_target = QuantLib.Time.JointCalendar(calendar_nyc, calendar_target) # standard constructor
34+
@test calendar_nyc_target isa QuantLib.Time.BusinessCalendar
35+
calendar_nyc_target_lon = QuantLib.Time.JointCalendar(calendar_nyc, calendar_target, calendar_lon) # new constructor
36+
@test calendar_nyc_target_lon isa QuantLib.Time.BusinessCalendar
37+
# at least 2 calendars must be specified for JointCalendar
38+
@test_throws ErrorException QuantLib.Time.JointCalendar(calendar_nyc)

0 commit comments

Comments
 (0)