diff --git a/src/generics.jl b/src/generics.jl index f848ee83..608afe78 100644 --- a/src/generics.jl +++ b/src/generics.jl @@ -58,17 +58,11 @@ Yields.Rate{Float64, Yields.Periodic}(0.03960780543711406, Yields.Periodic(2)) """ function par(curve, time; frequency=2) - mat_disc = discount(curve, time) coup_times = coupon_times(time,frequency) - coupon_pv = sum(discount(curve,t) for t in coup_times) Δt = step(coup_times) - r = (1-mat_disc) / coupon_pv - cfs = [t == last(coup_times) ? 1+r : r for t in coup_times] - # `sign(r)`` is used instead of `1` because there are times when the coupons are negative so we want to flip the sign - cfs = [-1;cfs] - r = internal_rate_of_return(cfs,[0;coup_times]) frequency_inner = min(1/Δt,max(1 / Δt, frequency)) - r = convert(Periodic(frequency_inner),r) + r = (1-discount(curve,time))/sum(discount(curve,t) for t in coup_times) * 1/Δt + r = Periodic(r,frequency_inner) return r end