Skip to content

Commit

Permalink
add name field to CurveMap
Browse files Browse the repository at this point in the history
  • Loading branch information
felipenoris committed Sep 23, 2021
1 parent c25d7e1 commit 7a64d04
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/curvemap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end
dt_curve = Date(2015,08,03)
curve_map = InterestRates.CurveMap(map_parallel_1pct, InterestRates.IRCurve("dummy-cont-flatforward", InterestRates.Actual360(),
curve_map = InterestRates.CurveMap("mapped-curve", map_parallel_1pct, InterestRates.IRCurve("dummy-cont-flatforward", InterestRates.Actual360(),
InterestRates.ContinuousCompounding(), InterestRates.FlatForward(), dt_curve,
vert_x, vert_y))
Expand All @@ -36,14 +36,16 @@ zero_rate(curve_map, dt_curve + Dates.Day(11)) ≈ 0.1
```
"""
struct CurveMap{M, C<:AbstractIRCurve{M}, F<:Function} <: AbstractIRCurve{M}
name::String
f::F
curve::C
end

for fun in (:curve_get_name, :curve_get_daycount, :curve_get_compounding, :curve_get_method, :curve_get_date, :curve_get_dtm, :curve_get_zero_rates, :curve_get_model_parameters, :curve_get_spline_fit_on_rates, :curve_get_spline_fit_on_discount_factors)
for fun in (:curve_get_daycount, :curve_get_compounding, :curve_get_method, :curve_get_date, :curve_get_dtm, :curve_get_zero_rates, :curve_get_model_parameters, :curve_get_spline_fit_on_rates, :curve_get_spline_fit_on_discount_factors)
@eval begin
($fun)(curve::CurveMap) = ($fun)(curve.curve)
end
end

zero_rate(curve::CurveMap, maturity::Date) = curve.f(zero_rate(curve.curve, maturity), maturity)
curve_get_name(curve::CurveMap) = curve.name
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,11 @@ end

dt_curve = Date(2015,08,03)

curve_map = InterestRates.CurveMap(map_parallel_1pct, InterestRates.IRCurve("dummy-cont-flatforward", InterestRates.Actual360(),
curve_map = InterestRates.CurveMap("parallel-1pct", map_parallel_1pct, InterestRates.IRCurve("dummy-cont-flatforward", InterestRates.Actual360(),
InterestRates.ContinuousCompounding(), InterestRates.FlatForward(), dt_curve,
vert_x, vert_y))

@test InterestRates.curve_get_name(curve_map) == "parallel-1pct"
@test zero_rate(curve_map, dt_curve + Dates.Day(11)) 0.1
@test zero_rate(curve_map, dt_curve + Dates.Day(15)) 0.15
@test zero_rate(curve_map, dt_curve + Dates.Day(19)) 0.20
Expand Down

2 comments on commit 7a64d04

@felipenoris
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/45429

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.0 -m "<description of version>" 7a64d04c31dfb4c0703bc2a05c9b8c809f1c20d9
git push origin v0.6.0

Please sign in to comment.