250 likes | 265 Views
Dive deep into Formula Linkbase design decisions, basic concepts, and best practices for constructing XBRL instances. Understand the importance of extensibility, linkbases, and fitting into existing tool sets. Learn about formula design, variable usage, value expression, result creation, and more.
E N D
Formula Linkbase Tutorial(afternoon) David vun Kannon Phillip Engel KPMG LLP
Remember! • XBRL OTSOG W3C • Therefore: • XBRL FL OTSOG XPath • and • WWSD? • (What Would SQL do?)
Basic Design Decisions • How important is extensibility? • Do you need a linkbase or just appinfo? • How important is it to fit into existing tool sets and thinking? • Is FL • A resource linkbase? • Item – formula • A relationship linkbase? • Item – inputs (+ formula)
Linkbase • Separates definition of formula from output item • Allows prohibition and override • Uses linkbase ideas popularized by XBRL 2.1 • But • Can’t use the linkbase element!
Top Level Design <fl:rulebase> <fl:formulaLink/> </fl:rulebase> Except for substituting rulebase for linkbase, this is a standard XBRL linkbase, with extended link roles for DTS use. (Don’t want to break the DTS model!)
formulaLink Design Inputs are buried in the formula <fl:formulaLink> <fl:formula/> <xl:loc/> <fl:formulaArc/> </fl:formulaLink> This is very similar to other (label, reference) “resource style” linkbases. Result element
formulaArc Design • Only one arc role defined so far • Item-formula
Formula Design <fl:formula xlink:type=“resource” xlink:label=“formula1” id = “myFormula1” > <fl:variable/> <fl:value/> <fl:result/> </fl:formula>
Variable Design <fl:variable name = “var1” select = “ci:Assets” filter = “ …XPath expression… ” /> What are you allowed to select? items, contexts, non-XBRL attributes? The idea of “free” variables.
Value Design <fl:value test = “ …Xpath expression…” select = “ …XPath expression…” /> Can use multiple value elements OR XPath 2.0 case construct in XPath expression.
Result Design <fl:result> <fl:resultPrecision/> <fl:resultUnit/> <fl:resultContext> <fl:resultEntity/> <fl:resultPeriod/> <fl:resultScenario/> </fl:resultContext> </fl:result>
FL OTSOG XPath! • Bind variables • Filter variables • Result choices • Compute results • Express API into XBRL instance documents
An XPath-based API • Standard predicates (functions) of XBRL 2.1 • C-equal • P-equal • S-equal • U-equal • Duplicate-item • Specific to the needs of Formula Linkbase • Decimal to precision conversion
Basic processing model Formula Linkbase XBRL Instance in Process Formulas Non-deterministic order XBRL Instance out Individual formula Bind variables Input Value expression Process Create result Output XBRL Instance New XBRL Instance Formula Processor DTS andFormula Linkbase
Formula linkbase example – Average Shares <formulaLink xlink:type="extended" xlink:role="http://www.xbrl.org/2003/role/link"> <link:loc xlink:type="locator" xlink:label="item" xlink:href="testFLconcepts.xsd#Assets"/> <formulaArc xlink:type="arc" xlink:from="item" xlink:to="formula" xlink:arcrole="http://www.xbrl.org/2004/arcrole/item-formula"/> <formula xlink:type="resource" xlink:label="formula" id="formula_2.3_AvgShares"> <variable select="co:CurrentAssets" name="CurrentAssets"/> <variable select="co:FixedAssets" name="FixedAssets" filter="flf:context-eq($this.context, $CurrentAssets.context) and flf:unit-eq($this.unit, $CurrentAssets.unit)"/> <value select="CurrentAssets.value + $FixedAssets.value"/> <result> <resultContext select="$CurrentAssets.context"/> <resultUnit select="$CurrentAssets.unit"/> </result> </formula> </formulaLink> Variables Value expression Formula Result creation
Binding variables • Set up the inputs to the formula • Bind to information at the XBRL abstraction level • Facts (items and tuples) • Contexts and Units • Bind to other XML data? • Filtering • Absolute and relative filters • Relate to other variable bindings • XBRL equalities • Free variables
Binding Variables <variable select="selction XPath expression" filter="filtering XPath expression" OR filterRef="filter id"/> • Binding in two steps 1. Select – XPath expression, context node is <XBRL> 2. Filter – Boolean XPath expression tested on each occurrence of the “select”. <variable select="co:CurrentAssets" name="CurrentAssets"/> <variable select="co:FixedAssets" name="FixedAssets" filterRef="rf2.1"/> <filter id="rf2.1" test="$this.context is $CurrentAssets.context and flf:unit-eq($this.unit, $CurrentAssets.unit) and flf:parent-eq($fact, $CurrentAssets)"/>
Binding Variables <variable select="selction XPath expression" filter="filtering XPath expression" OR filterRef="filter id"/> • Binding in two steps 1. Select – XPath expression, context node is <XBRL> 2. Filter – Boolean XPath expression tested on each occurrence of the “select”. <variable select="co:CurrentAssets" name="CurrentAssets" filter="$this.instant=‘2003-12-31’"/> <variable select="co:FixedAssets" name="FixedAssets" filterRef="rf2.1"/> <filter id="rf2.1" test="$this.context is $CurrentAssets.context and flf:unit-eq($this.unit, $CurrentAssets.unit) and flf:parent-eq($fact, $CurrentAssets)"/>
Binding variables - Filtering • Absolute filters – do not rely any other XBRL variable bindings • Relative filters – use other variables bindings to express a relationship between the variable being filtered and other variable bindings • $this variable – The current “select” being tested in the filter. • XBRL functions for filters • context-eq(), unit-eq(), parent-eq(), isFact(), isItem(), isTuple() <variable select="co:CurrentAssets" name="CurrentAssets" filter="$this.instant=‘2003-12-31’"/> <variable select="co:FixedAssets" name="FixedAssets" filterRef="rf2.1"/> <filter id="rf2.1" test="$this.context is $CurrentAssets.context and flf:unit-eq($this.unit, $CurrentAssets.unit) and flf:parent-eq($fact, $CurrentAssets)"/>
Free variables • Each XBRL variables creates a set of XPath variables based on what type of XBRL object is bound.
Value expressions • Cartesian product of bindings • Pre-testing – boolean XPath expression • Formula expression – XPath expression <value select="$CurrentAssets.value + $FixedAssets.value"/> <value test="true()" select="$Earnings.value / $Shares.value"/> <value test="$Shares" select="$Earnings.value / $Shares.value"/> <value test="$AvgShares" select="$Earnings.value / $AvgShares.value"/> <value select="fn:months-from-durations($Assets.instant - $PrevAssets.instant)"/>
Create the result • Value production • Context and unit production • Described from inputs or constants • Tuples – the problem child <result> <resultContext select="$CurrentAssets.context"/> <resultUnit select="$CurrentAssets.unit"/> </result> <result> <resultPeriod> <resultStartDate select="$Shares.instant + P1D"/> <resultEndDate select="$SharesNext.instant"/> </resultPeriod> <resultEntity select="$Shares.entity"/> <resultScenario select="$Shares.scenario"/> <resultUnit select="$Shares.unit"/> </result>
Formula linkbase example – Average Shares <formulaLink xlink:type="extended" xlink:role="http://www.xbrl.org/2003/role/link"> <link:loc xlink:type="locator" xlink:label="item" xlink:href="testFLconcepts.xsd#AvgShares"/> <formulaArc xlink:type="arc" xlink:from="item" xlink:to="formula" xlink:arcrole="http://www.xbrl.org/2004/arcrole/item-formula"/> <formula xlink:type="resource" xlink:label="formula" id="formula_2.3_AvgShares"> <variable select="co:Shares" name="SharesNext"/> <variable select="co:Shares" name="SharesPrev" filter="$this.period = $SharesNext.period - P1Y and flf:unit-eq($this.unit, $SharesNext.unit)"/> <value select="($SharesNext.value + $SharesPrev.value) / 2"/> <result> <resultPeriod> <resultStartDate select="$Shares.instant + P1D"/> <resultEndDate select="$SharesNext.instant"/> </resultPeriod> <resultEntity select="$SharesPrev.entity"/> <resultScenario select="$SharesPrev.scenario"/> <resultUnit select="$SharesPrev.unit"/> </result> </formula> </formulaLink> Result Item Result Item
Requirements balance The formula linkbase has to find a balance between: Expressing formulas as metadata vs. Processing formulas
Demo formula processor implementation • Written in XSLT – easy to create (OTSOG!!!) • Transforms a formula linkbase into an XSLT stylesheet • Each formula becomes a named template • An instance document is the input to the generated stylesheet • Output is a new valid instance document