@@ -78,9 +78,9 @@ See also: [`Continuous`](@ref)
7878"""
7979Periodic (x,frequency) = Rate (x, Periodic (frequency))
8080
81- struct Rate
82- value
83- compounding:: CompoundingFrequency
81+ struct Rate{N <: Real ,T <: CompoundingFrequency }
82+ value:: N
83+ compounding:: T
8484end
8585
8686# Base.:==(r1::Rate,r2::Rate) = (r1.value == r2.value) && (r1.compounding == r2.compounding)
@@ -141,7 +141,9 @@ julia> convert(Continuous(),r)
141141Rate(0.009995835646701251, Continuous())
142142```
143143"""
144- Base. convert (T:: CompoundingFrequency ,r:: Rate ) = convert (T, r, r. compounding)
144+ function Base. convert (T:: CompoundingFrequency ,r:: Rate{<:Real,<:CompoundingFrequency} )
145+ convert (T, r, r. compounding)
146+ end
145147function Base. convert (to:: Continuous , r, from:: Continuous )
146148 return r
147149end
@@ -159,8 +161,9 @@ function Base.convert(to::Periodic, r, from::Periodic)
159161return convert (to, c, Continuous ())
160162end
161163
162- rate (r:: Rate ) = r. value
163-
164+ function rate (r:: Rate{<:Real,<:CompoundingFrequency} )
165+ r. value
166+ end
164167
165168"""
166169An AbstractYield is an object which can be used as an argument to:
@@ -221,8 +224,8 @@ julia> discount(y,2)
2212240.9070294784580498 # 1 / (1.05) ^ 2
222225```
223226"""
224- struct Constant <: AbstractYield
225- rate
227+ struct Constant{T} <: AbstractYield
228+ rate:: T
226229end
227230
228231function Constant (rate:: T ) where {T <: Real }
@@ -338,7 +341,7 @@ Rate(0.06000000000000005, Periodic(1))
338341
339342```
340343"""
341- function Par (rates:: Vector{Rate} , maturities)
344+ function Par (rates:: Vector{<: Rate} , maturities)
342345 # bump to a constant yield if only given one rate
343346 if length (rates) == 1
344347 return Constant (rate[1 ])
@@ -394,7 +397,7 @@ function CMT(rates::Vector{T}, maturities) where {T <: Real}
394397 CMT (rs, maturities)
395398end
396399
397- function CMT (rates:: Vector{Rate} , maturities)
400+ function CMT (rates:: Vector{<: Rate} , maturities)
398401 return YieldCurve (
399402 rates,
400403 maturities,
@@ -421,7 +424,7 @@ function OIS(rates::Vector{T}, maturities) where {T <: Real}
421424
422425 return OIS (rs, maturities)
423426end
424- function OIS (rates:: Vector{Rate} , maturities)
427+ function OIS (rates:: Vector{<: Rate} , maturities)
425428 return YieldCurve (
426429 rates,
427430 maturities,
708711The discount factor for the `rate` for times `from` through `to`. If rate is a `Real` number, will assume a `Constant` interest rate.
709712"""
710713discount (yc,time) = yc. discount (time)
711- discount (rate:: Rate ,from,to) = discount (Constant (rate), from, to)
712- discount (rate:: Rate ,to) = discount (Constant (rate), to)
714+ discount (rate:: Rate{<:Real,<:CompoundingFrequency} ,from,to) = discount (Constant (rate), from, to)
715+ discount (rate:: Rate{<:Real,<:CompoundingFrequency} ,to) = discount (Constant (rate), to)
713716
714717
715718
@@ -731,12 +734,12 @@ The accumulation factor for the `rate` for times `from` through `to`. If rate is
731734function accumulation (y:: T , time) where {T <: AbstractYield }
732735 return 1 ./ discount (y, time)
733736end
734- accumulation (rate:: Rate ,to) = accumulation (Constant (rate), to)
737+ accumulation (rate:: Rate{<:Real,<:CompoundingFrequency} ,to) = accumulation (Constant (rate), to)
735738
736739function accumulation (y:: T , from, to) where {T <: AbstractYield }
737740 return 1 ./ discount (y, from, to)
738741end
739- accumulation (rate:: Rate ,from,to) = accumulation (Constant (rate), from, to)
742+ accumulation (rate:: Rate{<:Real,<:CompoundingFrequency} ,from,to) = accumulation (Constant (rate), from, to)
740743
741744# # Curve Manipulations
742745struct RateCombination <: AbstractYield
0 commit comments