quantlab.utils.symbol_axis#

The two rules for a panel’s symbol axis: its order and its dtype.

A panel is an xarray.Dataset indexed by timestamp and symbol. Its symbol axis holds either tickers (text) or numeric security identifiers such as CRSP PERMNOs (permanent integer ids that, unlike tickers, never change or get reused).

The axis is sorted numerically when every label is an integer (or a digit string) and lexicographically otherwise; sort_symbol_axis is the one place that rule is written down. Separately, labels a caller holds must be converted to the dtype the stored axis carries before they are used to index it, which normalize_to_axis_dtype does. Indexing an int64 axis with digit strings does not raise: reindex matches nothing and silently returns an all-NaN panel of the right shape. Preventing that silent failure is the purpose of this module.

Functions

normalize_to_axis_dtype

Convert labels to the dtype stored_index carries.

on_roster

Return the labels of axis that are on roster, in axis order.

sort_symbol_axis

Sort a symbol axis, numerically when every label is integral.