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.
- get_cid(ticker: str) str[source]#
- get_cid(ticker: Iterable[str]) List[str]
Returns the cross-sectional identifier (cid) from a ticker.
- get_xcat(ticker: str) str[source]#
- get_xcat(ticker: Iterable[str]) List[str]
Returns the category (xcat) from a ticker.
- 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:
df (pd.Dataframe) – Standardized JPMaQS DataFrame with necessary columns: ‘cid’, ‘xcat’, ‘real_date’ and ‘value’.
xcats (List[str]) – A list with least two categories whose cross-sectional identifiers are being considered. 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.
- 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 (Any) – If not None, the function will look for a key that matches the search parameters and has the specified type. Default is None.
- Returns:
The value associated with the key, or None if the key is not found.
- Return type:
Any