Skip to content

Commit

Permalink
Allow CashflowProjections to be pved (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
alecloudenback authored Nov 4, 2023
1 parent 90187c1 commit 95c8c5f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/Projection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions src/model/Model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/sp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 95c8c5f

Please sign in to comment.