Entities and statements#
An entity is a company with its own books. m.entity(...) creates one, and its income statement (co.pl), balance
sheet (co.bs) and cash-flow statement (co.cf) are built from the entity’s layout. The line makers inside co.pl
and co.bs are documented on the LineMaker page and the Line makers pages. This page documents
everything else on the entity, the statement objects, fiscal calendars, business-day calendars, and the error raised
when the books do not balance.
Entity#
The four OCI names are four different things: co.oci(...) books an item, co.bs.oci is the equity line maker that holds
the accumulated amount, co.other_comprehensive_income is the series of the period’s OCI, and co.oci_release(...)
reclassifies accumulated OCI.
- class boki.ledger.Entity(model, name, standard, fiscal=None, layout=None, currency=None, tax_rate=None)#
A company with its own books: one double-entry ledger, three statements, and the lines that fill them.
m.entity(...)creates an entity and returns it, andcostands for one in these docs. The entity owns an account for cash and one for retained earnings;co.plandco.bshold one LineMaker for each kind in the entity’s layout. Every line item posts balanced entries (an amount, a debit account, a credit account) to the ledger, and the balance sheet, the cash-flow statement, and their checks are derived from those entries. The entity’s values are Series that you read from the result ofm.render().- Parameters:
- modelModel
The model the entity belongs to. Created through
Model.entity, which also registers the entity there.- namestr
Entity name; required. It must be unique among the entities and groups of the model.
- standardStandard
Accounting standard,
b.JGAAP,b.IFRSorb.USGAAP. It sets the general layout, the labels, and the standard-specific accounting.Model.entityusesb.JGAAPwhen it is not given.- fiscalFiscal | None
Fiscal calendar made by
b.fiscal(...). Statements groupedby="fiscal_year"and the Excel statement columns use it. The default isNone, which means no fiscal calendar.- layoutLayout | None
Kinds and subtotals of the statements, such as
b.layouts.bank. The default isNone, the general layout of the standard.- currencyUnit | None
The functional currency, such as
JPY. The default isNone: the unit of the first amount booked sets it, and every later amount must be in the same unit.- tax_ratefloat | Series | Quantity | None
Default tax rate for deferred tax (
bs.deferred_tax) and taxed OCI (oci(..., tax=True)), a dimensionless ratio such as0.3for 30%. The default isNone, which makes those calls need their ownrate=.
- Attributes:
- modelModel
The model the entity belongs to.
- namestr
The entity’s name.
- standardStandard
The accounting standard.
- fiscalFiscal or None
The fiscal calendar, or
Nonewhen the entity has none.- layoutLayout
The layout of kinds and subtotals in use.
- tax_ratefloat, Series, Quantity, or None
The default tax rate given at creation, or
None.- plPL
The income statement: one LineMaker for each PL kind of the layout, and the layout’s subtotals as series.
- bsBS
The balance sheet: cash, one LineMaker for each BS kind of the layout, the totals, and the generic
assetandliabilitymakers.- cfCF
The cash-flow statement as series, by section.
- checksEntityChecks
The entity’s built-in check, for configuration.
- net_incomeSeries
The period’s net income, the same series as
co.pl.net_income. The unit is the entity’s currency per period. Every layout needs anet_incomesubtotal, soModel.entityraisesAttributeErrorfor a layout without one.- other_comprehensive_incomeSeries
The period’s other comprehensive income (OCI) after tax: the sum of the lines that
ocicreated, in the entity’s currency per period. It is 0 when the entity has booked no OCI. This is the period total, not the balance (bs.oci) and not the booking call (oci).- comprehensive_incomeSeries
net_incomeplusother_comprehensive_incomein each period.
See also
boki.LineMakerThe callable behind every
co.pl.<kind>andco.bs.<kind>.
Notes
Creating an entity through
Model.entityraisesValueErrorif the name is already used by an entity or group of the model, andAttributeErrorif the layout has nonet_incomesubtotal.The ledger is double-entry, and the entity verifies it when the model renders: assets equal liabilities plus equity in every period, the opening balance sheet balances, cash-flow sections add up to the change in cash, and the indirect cash flow equals the direct one. A failure raises LedgerError. See the double-entry notes for the design and consolidation for how groups combine entity ledgers.
Four names concern other comprehensive income, and they are four different things:
co.oci(name, amount, against=...)is a call that books one OCI item and returns its line;co.bs.ociis the equity line maker of kindoci, whose lines keep the accumulated OCI that is part of equity in theirbalance;co.other_comprehensive_incomeis the series of the period’s total OCI, after tax;co.oci_release(name, amount)is a call that reclassifies accumulated OCI to profit or retained earnings.
Examples
A monthly entity that earns 100 a month with 40 of costs, and its three statements:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Cafe", start="2027-01", periods=3, step=b.month) >>> co = m.entity("Cafe", standard=b.IFRS, currency=JPY) >>> co.bs.opening(cash=1000) >>> sales = co.pl.revenue("Sales", 100) >>> costs = co.pl.sga("Costs", 40) >>> r = m.render() >>> [r.value(co.net_income, month) for month in ("2027-01", "2027-02", "2027-03")] [60, 60, 60] >>> round(r.value(co.bs.cash, "2027-03")) 1180 >>> round(r.value(co.cf.operating, "2027-03")) 60
- property adjusted_ebitda#
Adjusted EBITDA, which boki refuses to define.
Reading this property always raises
AttributeError. Adjusted EBITDA has no standard definition, and a default would hide choices that change the number (goodwill, impairment, leases, one-off items). Build it yourself as a named series fromoperating_income,depreciation,amortizationand the adjustments you choose.- Raises:
- AttributeError
Always, when the property is read. The message shows how to build the measure from the parts.
See also
boki.ledger.Entity.operating_incomeThe operating income subtotal.
boki.ledger.Entity.depreciationDepreciation of tangible assets.
boki.ledger.Entity.amortizationAmortization of intangible assets.
Notes
EBITDA is a non-GAAP measure under J-GAAP, IFRS and US GAAP, so boki provides its parts and leaves the definition to the modeler. The standards differ in what goes into the parts:
Goodwill. J-GAAP amortizes it (up to 20 years, in SG&A), so J-GAAP EBITDA conventionally adds it back. IFRS and US GAAP do not amortize it (impairment only; US private companies may elect amortization).
Impairment. J-GAAP books it as an extraordinary loss, below operating income. IFRS and US GAAP book it within operating results, so adding it back is the modeler’s choice. Neither
depreciationnoramortizationincludes it.Leases. boki has no lease accounting yet. IFRS 16 puts most leases on the balance sheet (depreciation plus interest), ASC 842 operating leases stay a straight-line operating cost, and J-GAAP’s new lease standard is modeled on IFRS 16.
Operating income. Defined under J-GAAP. IFRS 18 (effective 2027-01-01) defines operating profit. US GAAP has no required subtotal.
Development costs. Capitalized under IFRS when the criteria are met (their amortization is in
amortization). Expensed under US GAAP and J-GAAP.
Examples
Reading the property raises
AttributeError:>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Parts", start="2027-01", periods=2, step=b.year) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> try: ... co.adjusted_ebitda ... except AttributeError as error: ... print(str(error).startswith("Adjusted EBITDA has no standard definition")) True
- property amortization#
Amortization of intangible assets, as a Series of positive expense.
The same as
depreciationforintangiblelines. Impairment is not included. On a consolidated group (Group.amortization) it also holds goodwill amortization.- Returns:
- Series
Amortization expense in each period, positive, in the entity’s currency per period.
Notes
EBITDA is a non-GAAP measure under J-GAAP, IFRS and US GAAP, so boki provides its parts and leaves the definition to the modeler. The standards differ in what goes into the parts:
Goodwill. J-GAAP amortizes it (up to 20 years, in SG&A), so J-GAAP EBITDA conventionally adds it back. IFRS and US GAAP do not amortize it (impairment only; US private companies may elect amortization).
Impairment. J-GAAP books it as an extraordinary loss, below operating income. IFRS and US GAAP book it within operating results, so adding it back is the modeler’s choice. Neither
depreciationnoramortizationincludes it.Leases. boki has no lease accounting yet. IFRS 16 puts most leases on the balance sheet (depreciation plus interest), ASC 842 operating leases stay a straight-line operating cost, and J-GAAP’s new lease standard is modeled on IFRS 16.
Operating income. Defined under J-GAAP. IFRS 18 (effective 2027-01-01) defines operating profit. US GAAP has no required subtotal.
Development costs. Capitalized under IFRS when the criteria are met (their amortization is in
amortization). Expensed under US GAAP and J-GAAP.
Examples
Software bought in the first month for 300 and amortized over three months:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Amortization", start="2027-01", periods=4, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> co.bs.opening(cash=1000) >>> software = co.bs.intangible("Software", cost=300, at=0, life=3 * b.month) >>> r = m.render() >>> [round(r.value(co.amortization, month)) for month in ("2027-01", "2027-02", "2027-03")] [0, 100, 100] >>> round(r.value(co.depreciation, "2027-02")) 0
- property currency#
The entity’s functional currency.
- Returns:
- Unit | frozenset | None
The Unit given as
currency=when the entity was created. Otherwise the dimensions of the unit of the first amount booked, as an opaquefrozenset, orNonewhile no amount has been booked. Every later amount must be in the same currency.
Examples
The unit of the first amount sets the currency when none was declared:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Currency", start="2027-01", periods=2, step=b.month) >>> co = m.entity("A", standard=b.IFRS) >>> co.currency is None True >>> sales = co.pl.revenue("Sales", 100 * JPY) >>> co.currency == JPY.dims True >>> m.entity("B", standard=b.IFRS, currency=JPY).currency is JPY True
- property depreciation#
Depreciation of tangible assets, as a Series of positive expense.
Every
fixed_assetline that is notintangibleand every completedconstructionline, wherever the expense is posted in the PL (any PL kind, anycategory=,depreciation=given directly, a capex program, an intercompany asset purchase). The assets decide, not the PL line: use this instead of summing a category. Impairment and losses on sale are not included.- Returns:
- Series
Depreciation expense in each period, positive, in the entity’s currency per period.
Notes
EBITDA is a non-GAAP measure under J-GAAP, IFRS and US GAAP, so boki provides its parts and leaves the definition to the modeler. The standards differ in what goes into the parts:
Goodwill. J-GAAP amortizes it (up to 20 years, in SG&A), so J-GAAP EBITDA conventionally adds it back. IFRS and US GAAP do not amortize it (impairment only; US private companies may elect amortization).
Impairment. J-GAAP books it as an extraordinary loss, below operating income. IFRS and US GAAP book it within operating results, so adding it back is the modeler’s choice. Neither
depreciationnoramortizationincludes it.Leases. boki has no lease accounting yet. IFRS 16 puts most leases on the balance sheet (depreciation plus interest), ASC 842 operating leases stay a straight-line operating cost, and J-GAAP’s new lease standard is modeled on IFRS 16.
Operating income. Defined under J-GAAP. IFRS 18 (effective 2027-01-01) defines operating profit. US GAAP has no required subtotal.
Development costs. Capitalized under IFRS when the criteria are met (their amortization is in
amortization). Expensed under US GAAP and J-GAAP.
Examples
A machine bought in the first month for 600 and depreciated over six months starts to depreciate in the next month, 100 a month:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Depreciation", start="2027-01", periods=4, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> co.bs.opening(cash=1000) >>> machine = co.bs.fixed_asset("Machine", cost=600, at=0, life=6 * b.month) >>> r = m.render() >>> [round(r.value(co.depreciation, month)) for month in ("2027-01", "2027-02", "2027-03")] [0, 100, 100]
- property ebit#
EBIT, which boki refuses to define.
Reading this property always raises
AttributeError. EBIT has no standard definition, and a default would hide choices that change the number (goodwill, impairment, leases, one-off items). Build it yourself as a named series fromoperating_incomeand the lines you decide belong in EBIT.- Raises:
- AttributeError
Always, when the property is read. The message shows how to build the measure from the parts.
See also
boki.ledger.Entity.operating_incomeThe operating income subtotal.
boki.ledger.Entity.depreciationDepreciation of tangible assets.
boki.ledger.Entity.amortizationAmortization of intangible assets.
Notes
EBITDA is a non-GAAP measure under J-GAAP, IFRS and US GAAP, so boki provides its parts and leaves the definition to the modeler. The standards differ in what goes into the parts:
Goodwill. J-GAAP amortizes it (up to 20 years, in SG&A), so J-GAAP EBITDA conventionally adds it back. IFRS and US GAAP do not amortize it (impairment only; US private companies may elect amortization).
Impairment. J-GAAP books it as an extraordinary loss, below operating income. IFRS and US GAAP book it within operating results, so adding it back is the modeler’s choice. Neither
depreciationnoramortizationincludes it.Leases. boki has no lease accounting yet. IFRS 16 puts most leases on the balance sheet (depreciation plus interest), ASC 842 operating leases stay a straight-line operating cost, and J-GAAP’s new lease standard is modeled on IFRS 16.
Operating income. Defined under J-GAAP. IFRS 18 (effective 2027-01-01) defines operating profit. US GAAP has no required subtotal.
Development costs. Capitalized under IFRS when the criteria are met (their amortization is in
amortization). Expensed under US GAAP and J-GAAP.
Examples
Reading the property raises
AttributeError:>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Parts", start="2027-01", periods=2, step=b.year) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> try: ... co.ebit ... except AttributeError as error: ... print(str(error).startswith("EBIT has no standard definition")) True
- property ebitda#
EBITDA, which boki refuses to define.
Reading this property always raises
AttributeError. EBITDA has no standard definition, and a default would hide choices that change the number (goodwill, impairment, leases, one-off items). Build it yourself as a named series fromoperating_income,depreciationandamortization.- Raises:
- AttributeError
Always, when the property is read. The message shows how to build the measure from the parts.
See also
boki.ledger.Entity.operating_incomeThe operating income subtotal.
boki.ledger.Entity.depreciationDepreciation of tangible assets.
boki.ledger.Entity.amortizationAmortization of intangible assets.
Notes
EBITDA is a non-GAAP measure under J-GAAP, IFRS and US GAAP, so boki provides its parts and leaves the definition to the modeler. The standards differ in what goes into the parts:
Goodwill. J-GAAP amortizes it (up to 20 years, in SG&A), so J-GAAP EBITDA conventionally adds it back. IFRS and US GAAP do not amortize it (impairment only; US private companies may elect amortization).
Impairment. J-GAAP books it as an extraordinary loss, below operating income. IFRS and US GAAP book it within operating results, so adding it back is the modeler’s choice. Neither
depreciationnoramortizationincludes it.Leases. boki has no lease accounting yet. IFRS 16 puts most leases on the balance sheet (depreciation plus interest), ASC 842 operating leases stay a straight-line operating cost, and J-GAAP’s new lease standard is modeled on IFRS 16.
Operating income. Defined under J-GAAP. IFRS 18 (effective 2027-01-01) defines operating profit. US GAAP has no required subtotal.
Development costs. Capitalized under IFRS when the criteria are met (their amortization is in
amortization). Expensed under US GAAP and J-GAAP.
Examples
Reading the property raises
AttributeError:>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Parts", start="2027-01", periods=2, step=b.year) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> try: ... co.ebitda ... except AttributeError as error: ... print(str(error).startswith("EBITDA has no standard definition")) True
- property ebitdar#
EBITDAR, which boki refuses to define.
Reading this property always raises
AttributeError. EBITDAR has no standard definition, and a default would hide choices that change the number (goodwill, impairment, leases, one-off items). Build it yourself as a named series fromoperating_income,depreciation,amortizationand the rent expense line.- Raises:
- AttributeError
Always, when the property is read. The message shows how to build the measure from the parts.
See also
boki.ledger.Entity.operating_incomeThe operating income subtotal.
boki.ledger.Entity.depreciationDepreciation of tangible assets.
boki.ledger.Entity.amortizationAmortization of intangible assets.
Notes
EBITDA is a non-GAAP measure under J-GAAP, IFRS and US GAAP, so boki provides its parts and leaves the definition to the modeler. The standards differ in what goes into the parts:
Goodwill. J-GAAP amortizes it (up to 20 years, in SG&A), so J-GAAP EBITDA conventionally adds it back. IFRS and US GAAP do not amortize it (impairment only; US private companies may elect amortization).
Impairment. J-GAAP books it as an extraordinary loss, below operating income. IFRS and US GAAP book it within operating results, so adding it back is the modeler’s choice. Neither
depreciationnoramortizationincludes it.Leases. boki has no lease accounting yet. IFRS 16 puts most leases on the balance sheet (depreciation plus interest), ASC 842 operating leases stay a straight-line operating cost, and J-GAAP’s new lease standard is modeled on IFRS 16.
Operating income. Defined under J-GAAP. IFRS 18 (effective 2027-01-01) defines operating profit. US GAAP has no required subtotal.
Development costs. Capitalized under IFRS when the criteria are met (their amortization is in
amortization). Expensed under US GAAP and J-GAAP.
Examples
Reading the property raises
AttributeError:>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Parts", start="2027-01", periods=2, step=b.year) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> try: ... co.ebitdar ... except AttributeError as error: ... print(str(error).startswith("EBITDAR has no standard definition")) True
- journal(name, amount, *, debit, credit, cf=None)#
Post an amount from one account of the entity to another.
Use it for entries no line maker books: a transfer between two balance-sheet accounts (a deposit turned into income, a lease asset and liability), or a cash posting that needs its own cash-flow class. The entry debits
debitand creditscreditbyamountin every period.- Parameters:
- namestr
Name of the entry. It names the returned series and the posting (the narration of the Beancount transaction). Required.
- amountscalar, Quantity, Series, or dict
Amount posted in each period, in the entity’s currency per period. A plain number is in the entity’s currency. A quantity per time, such as
100 * JPY / b.month, is integrated by period length. A dict maps period labels, indices, or dates to amounts and posts 0 in the other periods.- debitLineItem, balance, or Account
The account to debit, from this entity’s books: a line item, a balance such as
co.bs.cash, or an account.- creditLineItem, balance, or Account
The account to credit, with the same forms as
debit.- cfstr, optional
Cash-flow section of the entry when it moves cash:
"operating","investing","financing", or"fx". It is ignored when the entry does not touch cash. When it is omitted, a cash entry takes the section of the other account (operating for a PL account).
- Returns:
- Series
The amount posted in each period, named
name.
- Raises:
- ValueError
At construction, if
cfis not one of the four sections, or ifdebitorcreditis an account of another entity (a trade with another entity is booked withcounterparty=on a line instead).- TypeError
At construction, if
debitorcreditis not an account, a balance, or a line item, or ifamounthas a type boki cannot use in an expression.- UnitError
At construction, if
amountis in a unit other than the entity’s currency.
See also
boki.ledger.BS.openingDeclare opening balances instead of posting changes.
Notes
The entry is
Dr debit, Cr credit, with no cash involved unless one of the accounts is cash. When an account is a PL line, the entry changes that line’s value, and so the profit: crediting an income line or debiting an expense line adds to it, and the opposite entries reduce it. Journal entries on the balance sheet alone do not change profit. A cash entry is classified bycf; see the cash-flow rows.Examples
A customer forfeits a deposit of 10 in the first month, which moves it from the liability into income:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Journal", start="2027-01", periods=2, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> co.bs.opening(cash=100) >>> deposit = co.bs.liability("Deposit", opening=100) >>> fees = co.pl.revenue("Fees", 5) >>> entry = co.journal("Forfeited deposit", {0: 10}, debit=deposit, credit=fees) >>> r = m.render() >>> round(r.value(deposit, "2027-01")), round(r.value(deposit, "2027-02")) (90, 90) >>> r.value(fees, "2027-01"), r.value(fees, "2027-02") (15, 5) >>> r.value(co.net_income, "2027-01") 15
- label(key)#
Return the presentation name of a kind, subtotal, or statement line.
The standard’s own term comes first (IFRS says “Profit for the year”), then the common English name. A key that has no name is returned unchanged.
- Parameters:
- keystr
The internal name, such as
"gross_profit","net_income","receivable", or"total_assets".
- Returns:
- str
The name the statements show for
keyunder this entity’s standard, orkeywhen it has none.
See also
boki.StyleStatement titles and labels in the Excel output come from the style.
Examples
The same key has a different name under each standard:
>>> import boki as b >>> m = b.Model("Labels", start="2027-01", periods=1, step=b.year) >>> m.entity("A", standard=b.IFRS).label("net_income") 'Profit for the year' >>> m.entity("B", standard=b.USGAAP).label("net_income") 'Net income' >>> m.entity("C", standard=b.IFRS).label("not_a_line") 'not_a_line'
- property language#
The language of the entity’s statement labels.
- Returns:
- str
"en"for every standard: all labels are English.
Examples
>>> import boki as b >>> m = b.Model("Language", start="2027-01", periods=2, step=b.year) >>> m.entity("A", standard=b.JGAAP).language 'en'
- property noi#
NOI, which boki refuses to define.
Reading this property always raises
AttributeError. NOI has no standard definition, and a default would hide choices that change the number (goodwill, impairment, leases, one-off items). Build it yourself as a named series from revenue and operating expense lines.- Raises:
- AttributeError
Always, when the property is read. The message shows how to build the measure from the parts.
See also
boki.ledger.Entity.operating_incomeThe operating income subtotal.
boki.ledger.Entity.depreciationDepreciation of tangible assets.
boki.ledger.Entity.amortizationAmortization of intangible assets.
Notes
EBITDA is a non-GAAP measure under J-GAAP, IFRS and US GAAP, so boki provides its parts and leaves the definition to the modeler. The standards differ in what goes into the parts:
Goodwill. J-GAAP amortizes it (up to 20 years, in SG&A), so J-GAAP EBITDA conventionally adds it back. IFRS and US GAAP do not amortize it (impairment only; US private companies may elect amortization).
Impairment. J-GAAP books it as an extraordinary loss, below operating income. IFRS and US GAAP book it within operating results, so adding it back is the modeler’s choice. Neither
depreciationnoramortizationincludes it.Leases. boki has no lease accounting yet. IFRS 16 puts most leases on the balance sheet (depreciation plus interest), ASC 842 operating leases stay a straight-line operating cost, and J-GAAP’s new lease standard is modeled on IFRS 16.
Operating income. Defined under J-GAAP. IFRS 18 (effective 2027-01-01) defines operating profit. US GAAP has no required subtotal.
Development costs. Capitalized under IFRS when the criteria are met (their amortization is in
amortization). Expensed under US GAAP and J-GAAP.
Examples
Reading the property raises
AttributeError:>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Parts", start="2027-01", periods=2, step=b.year) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> try: ... co.noi ... except AttributeError as error: ... print(str(error).startswith("NOI has no standard definition")) True
- oci(name, amount, *, against, recycle=True, tax=False)#
Book an item of other comprehensive income (OCI) and return its line.
The item moves
amountin every period between the accountagainst(a security, a hedge, a pension asset) and a reserve in equity namedname, and the profit is untouched. Several calls with one name add to the same reserve.- Parameters:
- namestr
Name of the OCI component, which names the equity reserve. Required. A name used before adds to that component, and it must be given the same
recycleandtax.- amountscalar, Quantity, Series, or dict
OCI arising in each period before tax, in the entity’s currency per period; a loss is negative. A plain number is in the entity’s currency. A quantity per time is integrated by period length. A dict maps period labels, indices, or dates to amounts and books 0 in the other periods.
- againstLineItem, balance, or Account
The account of this entity’s books that takes the other side of the entry, such as a
co.bsline for a security. It is debited byamount. A PL line is allowed: its value falls byamount, which moves the amount from net income into OCI.- recyclebool, default=True
Whether the reserve is later reclassified to profit (
True) or transferred to retained earnings (False) byoci_release. It only takes effect there.- taxbool, default=False
Whether to recognize deferred tax on the OCI at the entity’s
tax_rateand show the OCI net of tax.
- Returns:
- LineItem
The component’s line, of kind
oci. Its value in a period is the OCI after tax, and itsbalanceis the accumulated reserve after tax. Another call with the samenamereturns the same line.
- Raises:
- ValueError
At construction, if
againstis an account of another entity, iftaxis true and the entity has notax_rate, or ifnamewas used before with a differentrecycleortax.- TypeError
At construction, if
againstis not an account, a balance, or a line item, or ifamounthas a type boki cannot use in an expression.- UnitError
At construction, if
amountis in a unit other than the entity’s currency, or the tax rate is not dimensionless.
See also
boki.ledger.Entity.oci_releaseReclassify accumulated OCI to profit or retained earnings.
boki.LineMakerco.bs.ociis the line maker of kindoci, whose lines are the ones this call returns.
Notes
The entry is
Dr against, Cr reserve. The reserve is an equity account of kindoci, shown as “Other components of equity” under IFRS and “Accumulated other comprehensive income” under US GAAP and J-GAAP. Withtax=True, deferred tax is recognized on the cumulative pre-tax OCI at the entity’stax_rate: a deferred tax liability while the cumulative amount is positive (Dr reserve, Cr deferred tax liability) and a deferred tax asset while it is negative. The tax is charged to equity, so profit and cash do not change.The period’s OCI after tax is also in
co.other_comprehensive_income, andco.comprehensive_incomeadds it to net income. Statements show OCI and comprehensive income below net income once the entity has OCI. Whether an item is recycled is a matter of the accounting standard; for example IFRS FVOCI equity instruments and defined-benefit remeasurements are not recycled. See S1: tax effects and OCI.Examples
A gain of 100 on a security in the first year and a loss of 40 in the third, taxed at 30%:
>>> import boki as b >>> from boki.units import JPY >>> years = ["2027", "2028", "2029"] >>> m = b.Model("OCI", start="2027-01", periods=3, step=b.year) >>> co = m.entity("A", standard=b.IFRS, currency=JPY, tax_rate=0.3) >>> security = co.bs.other_asset("Security", opening=0) >>> reserve = co.oci("Fair value reserve", {0: 100, 2: -40}, against=security, tax=True) >>> r = m.render() >>> [round(r.value(reserve, year)) for year in years] [70, 0, -28] >>> [round(r.value(reserve.balance, year)) for year in years] [70, 70, 42] >>> [round(r.value(co.net_income, year)) for year in years] [0, 0, 0] >>> [round(r.value(co.comprehensive_income, year)) for year in years] [70, 0, -28]
- oci_release(name, amount)#
Reclassify accumulated OCI of a component to profit or to retained earnings.
Call it when the item behind an OCI component is sold or settled. A component booked with
recycle=Truemoves the amount into profit, and one booked withrecycle=Falsemoves it to retained earnings. Neither moves cash.- Parameters:
- namestr
Name of an OCI component created by
oci. Required.- amountscalar, Quantity, Series, or dict
Amount released in each period, before tax, in the entity’s currency per period, with the forms of the
amountofoci. A dict books 0 in the other periods.
- Returns:
- Series
For a recycled component, the new profit line named
OCI release: <name>, a LineItem whose value is the amount released into profit. For a component that is not recycled, the released amount.
- Raises:
- ValueError
At construction, if the entity has no OCI component called
name, if a recycled component was released before (the profit lineOCI release: <name>already exists), or if a recycled component is released on a layout without a non-revenue income kind.- TypeError
At construction, if
amounthas a type boki cannot use in an expression.- UnitError
At construction, if
amountis in a unit other than the entity’s currency.
See also
boki.ledger.Entity.ociBook the OCI that this call releases.
Notes
A recycled release is booked as a profit line against the reserve,
Dr reserve, Cr income. The line goes to the first ofother_income,non_operating_income,non_interest_income,special_gainandfinance_incomethat the layout has (other_incomefor IFRS and US GAAP,non_operating_incomefor J-GAAP,non_interest_incomefor the bank layout). The period’s OCI falls by the amount, so before tax the transfer leaves comprehensive income unchanged. A release that is not recycled isDr reserve, Cr retained earningsand is a transfer inside equity.The amount is before tax. With
tax=Trueon the component, the deferred tax on the released amount is reversed and the reserve falls by the after-tax amount. A recycled release does not book the realized tax for you: record it in an income tax line. See the OCI tax rules in S1.Examples
A gain of 100 is booked in the first year and released into profit in the second:
>>> import boki as b >>> from boki.units import JPY >>> years = ["2027", "2028", "2029"] >>> m = b.Model("Release", start="2027-01", periods=3, step=b.year) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> security = co.bs.other_asset("Security", opening=0) >>> reserve = co.oci("Fair value reserve", {0: 100}, against=security) >>> released = co.oci_release("Fair value reserve", {1: 100}) >>> r = m.render() >>> [round(r.value(co.net_income, year)) for year in years] [0, 100, 0] >>> [round(r.value(co.other_comprehensive_income, year)) for year in years] [100, -100, 0] >>> [round(r.value(co.comprehensive_income, year)) for year in years] [100, 0, 0]
- property operating_income#
The layout’s operating income subtotal, the same series as
co.pl.operating_income.- Returns:
- Series
Operating income in each period, in the entity’s currency per period.
- Raises:
- AttributeError
At construction, when the property is read on a layout without an operating income subtotal, such as the bank layout.
Notes
EBITDA is a non-GAAP measure under J-GAAP, IFRS and US GAAP, so boki provides its parts and leaves the definition to the modeler. The standards differ in what goes into the parts:
Goodwill. J-GAAP amortizes it (up to 20 years, in SG&A), so J-GAAP EBITDA conventionally adds it back. IFRS and US GAAP do not amortize it (impairment only; US private companies may elect amortization).
Impairment. J-GAAP books it as an extraordinary loss, below operating income. IFRS and US GAAP book it within operating results, so adding it back is the modeler’s choice. Neither
depreciationnoramortizationincludes it.Leases. boki has no lease accounting yet. IFRS 16 puts most leases on the balance sheet (depreciation plus interest), ASC 842 operating leases stay a straight-line operating cost, and J-GAAP’s new lease standard is modeled on IFRS 16.
Operating income. Defined under J-GAAP. IFRS 18 (effective 2027-01-01) defines operating profit. US GAAP has no required subtotal.
Development costs. Capitalized under IFRS when the criteria are met (their amortization is in
amortization). Expensed under US GAAP and J-GAAP.
Examples
Operating income is the subtotal before finance items and tax, here sales less costs:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Operating", start="2027-01", periods=2, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> sales = co.pl.revenue("Sales", 100) >>> costs = co.pl.sga("Costs", 30) >>> r = m.render() >>> r.value(co.operating_income, "2027-01") 70
- vat_settlement(settle, name='VAT settlement')#
Pay the net value-added tax of each period to the tax authority on a schedule.
Lines declared with
vat=collect or pay tax and hold it in one shared VAT account. This call pays that account out in cash: each period’s net VAT (collected minus paid) is paid according tosettle. Lines declared after this call are included.- Parameters:
- settleKernel
When the net VAT of a period is paid, as the share paid in each period from that period on:
b.delay(1)pays it in the next period andb.even(2)pays half in the period itself and half in the next. The weights must sum to 1, and ab.curvemust end in 0.- namestr, default=”VAT settlement”
Name of the payment series and of the posting.
- Returns:
- Series
The cash paid to the tax authority in each period, in the entity’s currency per period, named
name. It is negative in a period when more VAT was paid than collected earlier, which is a refund.
- Raises:
- ValueError
At construction, if
settleis not a distribution: weights that are not finite, weights that do not sum to 1, or ab.curvethat does not end in 0.
See also
boki.LineMakervat=on a line books the tax that this call pays.
Notes
boki uses tax-exclusive accounting: a line stays net of tax, and
vat=books the tax beside it in the sharedVAT payable (net)account, with the cash timing of the line. Tax collected on a revenue line isDr cash (or receivable), Cr VAT payable, and tax paid on an expense line isDr VAT payable, Cr cash (or payable). This call postsDr VAT payable, Cr cashfor the payment, an operating cash flow. The VAT account is a liability that is negative while a refund is due. See net-of-tax accounting.Examples
Sales of 1,000 and purchases of 400 each month, both with 10% VAT. The net VAT of 60 a month is paid one month later, so the first payment is in the second month:
>>> import boki as b >>> from boki.units import JPY >>> months = ["2027-01", "2027-02", "2027-03"] >>> m = b.Model("VAT", start="2027-01", periods=3, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> co.bs.opening(cash=1000) >>> sales = co.pl.revenue("Sales", 1000, vat=0.1) >>> purchases = co.pl.cogs("Purchases", 400, vat=0.1) >>> payment = co.vat_settlement(settle=b.delay(1)) >>> r = m.render() >>> [round(r.value(payment, month)) for month in months] [0, 60, 60] >>> [round(r.value(co.bs.cash, month)) for month in months] [1660, 2260, 2860]
- class boki.ledger.EntityChecks#
The checks an entity brings with it, configured through
co.checks.Every entity has one built-in check: cash must not be negative in any period.
co.checks.cash(level=...)sets how it is enforced. The check runs when the model renders, together with the checks you declare withModel.check. Later built-in checks will join this object and are configured the same way.See also
boki.ledger.EntityChecks.cashSet the level of the cash check.
Notes
A failed check at level
"error"makesm.render()raiseCheckFailed, whoseresultattribute holds the complete Result. A failed check at level"warn"issues a warning and lets the render finish. A check at level"off"is not run.Examples
An entity that pays rent from zero cash fails the default check:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Funding", start="2027-01", periods=2, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> rent = co.pl.sga("Rent", 100) >>> try: ... m.render() ... except b.CheckFailed: ... print("cash is negative") cash is negative >>> co.checks.cash(level="off") >>> r = m.render()
- cash(level='error')#
Set how the check that cash does not go below zero is enforced.
Every entity has this check at level
"error", because a plan that spends money it does not have is not a plan. Declare"warn"when the plan is meant to show a funding gap (a source model with negative cash, or a gap the plan will finance later) and"off"to drop the check.- Parameters:
- levelstr, default=”error”
"error"makesm.render()raiseCheckFailedwhen cash is below zero in any period,"warn"warns instead, and"off"does not run the check.
- Raises:
- ValueError
At construction, if
levelis not"error","warn"or"off".
Notes
The check compares the closing cash balance of every period with zero, with a tolerance of 1e-9. It is reported in
Result.checksas"<entity name>: cash is not negative".m.render(checks="warn")turns every"error"check into a warning for that render without changing the level set here.Examples
Turn the check off for a plan that is meant to show a funding gap; an invalid level is an error:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Funding", start="2027-01", periods=2, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> rent = co.pl.sga("Rent", 100) >>> co.checks.cash(level="off") >>> r = m.render() >>> r.checks [] >>> co.checks.cash("loud") Traceback (most recent call last): ... ValueError: check level must be one of 'error', 'warn', 'off', not 'loud'
Statements#
- class boki.ledger.PL(entity)#
The income statement of an entity: one line maker per PL kind and the layout’s subtotals as series.
co.plis built from the entity’s layout. Each PL kind of the layout is an attribute named after the kind, a LineMaker (co.pl.revenue,co.pl.sga): calling it books a line, and itstotaladds up the lines of the kind. The layout’s subtotals (its stages) are Series attributes such asco.pl.gross_profit, in the entity’s currency per period. Expenses are positive amounts, and a subtotal subtracts them. The kinds and subtotals that exist depend on the layout, and reading one the layout does not have raisesAttributeError.- Parameters:
- entityEntity
The entity the statement belongs to. Created by the entity; user code does not construct it.
- Attributes:
- gross_profitSeries
Revenue less cost of sales. Present in the IFRS, US GAAP and J-GAAP general layouts.
- operating_incomeSeries
The operating subtotal. Present in the IFRS, US GAAP and J-GAAP general layouts, and absent in the bank layout. Shown as “Operating profit” under IFRS.
- ordinary_incomeSeries
Operating income plus non-operating income less non-operating expenses. J-GAAP only.
- net_interest_incomeSeries
Interest income less interest expense. Bank layout only.
- pretax_incomeSeries
Profit before income tax. Present in every built-in layout.
- net_incomeSeries
Profit after income tax, the entity’s net income. Every layout needs it.
See also
boki.LineMakerThe callable behind each PL kind.
boki.ledger.BSThe balance sheet.
Notes
Reading a name that is not a PL kind or subtotal of the layout, such as
co.pl.special_losson an IFRS entity, raisesAttributeErrorwhose message lists the kinds available.The subtotals of each built-in layout, with expenses as positive amounts:
IFRS:
gross_profit= revenue - cogs;operating_income= gross_profit - sga + other_income - other_expense;pretax_income= operating_income + finance_income - finance_cost;net_income= pretax_income - income_tax.US GAAP:
gross_profit= revenue - cogs;operating_income= gross_profit - sga;pretax_income= operating_income + other_income - other_expense - interest_expense;net_income= pretax_income - income_tax.J-GAAP:
gross_profit= revenue - cogs;operating_income= gross_profit - sga;ordinary_income= operating_income + non_operating_income - non_operating_expense;pretax_income= ordinary_income + special_gain - special_loss;net_income= pretax_income - income_tax.Bank layout:
net_interest_income= interest_income - interest_expense;pretax_income= net_interest_income - provision + non_interest_income - non_interest_expense;net_income= pretax_income - income_tax.
Where the layouts differ, the standard also differs in what it calls the subtotal:
co.label("operating_income")returns the name a statement shows. Custom layouts define their own subtotals; see boki.layouts.Examples
Revenue less cost of sales and operating costs in a monthly model:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Income", start="2027-01", periods=2, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> sales = co.pl.revenue("Sales", 100) >>> materials = co.pl.cogs("Materials", 30) >>> rent = co.pl.sga("Rent", 20) >>> r = m.render() >>> r.value(co.pl.gross_profit, "2027-01"), r.value(co.pl.operating_income, "2027-01") (70, 50) >>> r.value(co.pl.net_income, "2027-02") 50 >>> co.pl.special_loss Traceback (most recent call last): ... AttributeError: IFRS has no PL kind 'special_loss'; available: revenue, cogs, sga, other_income, other_expense, finance_income, finance_cost, income_tax
- class boki.ledger.BS(entity)#
The balance sheet of an entity: cash, one line maker per balance-sheet kind, the totals, and generic lines.
co.bsis built from the entity’s layout. Each balance-sheet kind of the layout is an attribute named after the kind, a LineMaker (co.bs.loan,co.bs.fixed_asset,co.bs.receivable): calling it books a line, and itstotaladds up the lines of the kind.assetandliabilitybook generic lines that are outside the layout. Balances are in the entity’s currency, positive on the account’s normal side. Reading a kind the layout does not have raisesAttributeError.- Parameters:
- entityEntity
The entity the balance sheet belongs to. Created by the entity; user code does not construct it.
- Attributes:
- cashSeries
The cash balance at the end of each period. Its
openingis the balance at the start of the period, and itschangethe movement.- retained_earningsSeries
Closing retained earnings in each period, including cumulative forecast profit to date.
- equityEquity
The equity namespace.
equity.totalis the same series astotal_equity.- total_assetsSeries
Every asset balance at the end of each period, cash included.
- total_liabilitiesSeries
Every liability balance at the end of each period.
- total_equitySeries
Capital, retained earnings, and other equity accounts, including the profit to date of the model. Total assets equal total liabilities plus total equity in every period; the render checks this.
See also
boki.ledger.PLThe income statement.
boki.ledger.CFThe cash-flow statement.
boki.LineMakerThe callable behind each balance-sheet kind.
Notes
Reading a name that is not a balance-sheet kind of the layout raises
AttributeErrorwhose message lists the kinds available and points toassetandliability.A line item’s value is its closing balance in each period, and its
openingis the previous period’s closing balance (the declared opening balance in the first period). Two kinds are the exception because they are flows: adividendline is the dividend declared in the period, and anociline is the period’s OCI after tax (itsbalanceis the accumulated reserve), soco.bs.oci.totalis the period’s OCI rather than a balance. The equity total adds the profit to date to the equity accounts: profit is not posted to the retained earnings account, and the statements add the cumulative profit to it.The kinds of the general layouts are listed in the balance-sheet rows, and
working_capitalis a line you declare, like the other kinds: it is not a total computed from the statements.Examples
A balance sheet with an opening cash balance and a loan drawn in the first month:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Balance", start="2027-01", periods=2, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> co.bs.opening(cash=100) >>> loan = co.bs.loan("Loan", draw={0: 400 * JPY}) >>> r = m.render() >>> round(r.value(co.bs.total_assets, "2027-01")), round(r.value(co.bs.total_liabilities, "2027-01")) (500, 400) >>> round(r.value(co.bs.total_equity, "2027-01")) 100 >>> co.bs.special Traceback (most recent call last): ... AttributeError: the IFRS general layout has no balance-sheet kind 'special'; available: receivable, inventory, prepaid, working_capital, other_current_asset, fixed_asset, intangible, construction, deposit, other_asset, deferred_tax_asset, payable, accrued, deferred_revenue, other_current_liability, lease_liability, other_liability, deferred_tax_liability, loan, capital, nci, dividend, oci, or use bs.asset / bs.liability
- asset(name, amount=None, at=None, *, target=None, opening=None, section='current', cf=None, tags=(), kind='asset', counterparty=None, actuals=None)#
Add a generic balance-sheet asset that is not one of the layout’s kinds.
Use it for an asset the layout has no kind for. Give
amountto change the balance each period against cash, ortargetto hold the balance at a level and let cash absorb the change. Without either, the line only has its opening balance.- Parameters:
- namestr
Line name; required. It must be unique among the entity’s accounts of the same
kind.- amountscalar, Quantity, Series, or dict, optional
Change of the balance in each period, paid in cash: a positive amount increases the asset and reduces cash. In the entity’s currency per period. A plain number is in the entity’s currency. A quantity per time is integrated by period length. A dict maps period labels, indices, or dates to amounts and uses 0 in the other periods. Give
amountortarget, not both.- atint, str, or date, optional
With
amount, books the amount in this period only, and 0 in every other period. The default isNone, which means the amount applies to every period.- targetscalar, Quantity, or Series, optional
The closing balance to hold in each period, in the entity’s currency. Cash absorbs the difference from the balance before. Give
amountortarget, not both.- openingscalar or Quantity, optional
Balance at the start of the first period, in the entity’s currency. The default is
None, meaning 0.- sectionstr, default=”current”
"current"or"noncurrent". It only sets the default cash-flow section:"current"gives"operating"and anything else"investing".- cfstr, optional
Cash-flow section of the cash that moves:
"operating","investing","financing", or"fx". The default isNone, which uses the section fromsection.- tagsiterable of str, default=()
Labels stored on the account and copied into consolidated books. boki reads a few internal tags; others have no effect on values.
- kindstr, default=”asset”
The account kind recorded as
LineItem.kind. The Excel balance sheet places the line in the current or non-current group by the layout kind of this name, if the layout has one.- counterpartyEntity, optional
The other entity of the same model that holds the matching liability. It needs
openingand does not takeamount,at, ortarget: only an opening intercompany balance is booked, and the other entity gets a mirrored line.- actualsdict, optional
Historical closing balances for periods up to
actual_until, as{period: amount}. RequiresModel(..., actual_until=...).
- Returns:
- LineItem
The new line, whose value in each period is its closing balance.
line.balanceis the same series.
- Raises:
- TypeError
At construction, if both
amountandtargetare given, or ifcounterpartyis not an entity, is given withoutopening, or is combined withamount,targetorat.- ValueError
At construction, if a line of this kind with this name already exists, if
cfis not a valid section, or ifcounterpartyis this entity or belongs to another model.- UnitError
At construction, if an amount is in a unit other than the entity’s currency.
See also
boki.ledger.BS.liabilityThe generic liability.
boki.ledger.BS.openingOpening cash and retained earnings.
Notes
amountbooksDr asset, Cr cash, andtargetbooks the cash entry that makes the closing balance equal the target. The cash flow is classified bycf. Layout kinds such asco.bs.other_assettake the same arguments and have a default section of their own; useassetfor something the layout does not offer.Examples
A deposit that grows by 20 a month and a stock held at 50, paid from cash:
>>> import boki as b >>> from boki.units import JPY >>> months = ["2027-01", "2027-02", "2027-03"] >>> m = b.Model("Assets", start="2027-01", periods=3, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> co.bs.opening(cash=1000) >>> deposit = co.bs.asset("Deposit", 20, opening=100) >>> stock = co.bs.asset("Stock", target=50, opening=10) >>> r = m.render() >>> [round(r.value(deposit, month)) for month in months] [120, 140, 160] >>> [round(r.value(stock, month)) for month in months] [50, 50, 50] >>> [round(r.value(co.bs.cash, month)) for month in months] [940, 920, 900]
- deferred_tax(name, difference, rate=None, recognized=1.0)#
Book deferred tax from the temporary difference at the end of each period.
A positive difference creates a deferred tax liability and a negative one a deferred tax asset. The balances follow the difference, and each period’s change is charged to income tax without moving cash.
- Parameters:
- namestr
Name of the deferred tax item; required. It must be unique among the entity’s deferred tax items.
- differencescalar, Quantity, Series, or dict
The temporary difference between book and tax amounts at the end of each period, a balance in the entity’s currency (not a change). Positive is taxable and negative is deductible. A plain number is in the entity’s currency. A dict maps period labels, indices, or dates to differences and uses 0 in the other periods.
- ratescalar or Series, optional
Tax rate on the difference, a dimensionless ratio such as
0.3for 30%. The default isNone, which uses the entity’stax_rate.- recognizedscalar or Series, default=1.0
Share of a deductible difference that is recognized as an asset, a dimensionless ratio from 0 to 1. It does not apply to taxable differences. boki does not assess recoverability, so this is your judgement.
- Raises:
- ValueError
At construction, if a deferred tax item with this name already exists, or if neither
ratenor the entity’stax_rateis given.- UnitError
At construction, if
rateorrecognizedis not dimensionless, ordifferenceis in a unit other than the entity’s currency.- TypeError
At construction, if an argument has a type boki cannot use in an expression.
See also
boki.ledger.Entity.ociTaxed OCI recognizes deferred tax through its own reserve.
Notes
The deferred tax liability is
ratetimes the positive part ofdifference, and the deferred tax asset israte * recognizedtimes the negative part. The balances are inco.bs.deferred_tax_liabilityandco.bs.deferred_tax_asset(the kinds are non-current and non-cash), and the movements are in the income tax line “Deferred tax” (“Deferred income tax” under US GAAP). An increase of the liability isDr deferred tax expense, Cr deferred tax liability, and an increase of the asset isDr deferred tax asset, Cr deferred tax expense. Cash does not change. See S1: deferred taxes.Examples
At a 30% tax rate, temporary differences of 100, 150 and 50 at the year ends give liabilities of 30, 45 and 15 and tax expenses of 30, 15 and -30:
>>> import boki as b >>> from boki.units import JPY >>> years = ["2027", "2028", "2029"] >>> m = b.Model("Deferred", start="2027-01", periods=3, step=b.year) >>> co = m.entity("A", standard=b.IFRS, currency=JPY, tax_rate=0.3) >>> co.bs.deferred_tax("Depreciation difference", {0: 100, 1: 150, 2: 50}) >>> r = m.render() >>> [round(r.value(co.bs.deferred_tax_liability.total, year)) for year in years] [30, 45, 15] >>> [round(r.value(co.pl.income_tax.total, year)) for year in years] [30, 15, -30] >>> [round(r.value(co.bs.cash, year)) for year in years] [0, 0, 0]
- liability(name, amount=None, at=None, *, target=None, opening=None, cf=None, tags=(), kind='liability', counterparty=None, actuals=None)#
Add a generic balance-sheet liability that is not one of the layout’s kinds.
It works like
asseton the other side of the balance sheet:amountchanges the balance each period and brings cash in, andtargetholds the balance at a level.- Parameters:
- namestr
Line name; required. It must be unique among the entity’s accounts of the same
kind.- amountscalar, Quantity, Series, or dict, optional
Change of the balance in each period, received in cash: a positive amount increases the liability and increases cash. In the entity’s currency per period, with the forms of the
amountofasset. Giveamountortarget, not both.- atint, str, or date, optional
With
amount, books the amount in this period only. The default isNone, which means every period.- targetscalar, Quantity, or Series, optional
The closing balance to hold in each period, in the entity’s currency. Cash absorbs the change.
- openingscalar or Quantity, optional
Balance at the start of the first period, in the entity’s currency. The default is
None, meaning 0.- cfstr, optional
Cash-flow section of the cash that moves:
"operating","investing","financing", or"fx". The default isNone, which means"operating".- tagsiterable of str, default=()
Labels stored on the account and copied into consolidated books.
- kindstr, default=”liability”
The account kind recorded as
LineItem.kind.- counterpartyEntity, optional
The other entity of the same model that holds the matching asset. It needs
openingand does not takeamount,at, ortarget.- actualsdict, optional
Historical closing balances for periods up to
actual_until, as{period: amount}. RequiresModel(..., actual_until=...).
- Returns:
- LineItem
The new line, whose value in each period is its closing balance.
line.balanceis the same series.
- Raises:
- TypeError
At construction, if both
amountandtargetare given, or ifcounterpartyis not an entity, is given withoutopening, or is combined withamount,targetorat.- ValueError
At construction, if a line of this kind with this name already exists, if
cfis not a valid section, or ifcounterpartyis this entity or belongs to another model.- UnitError
At construction, if an amount is in a unit other than the entity’s currency.
See also
boki.ledger.BS.assetThe generic asset.
Notes
amountbooksDr cash, Cr liability, andtargetbooks the cash entry that makes the closing balance equal the target. The default cash-flow section is operating.Examples
An accrual held at 5, starting from 3, and a deposit received once in the second month:
>>> import boki as b >>> from boki.units import JPY >>> months = ["2027-01", "2027-02", "2027-03"] >>> m = b.Model("Liabilities", start="2027-01", periods=3, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> co.bs.opening(cash=100) >>> accrued = co.bs.liability("Accrued", target=5, opening=3) >>> deposit = co.bs.liability("Deposit", 30, at="2027-02") >>> r = m.render() >>> [round(r.value(accrued, month)) for month in months] [5, 5, 5] >>> [round(r.value(deposit, month)) for month in months] [0, 30, 30] >>> [round(r.value(co.bs.cash, month)) for month in months] [102, 132, 132]
- opening(*, cash=None, retained_earnings=None)#
Declare the opening cash and retained earnings of the balance sheet at the model start.
The opening balance sheet is made of the opening balances declared on each account:
cashhere andopening=on lines. Retained earnings take whatever balances the sheet unless you give them.- Parameters:
- cashscalar or Quantity, optional
Cash at the start of the first period, in the entity’s currency. The default is
None, which leaves the opening cash unchanged (0 when never given).- retained_earningsscalar or Quantity, optional
Retained earnings at the start of the first period, in the entity’s currency. The default is
None, which leaves the opening retained earnings as the amount that balances the sheet: assets less liabilities and the other equity accounts. If you give it, the opening balance sheet must balance on its own.
- Raises:
- UnitError
At construction, if an amount is in a unit other than the entity’s currency.
See also
boki.LineMakeropening=on a line declares that line’s own opening balance.boki.ledger.Entity.journalPost changes between accounts instead of declaring opening balances.
Notes
bs.openingdeclares the opening balance of the cash account and of retained earnings. The opening balance of any other account is declared withopening=on its line, such asco.bs.receivable("Receivable", opening=200). Retained earnings are the balancing figure unless given. Whenretained_earningsis given and the opening balance sheet does not balance,m.render()raises LedgerError and names the difference. Each call replaces only the amounts it names. See the opening balance sheet.Examples
Retained earnings balance the sheet unless you give them:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Opening", start="2027-01", periods=2, step=b.year) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> co.bs.opening(cash=1000) >>> receivable = co.bs.receivable("Receivable", opening=200) >>> r = m.render() >>> round(r.value(co.bs.total_equity, "2027")) 1200 >>> co.bs.opening(cash=1000, retained_earnings=500) >>> try: ... m.render() ... except b.LedgerError: ... print("opening balance sheet does not balance") opening balance sheet does not balance
- sell(asset_line, price, *, at, counterparty, life)#
Sell an existing fixed asset to another entity of the model.
The seller stops depreciating the asset from the period of sale, derecognizes its carrying amount at the start of that period, and books the difference from the price as a gain or loss. The buyer books the asset at the price and depreciates it straight-line over
life.- Parameters:
- asset_lineLineItem
A depreciating fixed-asset line of this entity, made by
co.bs.fixed_asset. Required.- priceQuantity
The sale price, in the entity’s currency, such as
150 * JPY. A plain number is dimensionless and raises UnitError when the books have a currency.- atint, str, or date
The period of the sale, as an index, a period label, or a date. The price is received in that period.
- counterpartyLineMaker
The buyer’s
bs.fixed_asset,other.bs.fixed_asset, whereotheris another entity of the same model.- lifeQuantity or Unit
The buyer’s useful life as a time, such as
5 * b.year. It must be positive.
- Returns:
- LineItem
asset_line, whosecounterpartyattribute is now the buyer’s asset line, named<asset name> (<seller name>).
- Raises:
- TypeError
At construction, if
asset_lineis not a fixed-asset line of this entity with depreciation, orcounterpartyis not abs.fixed_assetmaker.- ValueError
At construction, if the counterparty is this entity or belongs to another model, if
lifeis not positive, or if the layout of the seller has no gain or loss kind for fixed-asset disposals, or the buyer’s layout has nofixed_assetkind.- IndexError
At construction, if
atis outside the model timeline.- UnitError
At construction, if
priceorlifehas the wrong unit.
See also
boki.LineMakercounterparty=on a revenue line sells new goods or equipment instead.
Notes
The seller books
Dr cash, Cr assetfor the price andDr asset, Cr gain(orDr loss, Cr asset) for the difference between the price and the carrying amount. The gain or loss is “Gain on sale of fixed assets” inspecial_gainunder J-GAAP, and “Gain on disposal of fixed assets” inother_income(orother_expensefor a loss) under IFRS and US GAAP. The buyer booksDr asset, Cr cash. Consolidation removes the entries of the sale and the unrealized gain; see S6: intercompany asset sales.Examples
A machine with a carrying amount of 90 at the start of the second month is sold for 150, a gain of 60. The buyer depreciates it over five years, 2.5 a month:
>>> import boki as b >>> from boki.units import JPY >>> months = ["2027-01", "2027-02", "2027-03"] >>> m = b.Model("Sale", start="2027-01", periods=3, step=b.month) >>> seller = m.entity("Seller", standard=b.IFRS, currency=JPY) >>> buyer = m.entity("Buyer", standard=b.IFRS, currency=JPY) >>> buyer.bs.opening(cash=500 * JPY) >>> machine = seller.bs.fixed_asset("Machine", opening=100 * JPY, depreciation=10 * JPY) >>> sold = seller.bs.sell(machine, 150 * JPY, at="2027-02", counterparty=buyer.bs.fixed_asset, life=5 * b.year) >>> r = m.render() >>> [round(r.value(seller.pl.other_income.total, month)) for month in months] [0, 60, 0] >>> [round(r.value(machine.counterparty.balance, month), 1) for month in months] [0.0, 147.5, 145.0]
- class boki.ledger._Equity(entity)#
The equity namespace of a balance sheet,
co.bs.equity, which holds the equity total.- Parameters:
- entityEntity
The entity whose equity it totals. Created by the balance sheet; user code does not construct it.
- Attributes:
- totalSeries
Equity at the end of each period, in the entity’s currency: capital, retained earnings, other equity accounts, and the profit to date. It is the same value as
co.bs.total_equity.
See also
boki.ledger.BSThe balance sheet, whose
total_equityis the same total.
Examples
Equity grows by the profit of each period:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Equity", start="2027-01", periods=2, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> co.bs.opening(cash=1000) >>> sales = co.pl.revenue("Sales", 100) >>> r = m.render() >>> [round(r.value(co.bs.equity.total, month)) for month in ("2027-01", "2027-02")] [1100, 1200]
- class boki.ledger.CF(entity)#
The cash-flow statement of an entity as series, one for each section (direct method, from the ledger).
Each section adds up the cash postings of the entity’s ledger that the entity classified into it. The four sections together equal the change in cash in every period, which the render checks, along with the indirect method.
- Parameters:
- entityEntity
The entity the statement belongs to. Created by the entity; user code does not construct it.
- Attributes:
- operatingSeries
Cash received or paid for operations, in the entity’s currency per period.
- investingSeries
Cash received or paid for investments, such as fixed assets and subsidiary shares, in the entity’s currency per period.
- financingSeries
Cash received or paid for borrowing, equity, and dividends, in the entity’s currency per period.
- fxSeries
The effect of exchange rates on cash, in the entity’s currency per period. It is 0 unless a journal entry is booked with
cf="fx".
See also
boki.ledger.CF.financing_excludingFinancing cash flow without some lines.
Notes
A posting that moves cash is classified by its
cfif one was given (Entity.journal(..., cf=...)or a line’scf=). Otherwise it takes the class of the account on the other side: operating for profit-and-loss accounts and operating balance-sheet accounts, and the account’s own class for the others (fixed assets investing, loans and capital financing). Receipts are positive and payments negative. See the cash-flow rows.Examples
A loan drawn in the first month and a machine bought in the same month, with sales of 50 a month:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Cash flow", start="2027-01", periods=2, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> co.bs.opening(cash=100) >>> sales = co.pl.revenue("Sales", 50) >>> loan = co.bs.loan("Loan", draw={0: 500 * JPY}) >>> machine = co.bs.fixed_asset("Machine", cost=200, at=0, life=4 * b.year) >>> r = m.render() >>> [round(r.value(co.cf.operating, month)) for month in ("2027-01", "2027-02")] [50, 50] >>> round(r.value(co.cf.investing, "2027-01")), round(r.value(co.cf.financing, "2027-01")) (-200, 500) >>> round(r.value(co.bs.cash, "2027-01")) 450
- financing_excluding(*items)#
Return the financing cash flow without the cash postings of some lines.
Use it to size a line from the rest of financing, such as a revolver that borrows the shortfall.
- Parameters:
- *itemsLineItem, balance, or Account
The lines to leave out: line items, balances, or accounts of this entity’s books, such as a revolver. Without any, the result equals
cf.financing.
- Returns:
- Series
Financing cash flow in each period, in the entity’s currency per period, without the postings between cash and the given accounts.
- Raises:
- TypeError
At construction, if an item is not an account, a balance, or a line item.
See also
boki.ledger.CFThe sections of the cash-flow statement.
Examples
Financing before the loan, in a model where the loan is drawn once and capital is paid in the second month:
>>> import boki as b >>> from boki.units import JPY >>> months = ["2027-01", "2027-02", "2027-03"] >>> m = b.Model("Financing", start="2027-01", periods=3, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> loan = co.bs.loan("Loan", draw={0: 500 * JPY}, repay={2: 100 * JPY}) >>> shares = co.bs.capital("Shares", 20, at=1) >>> co.checks.cash(level="off") >>> r = m.render() >>> [round(r.value(co.cf.financing, month)) for month in months] [500, 20, -100] >>> [round(r.value(co.cf.financing_excluding(loan), month)) for month in months] [0, 20, 0]
Calendars#
- boki.fiscal(year_end, change=None)#
Make a fiscal calendar for an entity.
- Parameters:
- year_endstr
The day each fiscal year ends, as
"MM-DD", such as"03-31"or"12-31". Required. A day beyond the end of the month is moved to the last day of that month.- changedict, optional
Changes of year end as
{date: "MM-DD"}. A key is the last day of a fiscal year, as a date or a"YYYY-MM-DD"string, and the value is the year-end rule for the years after it. The default isNone, which means no change.
- Returns:
- Fiscal
The fiscal calendar, to pass as
fiscal=toModel.entity.
- Raises:
- ValueError
At construction, if a key of
changeis not a date or a date string.
See also
boki.calendarBusiness-day counts, which are a different calendar.
Examples
Group a monthly model into March fiscal years:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Fiscal", start="2027-01", periods=18, step=b.month) >>> co = m.entity("A", standard=b.IFRS, currency=JPY, fiscal=b.fiscal("03-31")) >>> sales = co.pl.revenue("Sales", 10) >>> r = m.render() >>> table = r.pl(co, by="fiscal_year") >>> table.columns ['FY2027-03', 'FY2028-03', 'FY2029-03']
- class boki.statements.Fiscal(year_end, change=None)#
A fiscal calendar: the day each fiscal year ends, with optional changes of year end.
Statements grouped
by="fiscal_year"and the Excel statement columns use it to sum monthly or quarterly model periods into fiscal years. The model’s periods do not change: a fiscal calendar is a reporting view of them. Make one withb.fiscal(...)and pass it asfiscal=toModel.entity.- Parameters:
- year_endstr
The day each fiscal year ends, as
"MM-DD":"03-31"for a year ending on March 31 and"12-31"for a calendar year. A day beyond the end of the month is moved to the last day of the month, so"02-30"ends on February 28 (or 29). Required. It is not checked when the calendar is made; a malformed value raises when a label is needed.- changedict | None
Changes of year end as
{date: "MM-DD"}. A key is the last day of a fiscal year, as a date or a"YYYY-MM-DD"string, and the value is the year-end rule that applies to the years after it. The default isNone, which means no change. The year that ends on a key is shorter or longer than twelve months when the old and new year ends differ.
- Attributes:
- year_endstr
The year-end rule as given.
- changedict
The changes of year end, keyed by datetime.date.
See also
boki.fiscalMake a fiscal calendar.
boki.statements.Fiscal.labelThe label of the fiscal year a period belongs to.
Notes
b.fiscalraisesValueErrorif a key ofchangeis not a date or a date string. A year-end rule that is not a valid"MM-DD"is not checked there: it raisesValueErrorwhen a label is needed, at evaluation.Examples
A March year end, and a December year end that moves to March after the year ending 2029-03-31 (a three-month transition year):
>>> import boki as b >>> from datetime import date >>> fy = b.fiscal("03-31") >>> fy.label(date(2027, 4, 1)) 'FY2028-03' >>> moved = b.fiscal("12-31", change={"2029-03-31": "03-31"}) >>> [moved.label(date(*start)) for start in ((2028, 6, 1), (2029, 1, 1), (2029, 4, 1))] ['FY2028-12', 'FY2029-03', 'FY2030-03']
- label(period_start)#
Return the label of the fiscal year that contains a date.
- Parameters:
- period_startdatetime.date
The first day of a model period, or any date. It must be a
date, not a string.
- Returns:
- str
"FY<year>-<month>"for the fiscal year whose last day is on or after the date, such as"FY2028-03"for the year ending 2028-03-31.
- Raises:
- ValueError
At evaluation, if the year-end rule is not a valid
"MM-DD".
See also
boki.fiscalMake a fiscal calendar.
Examples
The last day of a fiscal year belongs to that year, and the next day to the following one:
>>> import boki as b >>> from datetime import date >>> fy = b.fiscal("03-31") >>> fy.label(date(2028, 3, 31)), fy.label(date(2028, 4, 1)) ('FY2028-03', 'FY2029-03')
- boki.calendar(model, holidays=None, closed=())#
Make a business-day calendar for a model.
- Parameters:
- modelModel
The model whose periods are counted. Required; it needs a dated timeline.
- holidaysiterable of date or str, optional
Dates that never count, as dates or
"YYYY-MM-DD"strings. The default isNone, which means no holidays."jp"is not available.- closediterable of str, default=()
Weekdays that never count, as
"Mon"to"Sun".
- Returns:
- Calendar
The calendar. Call
dayson it to get a series.
- Raises:
- NotImplementedError
At construction, if
holidaysis"jp": built-in Japanese holidays are not bundled.- KeyError
At construction, if
closedhas an entry that is not a weekday abbreviation.- ValueError
At construction, if a holiday is not a date or a date string.
See also
boki.fiscalFiscal years, which are a different calendar.
Examples
Count the days open in each month when the business is closed on Sundays:
>>> import boki as b >>> m = b.Model("Open days", start="2027-07", periods=2, step=b.month) >>> cal = b.calendar(m, closed=["Sun"]) >>> days_open = cal.days("Mon-Sat") >>> r = m.render() >>> r.value(days_open, "2027-07"), r.value(days_open, "2027-08") (27, 26)
- class boki.statements.Calendar(model, holidays=None, closed=())#
A business-day calendar that counts the days of each model period.
b.calendar(m, ...)makes one for a model.daysthen counts, in every period, the days that match a weekday pattern and are neither a closed weekday nor a holiday. Use the counts to scale amounts that depend on trading days.- Parameters:
- modelModel
The model whose periods are counted. It needs a dated timeline.
- holidaysIterable[date | str] | None
Dates that never count, as dates or
"YYYY-MM-DD"strings. The default isNone, which means no holidays."jp"is not available and raises NotImplementedError.- closedIterable[str]
Weekdays that never count, from
"Mon","Tue","Wed","Thu","Fri","Sat"and"Sun". The default is an empty tuple. An entry that is not a weekday abbreviation raisesKeyErrorthroughb.calendar.
- Attributes:
- holidaysset[date]
The holidays.
- closedset[int]
The closed weekdays as numbers, Monday is 0 and Sunday is 6.
- Raises:
- NotImplementedError
At construction through
b.calendar, ifholidaysis"jp".
See also
boki.calendarMake a calendar.
boki.statements.Calendar.daysCount the matching days of each period.
Examples
July 2027 has 27 days that are not Sundays, and 26 after one holiday:
>>> import boki as b >>> m = b.Model("Days", start="2027-07", periods=1, step=b.month) >>> cal = b.calendar(m, holidays=["2027-07-19"], closed=["Sun"]) >>> r = m.render() >>> r.value(cal.days("Mon-Sat"), "2027-07") 26
- days(spec)#
Count the days of each period that match a weekday pattern.
A day counts when its weekday is in
spec, it is not a closed weekday of the calendar, and it is not a holiday.- Parameters:
- specstr
Weekdays as names joined by commas, where a name can be a range:
"Mon-Sat","Fri-Sat","Mon,Wed". A range whose end is before its start wraps around the week, so"Sat-Mon"is Saturday, Sunday and Monday. Names areMontoSun. Required.
- Returns:
- Series
The number of matching days in each period, a quantity in days (
b.day).
- Raises:
- KeyError
At construction, if a weekday name in
specis notMontoSun.
See also
boki.calendarMake a calendar.
Examples
Days open Monday to Friday and on Saturday and Sunday in July 2027:
>>> import boki as b >>> m = b.Model("Days", start="2027-07", periods=2, step=b.month) >>> cal = b.calendar(m, holidays=["2027-07-19"], closed=["Sun"]) >>> r = m.render() >>> r.value(cal.days("Mon-Fri"), "2027-07"), r.value(cal.days("Sat-Mon"), "2027-07") (21, 8) >>> r.value(cal.days("Mon,Wed"), "2027-08") 9
Errors#
- exception boki.LedgerError#
Error raised when an entity’s books fail a consistency check.
m.render()verifies every entity and group before it evaluates your own checks. It raises LedgerError when an opening balance sheet does not balance, when assets differ from liabilities plus equity in any period, when cash-flow sections do not add up to the change in cash, or when the indirect cash flow differs from the direct one. A group’s consolidated books are checked too, including the profit attributed to owners and to non-controlling interests. The message names the entity, the check, and the period.See also
boki.ledger.EntityChecksChecks about your plan, such as cash not being negative.
Notes
A difference larger than a relative tolerance of 1e-6 fails. Postings made through boki’s own lines always balance, so a ledger error usually means a bug in boki, or an amount computed outside the ledger. You can also cause it by declaring an opening balance sheet that does not balance: giving both
cashandretained_earningstoco.bs.opening(or an opening balance on a line) without matching amounts.LedgerErroris an AssertionError, so it is not caught by handlers forValueError, and it differs from the check failures thatModel.renderraises asCheckFailedfor conditions of your plan.Examples
An opening balance sheet that declares cash of 1,000 and retained earnings of 500 does not balance:
>>> import boki as b >>> from boki.units import JPY >>> m = b.Model("Unbalanced", start="2027-01", periods=1, step=b.year) >>> co = m.entity("A", standard=b.IFRS, currency=JPY) >>> co.bs.opening(cash=1000, retained_earnings=500) >>> try: ... m.render() ... except b.LedgerError as error: ... print(error) A: the opening balance sheet does not balance: assets 1,000 != liabilities 0 + equity 500; difference 500