Skip to content

Commit 4776b60

Browse files
update for DataInterpolations 7.0 (#197)
The extrapolation argument for splines now has more options. See DataInterpolations documentation for more details.
1 parent 59d2185 commit 4776b60

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "FinanceModels"
22
uuid = "77f2ae65-bdde-421f-ae9d-22f1af19dd76"
33
authors = ["Alec Loudenback <[email protected]> and contributors"]
4-
version = "4.12.0"
4+
version = "4.13.0"
55

66
[deps]
77
AccessibleOptimization = "d88a00a0-4a21-4fe4-a515-e2123c37b885"
@@ -30,12 +30,12 @@ FinanceModelsUnicodePlots = "UnicodePlots"
3030
[compat]
3131
AccessibleOptimization = "^0.1.2"
3232
Accessors = "^0.1"
33-
DataInterpolations = "5,6"
33+
DataInterpolations = "8"
3434
Dates = "^1.6"
3535
FinanceCore = "^2.1"
3636
IntervalSets = "^0.7"
3737
LinearAlgebra = "1"
38-
MakieCore = "0.7, 0.8"
38+
MakieCore = "0.8,0.9"
3939
Optimization = "4"
4040
OptimizationMetaheuristics = "0.3"
4141
PrecompileTools = "^1.1"

src/model/Yield.jl

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ struct Constant{R} <: AbstractYieldModel
2323
rate::R
2424
end
2525

26-
function Constant(rate::R) where {R<:Real}
27-
Constant(FinanceCore.Rate(rate))
26+
function Constant(rate::R) where {R <: Real}
27+
return Constant(FinanceCore.Rate(rate))
2828
end
2929

3030
Constant() = Constant(0.0)
3131

3232
FinanceCore.discount(c::Constant, t) = FinanceCore.discount(c.rate, t)
3333

3434
# used as the object which gets optmized before finally returning a completed spline
35-
struct IntermediateYieldCurve{T<:Sp.SplineCurve,U,V} <: AbstractYieldModel
35+
struct IntermediateYieldCurve{T <: Sp.SplineCurve, U, V} <: AbstractYieldModel
3636
b::T
3737
xs::Vector{U}
3838
ys::Vector{V} # here, ys are the discount factors
@@ -67,17 +67,17 @@ function Spline(b::Sp.BSpline, xs, ys)
6767
:Average
6868
end
6969

70-
return Spline(DataInterpolations.BSplineInterpolation(ys, xs, order, :Uniform, knot_type; extrapolate=true))
70+
return Spline(DataInterpolations.BSplineInterpolation(ys, xs, order, :Uniform, knot_type; extrapolation = DataInterpolations.ExtrapolationType.Extension))
7171
end
7272

7373
function Spline(b::Sp.PolynomialSpline, xs, ys)
7474
order = min(length(xs) - 1, b.order) # in case the length of xs is less than the spline order
7575
if order == 1
76-
return Spline(DataInterpolations.LinearInterpolation(ys, xs; extrapolate=true))
76+
return Spline(DataInterpolations.LinearInterpolation(ys, xs; extrapolation = DataInterpolations.ExtrapolationType.Extension))
7777
elseif order == 2
78-
return Spline(DataInterpolations.QuadraticSpline(ys, xs; extrapolate=true))
78+
return Spline(DataInterpolations.QuadraticSpline(ys, xs; extrapolation = DataInterpolations.ExtrapolationType.Extension))
7979
else
80-
return Spline(DataInterpolations.CubicSpline(ys, xs; extrapolate=true))
80+
return Spline(DataInterpolations.CubicSpline(ys, xs; extrapolation = DataInterpolations.ExtrapolationType.Extension))
8181
end
8282
end
8383

@@ -91,15 +91,15 @@ include("Yield/NelsonSiegelSvensson.jl")
9191
9292
The discount factor for the yield curve `yc` for times `from` through `to`.
9393
"""
94-
FinanceCore.discount(yc::T, from, to) where {T<:AbstractYieldModel} = discount(yc, to) / discount(yc, from)
94+
FinanceCore.discount(yc::T, from, to) where {T <: AbstractYieldModel} = discount(yc, to) / discount(yc, from)
9595

9696
"""
9797
forward(yc, from, to)˚
9898
9999
The forward `Rate` implied by the yield curve `yc` between times `from` and `to`.
100100
"""
101-
function FinanceCore.forward(yc::T, from, to=from + 1) where {T<:AbstractYieldModel}
102-
Continuous(log(discount(yc, from) / discount(yc, to)) / (to - from))
101+
function FinanceCore.forward(yc::T, from, to = from + 1) where {T <: AbstractYieldModel}
102+
return Continuous(log(discount(yc, from) / discount(yc, to)) / (to - from))
103103
end
104104

105105
"""
@@ -128,7 +128,7 @@ julia> Yields.par(c,2.5)
128128
Yields.Rate{Float64, Yields.Periodic}(0.03960780543711406, Yields.Periodic(2))
129129
```
130130
"""
131-
function par(curve, time; frequency=2)
131+
function par(curve, time; frequency = 2)
132132
mat_disc = discount(curve, time)
133133
coup_times = coupon_times(time, frequency)
134134
coupon_pv = sum(discount(curve, t) for t in coup_times)
@@ -148,7 +148,7 @@ end
148148
149149
Return the zero rate for the curve at the given time.
150150
"""
151-
function Base.zero(c::YC, time) where {YC<:AbstractYieldModel}
151+
function Base.zero(c::YC, time) where {YC <: AbstractYieldModel}
152152
df = discount(c, time)
153153
r = -log(df) / time
154154
return Continuous(r)
@@ -177,7 +177,7 @@ Can only be created via the public API by using the `+`, `-`, `*`, and `/` opera
177177
As this is double the normal operations when performing calculations, if you are using the curve in performance critical locations, you should consider transforming the inputs and
178178
constructing a single curve object ahead of time.
179179
"""
180-
struct CompositeYield{T,U,V} <: AbstractYieldModel
180+
struct CompositeYield{T, U, V} <: AbstractYieldModel
181181
r1::T
182182
r2::U
183183
op::V
@@ -217,13 +217,13 @@ While `ForwardStarting` could be nested so that, e.g. the third period's curve i
217217
218218
`ForwardStarting` is not used to construct a curve based on forward rates.
219219
"""
220-
struct ForwardStarting{T,U} <: AbstractYieldModel
220+
struct ForwardStarting{T, U} <: AbstractYieldModel
221221
curve::U
222222
forwardstart::T
223223
end
224224

225225
function FinanceCore.discount(c::ForwardStarting, to)
226-
FinanceCore.discount(c.curve, c.forwardstart, to + c.forwardstart)
226+
return FinanceCore.discount(c.curve, c.forwardstart, to + c.forwardstart)
227227
end
228228

229229
"""
@@ -239,11 +239,11 @@ function Base.:+(a::Constant, b::Constant)
239239
return Constant(a.rate + b.rate)
240240
end
241241

242-
function Base.:+(a::T, b) where {T<:AbstractYieldModel}
242+
function Base.:+(a::T, b) where {T <: AbstractYieldModel}
243243
return a + Constant(b)
244244
end
245245

246-
function Base.:+(a, b::T) where {T<:AbstractYieldModel}
246+
function Base.:+(a, b::T) where {T <: AbstractYieldModel}
247247
return Constant(a) + b
248248
end
249249

@@ -279,11 +279,11 @@ function Base.:*(a::Constant, b::Constant)
279279
)
280280
end
281281

282-
function Base.:*(a::T, b) where {T<:AbstractYieldModel}
282+
function Base.:*(a::T, b) where {T <: AbstractYieldModel}
283283
return a * Constant(b)
284284
end
285285

286-
function Base.:*(a, b::T) where {T<:AbstractYieldModel}
286+
function Base.:*(a, b::T) where {T <: AbstractYieldModel}
287287
return Constant(a) * b
288288
end
289289

@@ -297,14 +297,14 @@ function Base.:-(a::AbstractYieldModel, b::AbstractYieldModel)
297297
end
298298

299299
function Base.:-(a::Constant, b::Constant)
300-
Constant(a.rate - b.rate)
300+
return Constant(a.rate - b.rate)
301301
end
302302

303-
function Base.:-(a::T, b) where {T<:AbstractYieldModel}
303+
function Base.:-(a::T, b) where {T <: AbstractYieldModel}
304304
return a - Constant(b)
305305
end
306306

307-
function Base.:-(a, b::T) where {T<:AbstractYieldModel}
307+
function Base.:-(a, b::T) where {T <: AbstractYieldModel}
308308
return Constant(a) - b
309309
end
310310

@@ -340,11 +340,11 @@ function Base.:/(a::Constant, b::Constant)
340340
)
341341
end
342342

343-
function Base.:/(a::T, b) where {T<:AbstractYieldModel}
343+
function Base.:/(a::T, b) where {T <: AbstractYieldModel}
344344
return a / Constant(b)
345345
end
346346

347-
function Base.:/(a, b::T) where {T<:AbstractYieldModel}
347+
function Base.:/(a, b::T) where {T <: AbstractYieldModel}
348348
return Constant(a) / b
349349
end
350350

0 commit comments

Comments
 (0)