Primary interface:
- Defining a
Ledger.ValuationBasis
- Defining how to account for that with
Ledger.value(::ValuationBasis,myType)
Define a new valuation basis and a simple asset type:
# Extending the interface for my own types/valuation basis
struct MyValuationBasis <: Ledger.ValuationBasis end
struct MyCash <: Ledger.Asset
balance
end
Ledger.value(::MyValuationBasis,b::MyCash) = b.balance
Now create a GeneralLedger
which will contain references to the underlying objects and be able to value them:
gl = GeneralLedger()
addAsset!(gl,MyCash(100))
With a single asset in the ledger, show the assets, liabilities, and equity:
bal = Balance(MyValuationBasis(),gl)
@test sum(bal.assets) == 100.0
@test length(bal.liabilities) == 0
@test sum(bal.equity) == 100.0
Extending the example to include a liability with a more complex value
function:
struct myDebt <: Ledger.Liability
balance
int_rate
years_due
end
Ledger.value(::MyValuationBasis,b::myDebt) = b.balance / (1+ b.int_rate) ^ b.years_due
addLiability!(gl,myDebt(50,0.05,3))
bal = Balance(MyValuationBasis(),gl)
@test sum(bal.assets) == 100.0
@test sum(bal.liabilities) == 50 / 1.05 ^ 3
@test sum(bal.equity) == 100.0 - 50 / 1.05 ^ 3