Set context from custom XBRL file

Question:

I’m able to read a custom XBRL file. The problem is that the parsed object has the amounts of the initial period (last december) and not the last accountable period.

from xbrl import XBRLParser, GAAP, GAAPSerializer
# xbrl comes from python-xbrl package

xbrl_parser = XBRLParser()
with open('filename.xbrl') as file:
    xbrl = xbrl_parser.parse(file)    
    custom_obj = xbrl_parser.parseCustom(xbrl)
    print(custom_obj.cashandcashequivalents)

This prints the cash of 2021/12 not 2022/06 as expected

Current output: 100545101000
Expected: 81518021000

I think those number are the ones you can see in lines 9970 and 9972 of xbrl file.

These are the lines:

9970:    <ifrs-full:CashAndCashEquivalents decimals="-3" contextRef="CierreTrimestreActual" unitRef="CLP">81518021000</ifrs-full:CashAndCashEquivalents>
9972:    <ifrs-full:CashAndCashEquivalents decimals="-3" contextRef="SaldoActualInicio" unitRef="CLP">100545101000</ifrs-full:CashAndCashEquivalents>

How can I set the context/contextRef so the custom_obj has the numbers of the latest periods?

XBRL file: https://www.cmfchile.cl/institucional/inc/inf_financiera/ifrs/safec_ifrs_verarchivo.php?auth=&send=&rut=70016160&mm=06&aa=2022&archivo=70016160_202206_C.zip&desc_archivo=Estados%20financieros%20(XBRL)&tipo_archivo=XBRL

Answers:

I’ve never used python-xbrl, but from a quick look at the source code it looks very basic and makes lots of unwarranted assumptions about the structure of the document. It doesn’t appear to have any support for XBRL Dimensions, which the report you’re using makes use of.

The module isn’t built on a proper model of the XBRL data which would give you easy access to each fact’s properties such as the period, and allow you to easily filter down to just the facts that you want.

I don’t think the module will allow you to do what you want. Looking at this code it just iterates over all the facts, and sticks them onto properties on an object, so whichever fact it hits last in the document will be the one that you get, and given that order isn’t important in XBRL files, it’s just going to be pot luck which one you get.

I’d strongly recommend switching to a better XBRL library. Arelle is probably the most widely used, although you could also use my own pxp.

As an example, either tool can be used to convert the XBRL to JSON format, and will give you facts like this:

  "f126928": {
   "value": "81518021000",
   "decimals": -3,
   "dimensions": {
    "concept": "ifrs-full:CashAndCashEquivalents",
    "entity": "scheme:70016160-9",
    "period": "2022-07-01T00:00:00",
    "unit": "iso4217:CLP"
   }
  },
  
  "f126930": {
   "value": "100545101000",
   "decimals": -3,
   "dimensions": {
    "concept": "ifrs-full:CashAndCashEquivalents",
    "entity": "scheme:70016160-9",
    "period": "2022-01-01T00:00:00",
    "unit": "iso4217:CLP"
   }
  },

With this, you can then sort the facts by period, and then select the most recent one. Of course, you can do the same directly via the Python interfaces in these tools, rather than going via JSON.

Answered By: pdw
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.