https://github.com/alecloudenback/ledger
https://github.com/alecloudenback/ledger
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/alecloudenback/ledger
- Owner: alecloudenback
- License: mit
- Created: 2020-05-17T21:20:36.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-17T21:21:59.000Z (about 6 years ago)
- Last Synced: 2025-10-10T14:42:39.375Z (9 months ago)
- Language: Julia
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ledger
[](https://alecloudenback.github.io/Ledger.jl/stable)
[](https://alecloudenback.github.io/Ledger.jl/dev)
Primary interface:
- Defining a `Ledger.ValuationBasis`
- Defining how to account for that with `Ledger.value(::ValuationBasis,myType)`
## Example
Define a new valuation basis and a simple asset type:
```julia
# 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:
```julia
gl = GeneralLedger()
addAsset!(gl,MyCash(100))
```
With a single asset in the ledger, show the assets, liabilities, and equity:
```julia
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:
```julia
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
```