If I'm trying to read an SEC XBRL filing, is there a way to programatically determine what the most recent context is? Or does the naming of a context follow a particular pattern?
For example, if I am trying to read the AAPL Q2 2020 SEC Filing, there are many different contexts, ex. FI2019Q4, FD2020Q2YTD, FI2020Q2, FD2019Q2YTD, FI2019Q4, FD2020Q2QTD, etc.
I just want the most recent quarterly numbers, ie. FI2020Q2, however I also want a way to determine this programatically so that I don't have to manually decide which context I'm interested in for every SEC filing.
Is there a systematic way to do this, or does the naming of the context follow a pattern?
For SEC filings, there should be a single dei:DocumentType
fact. The period for this fact will correspond to the current reporting period. You can then find other facts that have the same period, or the same end date (for instant facts).
See section 6.5.19 of the Edgar Filer Manual Volume II
The names of contexts are simply unique identifiers to allow them to be referenced by facts. Whilst some tools may follow a convention in assigning them, you should not attempt to infer any meaning from them.
Also be aware that not all facts for the same period will be in the same context. Some facts may have additional dimensions, and will therefore use a different context.