diff --git a/Project.toml b/Project.toml index bc3320d..6adf9f1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Curves" uuid = "9bed79ab-e35b-4b7a-8527-918872a9571e" authors = ["Benjamin Lungwitz "] -version = "0.2.4" +version = "0.2.5" [deps] Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" diff --git a/src/Curves.jl b/src/Curves.jl index 0ad7a68..9457cba 100644 --- a/src/Curves.jl +++ b/src/Curves.jl @@ -117,11 +117,15 @@ Construct Curve objects from an array of tenor strings as x-axis. Curve(x:: AbstractVector{<: AbstractString}, y:: AbstractVector; kwargs...) = Curve(Tenor.(x), y; kwargs...) """ - Curve(x:: AbstractVector{Tenor}, y:: AbstractVector; kwargs...) + Curve(x:: AbstractVector{Tenor}, y:: AbstractVector; offset:: Real = 0, kwargs...) Construct Curve objects from an array of Tenor objects strings as x-axis. + +With the `offset` keyword argument the points on the x-axis, defined by the given tenors, can be shifted. +This could be e.g. used to take a spot lag of financial instruments into account. +Note that the shift is always in calendar days, a spot lag given in business days must be converted to calendar days beforehand. """ -Curve(x:: AbstractVector{Tenor}, y:: AbstractVector; kwargs...) = Curve(get_days.(x), y; kwargs...) +Curve(x:: AbstractVector{Tenor}, y:: AbstractVector; offset:: Real = 0, kwargs...) = Curve(get_days.(x) .+ offset, y; kwargs...) Curve(x:: Real, y:: Real; kwargs...) = Curve([x], [y]; kwargs...) Curve(x:: Tenor, y:: Real; kwargs...) = Curve([get_days(x)], [y]; kwargs...) diff --git a/test/test_tenors.jl b/test/test_tenors.jl index e25080b..c80b5ce 100644 --- a/test/test_tenors.jl +++ b/test/test_tenors.jl @@ -37,6 +37,10 @@ ct2 = Curve(collect(t), [0.5, 0.7, 0.75, 0.83]) @test t"1W" == Tenor(Curves.TWeeks, 1) @test_throws KeyError t"1X" +ct3 = Curve(["1D", "3W", "1M", "10y"], [0.5, 0.7, 0.75, 0.83], offset=2) +ct4 = Curve(collect(t), [0.5, 0.7, 0.75, 0.83], offset=2) +@test ct3 == ct4 == Curve([1+2, 21+2, 30+2, 3650+2], [0.5, 0.7, 0.75, 0.83]) + # test pretty printing io = IOBuffer(append=true) print(io, t"1W")