Select indices based on specified filter criteria. Returns all indices when no input is given and has the option to give a specific combination of indices based on the filters defined. Args: category_group (str | list, optional): Filter by category grou
(
self,
category_group: str | list | None = None,
category: str | list | None = None,
currency: str | list | None = None,
exchange: str | list | None = None,
mic: str | list | None = None,
)
| 22 | FILE_NAME = "indices.bz2" |
| 23 | |
| 24 | def select( |
| 25 | self, |
| 26 | category_group: str | list | None = None, |
| 27 | category: str | list | None = None, |
| 28 | currency: str | list | None = None, |
| 29 | exchange: str | list | None = None, |
| 30 | mic: str | list | None = None, |
| 31 | ) -> FinanceFrame: |
| 32 | """ |
| 33 | Select indices based on specified filter criteria. |
| 34 | |
| 35 | Returns all indices when no input is given and has the option to give |
| 36 | a specific combination of indices based on the filters defined. |
| 37 | |
| 38 | Args: |
| 39 | category_group (str | list, optional): Filter by category group. |
| 40 | Default is None, which returns all category groups. |
| 41 | category (str | list, optional): Filter by category. |
| 42 | Default is None, which returns all categories. |
| 43 | currency (str | list, optional): Filter by currency. |
| 44 | Default is None, which returns all currencies. |
| 45 | exchange (str | list, optional): Filter by exchange. |
| 46 | Default is None, which returns all exchanges. |
| 47 | mic (str | list, optional): Filter by ISO 10383 MIC code. |
| 48 | Default is None, which returns all MIC codes. |
| 49 | |
| 50 | Raises: |
| 51 | ValueError: If the specified category group, category, currency, or exchange |
| 52 | is not available in the database. |
| 53 | |
| 54 | Returns: |
| 55 | FinanceFrame: DataFrame containing indices data matching the specified criteria. |
| 56 | """ |
| 57 | indices = self.data.copy(deep=True) |
| 58 | |
| 59 | if category_group: |
| 60 | category_groups = ( |
| 61 | [category_group] if isinstance(category_group, str) else category_group |
| 62 | ) |
| 63 | category_groups_lower = [ |
| 64 | category_group.lower() for category_group in category_groups |
| 65 | ] |
| 66 | options_lower = [ |
| 67 | option.lower() |
| 68 | for option in self.show_options(selection="category_group") |
| 69 | ] |
| 70 | for category_group_lower, category_group_actual in zip( |
| 71 | category_groups_lower, category_groups |
| 72 | ): |
| 73 | if category_group_lower not in options_lower: |
| 74 | raise ValueError( |
| 75 | f"The category group '{category_group_actual}' is not available in the database. " |
| 76 | "Please check the available category groups using the 'show_options' method." |
| 77 | ) |
| 78 | indices = indices[ |
| 79 | indices["category_group"].str.lower().isin(category_groups_lower) |
| 80 | ] |
| 81 | if category: |
no test coverage detected