macrosynergy.management.utils.core#
This module contains core utility functions, as well as stand-alone functions that are used across the package.
- split_ticker(ticker: str) str [source]#
- split_ticker(ticker: Iterable[str]) List[str]
Returns either the cross-sectional identifier (cid) or the category (xcat) from a ticker. The function is overloaded to accept either a single ticker or an iterable (e.g. list, tuple, pd.Series, np.array) of tickers.
- Parameters:
Returns :return <str>: The cross-sectional identifier or category.
- get_cid(ticker: str) str [source]#
- get_cid(ticker: Iterable[str]) List[str]
Returns the cross-sectional identifier (cid) from a ticker.
Returns :return <str>: The cross-sectional identifier.
- get_xcat(ticker: str) str [source]#
- get_xcat(ticker: Iterable[str]) List[str]
Returns the category (xcat) from a ticker.
Returns :return <str>: The category.
- Return type:
- form_full_url(url, params={})[source]#
Forms a full URL from a base URL and a dictionary of parameters. Useful for logging and debugging.
- common_cids(df, xcats)[source]#
- Returns a list of cross-sectional identifiers (cids) for which the specified
categories (xcats) are available.
- Parameters:
- return <List[str]>: List of cross-sectional identifiers for which all categories in
xcats are available.
- generate_random_date(start='1990-01-01', end='2020-01-01')[source]#
Generates a random date between two dates.
- Parameters:
Returns :return <str>: The random date.
- Return type:
- get_dict_max_depth(d)[source]#
Returns the maximum depth of a dictionary.
- Parameters:
d (
dict
) – The dictionary to be searched.
Returns :return <int>: The maximum depth of the dictionary.
- Return type:
- rec_search_dict(d, key, match_substring=False, match_type=None)[source]#
Recursively searches a dictionary for a key and returns the value associated with it.
- Parameters:
d (
dict
) – The dictionary to be searched.key (
str
) – The key to be searched for.match_substring (
bool
) – If True, the function will return the value of the first key that contains the substring specified by the key parameter. If False, the function will return the value of the first key that matches the key parameter exactly. Default is False.match_type – If not None, the function will look for a key that matches the search parameters and has the specified type. Default is None.
- Return Any:
The value associated with the key, or None if the key is not found.