Skip to content

Commit

Permalink
added possibility to specify an offset for curve construction from tenor
Browse files Browse the repository at this point in the history
  • Loading branch information
lungben committed Jul 22, 2020
1 parent 7cc6fee commit 3f4abc4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Curves"
uuid = "9bed79ab-e35b-4b7a-8527-918872a9571e"
authors = ["Benjamin Lungwitz <[email protected]>"]
version = "0.2.4"
version = "0.2.5"

[deps]
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
Expand Down
8 changes: 6 additions & 2 deletions src/Curves.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
4 changes: 4 additions & 0 deletions test/test_tenors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

2 comments on commit 3f4abc4

@lungben
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 register()

@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/18303

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.2.5 -m "<description of version>" 3f4abc4af87df988772351522e764bb70ac7051e
git push origin v0.2.5

Please sign in to comment.