Hi guys 👋
I am not an accountant (not even close), but nonetheless, I feel like accounting is core to finance and should be baked into whatever we do here in some way from the beginning.
Along those lines, I just created a simple accounting package: GeneralLedgers.jl
As I noted here #7, all these packages are registered in the new JuliaFinance registry so you will need to add this registry to use them via:
pkg> registry add https://github.com/JuliaFinance/JuliaFinance.git
and then you should be able to add them as usual, e.g.
I included a very simple example function:
julia> using GeneralLedgers; const GL = GeneralLedgers;
julia> ledger, assets, liabilities, cash, payable, entry = GL.example(); ledger
NewCo
├─ Assets
│ └─ Cash: 0.0 USD
├─ Liabilities
│ └─ Accounts Payable: 0.0 USD
└─ Chart of Accounts:
├─ Accounts Payable: 0.0 USD
└─ Cash: 0.0 USD
At its core, there is just one main Account type, but it uses (my understanding) of Holy traits to dispatch on five primary subaccount types:
GeneralLedger: Top-level Account. Has no parent. Has children. Journal entries cannot be posted directly to a GeneralLedger. Note: Since we use double-entry booking, the balance of the GeneralLedger should always be zero since debits = credits.
DebitGroup: Has a parent. Has children. Journal entries cannot be posted directly to DebitGroups, but for the purpose of aggregating children, it is treated as a debit account, i.e. a debit child increases the balance while a credit child decreases the balance.
CreditGroup: Has a parent. Has children. Journal entries cannot be posted directly to CreditGroups, but for the purpose of aggregating children, it is treated as a credit account, i.e. a debit child decreases the balance while a credit child increases the balance.
DebitAccount: Has a parent. Has no children. Journal entries can be posted directly to a DebitAccount. Debit entries increase the balance and credit entries decrease the balance.
CreditAccount: Has a parent. Has no children. Journal entries can be posted directly to a CreditAccount. Debit entries decrease the balance and credit entries increase the balance.
The example contains a journal Entry
julia> entry
Entry
├─ Debit: Cash
├─ Credit: Accounts Payable
└─ 10.0 USD
and we can post the Entry to the GeneralLedger as follows:
julia> GL.post!(entry); ledger
NewCo
├─ Assets
│ └─ Cash: 10.0 USD
├─ Liabilities
│ └─ Accounts Payable: 10.0 USD
└─ Chart of Accounts:
├─ Accounts Payable: 10.0 USD
└─ Cash: 10.0 USD
Early drafts of this package had an internal Cash type defined. As we have discussed elsewhere, we need to take care and agree on some terminology. For the purposes of this package (and hopefully this organization),
Cash should be thought of as a Position in a Currency.
Thought in this way, Currency is a kind of FinancialInstrument so Cash is a special case of a more general concept of Positions of FinancialInstruments.
I did a bit of meditating over the weekend and came up with a hierarchy. Not set in stone and open for discussion, but I think we need something like this.
At the top are very simple and lean Countries and Currencies. These are kind of primordial types on top of which most others are built.
Sitting under these we have Markets. As I've described elsewhere, I see a Market as a kind of living provider of market quotes, e.g. yield curves, stock prices, implied volatilities, etc. ultimately to be used to price FinancialInstruments.
Sitting under Markets, we have Jurisdictions. A Jurisdiction could be a country, state / province, county, city / municipality, etc. Different Jurisdictions can have different laws / regulations, different tax treatments, different capital adequacy requirements, etc. These all have impacts on accounting.
Sitting under Jurisdictions. we have Entities. An Entity is basically an issuer of FinancialInstruments. These could be governement treasuries, central banks, municipalities, corporations, etc. This is also where we could keep info about counterparties such as credit ratings, etc.
Finally, sitting under Entities, we have FinancialInstruments. Based on conversations here, on Slack and on Discourse, I think most people will be interested in FinancialInstruments. That is the "quant" stuff, i.e. defining and pricing (possibly complex) financial instruments.
This is also where there is a large possibility to overlap with Miletus.jl since a FinancialInstrument is a contract. I suspect we'll need to do a lot of bikeshedding around FinancialInstruments, but it is my hope that we can have other packages spring up to extend Financialinstruments in such a way that it still plays nice with the underlying accounting stuff.
Next, we have Positions sitting under FinancialInstruments. Positions is a generalization of Cash to accommodate a position in either Currency or a FinancialInstrument.
At the bottom of the totem pole, we have GeneralLedgers - as described above - sitting under Positions. So the entire totem pole looks like
Countries / Currencies
Markets
Jurisdictions
Entities
FinancialInstruments
Positions
GeneralLedgers
All these are still skeletal with the most flesh on GeneralLedgers, but I wanted to get something out there working so we can start an important discussion and map things out.
I hope this is helpful and I look forward to feedback / questions / suggestions / etc.
Take care! 😊
Hi guys 👋
I am not an accountant (not even close), but nonetheless, I feel like accounting is core to finance and should be baked into whatever we do here in some way from the beginning.
Along those lines, I just created a simple accounting package: GeneralLedgers.jl
As I noted here #7, all these packages are registered in the new
JuliaFinanceregistry so you will need to add this registry to use them via:and then you should be able to add them as usual, e.g.
pkg> add GeneralLedgersI included a very simple example function:
At its core, there is just one main
Accounttype, but it uses (my understanding) of Holy traits to dispatch on five primary subaccount types:GeneralLedger: Top-levelAccount. Has no parent. Has children. Journal entries cannot be posted directly to aGeneralLedger. Note: Since we use double-entry booking, the balance of theGeneralLedgershould always be zero since debits = credits.DebitGroup: Has a parent. Has children. Journal entries cannot be posted directly toDebitGroups, but for the purpose of aggregating children, it is treated as a debit account, i.e. a debit child increases the balance while a credit child decreases the balance.CreditGroup: Has a parent. Has children. Journal entries cannot be posted directly toCreditGroups, but for the purpose of aggregating children, it is treated as a credit account, i.e. a debit child decreases the balance while a credit child increases the balance.DebitAccount: Has a parent. Has no children. Journal entries can be posted directly to aDebitAccount. Debit entries increase the balance and credit entries decrease the balance.CreditAccount: Has a parent. Has no children. Journal entries can be posted directly to aCreditAccount. Debit entries decrease the balance and credit entries increase the balance.The example contains a journal
Entryand we can
posttheEntryto theGeneralLedgeras follows:Early drafts of this package had an internal
Cashtype defined. As we have discussed elsewhere, we need to take care and agree on some terminology. For the purposes of this package (and hopefully this organization),Thought in this way,
Currencyis a kind ofFinancialInstrumentsoCashis a special case of a more general concept ofPositionsofFinancialInstruments.I did a bit of meditating over the weekend and came up with a hierarchy. Not set in stone and open for discussion, but I think we need something like this.
At the top are very simple and lean
CountriesandCurrencies. These are kind of primordial types on top of which most others are built.Sitting under these we have
Markets. As I've described elsewhere, I see aMarketas a kind of living provider of market quotes, e.g. yield curves, stock prices, implied volatilities, etc. ultimately to be used to priceFinancialInstruments.Sitting under
Markets, we haveJurisdictions. AJurisdictioncould be a country, state / province, county, city / municipality, etc. DifferentJurisdictionscan have different laws / regulations, different tax treatments, different capital adequacy requirements, etc. These all have impacts on accounting.Sitting under
Jurisdictions. we haveEntities. AnEntityis basically an issuer ofFinancialInstruments. These could be governement treasuries, central banks, municipalities, corporations, etc. This is also where we could keep info about counterparties such as credit ratings, etc.Finally, sitting under
Entities, we haveFinancialInstruments. Based on conversations here, on Slack and on Discourse, I think most people will be interested inFinancialInstruments. That is the "quant" stuff, i.e. defining and pricing (possibly complex) financial instruments.This is also where there is a large possibility to overlap with Miletus.jl since a
FinancialInstrumentis a contract. I suspect we'll need to do a lot of bikeshedding aroundFinancialInstruments, but it is my hope that we can have other packages spring up to extendFinancialinstrumentsin such a way that it still plays nice with the underlying accounting stuff.Next, we have
Positionssitting underFinancialInstruments.Positionsis a generalization ofCashto accommodate a position in eitherCurrencyor aFinancialInstrument.At the bottom of the totem pole, we have
GeneralLedgers- as described above - sitting underPositions. So the entire totem pole looks likeCountries/CurrenciesMarketsJurisdictionsEntitiesFinancialInstrumentsPositionsGeneralLedgersAll these are still skeletal with the most flesh on
GeneralLedgers, but I wanted to get something out there working so we can start an important discussion and map things out.I hope this is helpful and I look forward to feedback / questions / suggestions / etc.
Take care! 😊