diff --git a/src/Projection.jl b/src/Projection.jl index ab20805..ba2a503 100644 --- a/src/Projection.jl +++ b/src/Projection.jl @@ -208,3 +208,11 @@ function __rewrap(from, to) # we've hit bottom, so return `to` return to end + +function FinanceCore.present_value(model, p::FinanceModels.Projection{C,M,K}, cur_time=0.0) where +{ + C,M,K<:FinanceModels.CashflowProjection +} + xf = p |> Filter(cf -> cf.time >= cur_time) |> Map(cf -> FinanceCore.discount(model, cur_time, cf.time) * cf.amount) + foldxl(+, xf) +end diff --git a/src/model/Model.jl b/src/model/Model.jl index 779da3c..f06ba7b 100644 --- a/src/model/Model.jl +++ b/src/model/Model.jl @@ -19,8 +19,9 @@ include("Equity.jl") """ present_value(model,contract,current_time=0.0) - -Return the value of the contract as corresponding with the valuation assumptions embedded in the `model`. + present_value(model,projection,current_time=0.0) + + Return the value of the contract as corresponding with the valuation assumptions embedded in the `model` for the given contract or projection with `CashflowProjection` kind. # Examples diff --git a/test/sp.jl b/test/sp.jl index 0755814..74c21c1 100644 --- a/test/sp.jl +++ b/test/sp.jl @@ -20,6 +20,7 @@ end @test collect(Bond.Fixed(0.05, Periodic(1), 1)) == [Cashflow(1.05, 1.0)] @test pv(Yield.Constant(0.05), Bond.Fixed(0.05, Periodic(1), 3.0)) ≈ 1.0 + @test pv(Yield.Constant(0.05), p) ≈ 1.0 end @testset "Floating Bonds" begin