Data Class

A class to handle data operations for the Solvency Capital Requirement (SCR) calculation.

This class is responsible for importing, processing, and exporting data used in the SCR calculations. It serves as a crucial component in the SCR calculation process, providing data management and validation functionalities.

The class is split across several modules:
  • data.py: The main class file containing core data handling functions

  • access.py: Functions for interacting with MS Access databases

  • excel.py: Functions for reading from and writing to Excel files

  • odbc.py: Functions for ODBC database connections and operations

  • data_models.py: Pydantic models for data validation, still under development

  • data_validation.py: Functions for validating imported data, still under development

The Data class supports various data sources and formats, ensuring flexibility in data input and output for SCR calculations. Future plans are to implement data validation to ensure the integrity and correctness of imported data before it’s used in SCR calculations.

Note:

This class is designed to be used in conjunction with the SCR class and its various risk modules. It provides the necessary data infrastructure for accurate and efficient SCR calculations.

data

Supporting Modules

access

data_models

data_validation

excel

f_excel_export(sam_scr, result_set, export_file, process_id=None)[source]

Export data to an Excel workbook.

f_excel_import_data(import_file, dictionary)[source]

Imports various Excel ranges into a dictionary. This is a helper function to the ‘import_metadata’ and ‘import_data’ functions.

Parameters:
  • import_file (str) – The name of the file to import.

  • sheet_name (str) – The dictionary to import. Must be one of : [“metadata”, “data”]

  • transformation (str) – The type of transformation to apply to the data. Must be one of : [“none”, “index”, “corr”, “melt”]

  • dictionary (Literal['metadata', 'data'])

Returns:

A dictionary of results.

Return type:

Union[pd.DataFrame, None]

Raises:

ValueError – If an unsupported transformation is provided.

Note

The ranges to import are assumed to come from a range named ‘imports’ in the work sheet ‘imports’. The ‘import’ range must include the columns:

-‘dictionary’ -‘python_variable’ -‘worksheet’ -‘range_name’ -‘transformation’

Example:

Parameters:
  • import_file (str)

  • dictionary (Literal['metadata', 'data'])

Return type:

dict

>>> f_excel_import_data("c:/samplicity/test_file.xlsx", "data")
f_excel_import_pa_data(risk_free_rates, symmetric_adjustment)[source]

Import monthly PA files.

f_excel_import_range(range_name, sheet_name, transformation, wb)[source]

Import an Excel range from a workbook.

Parameters:
  • range_name (str) – The name of the range.

  • sheet_name (str) – The name of the worksheet.

  • transformation (str) – The type of transformation to apply to the data. Must be one of : [“none”, “index”, “corr”, “melt”]

  • wb (Book)

Returns:

A Dataframe of results or None if not successful

Return type:

Union[pd.DataFrame, None]

Raises:

ValueError – If an unsupported transformation is provided.

Example:

>>> f_excel_import_range("range_name", "sheet_name", "none", wb)

odbc

chunker(seq, size)[source]
f_odbc_export(self, result_set, conn_string, export_id=None)[source]

Export results using ODBC connection.

f_odbc_import(dat, conn_string, import_table, dict_param=None)[source]
f_odbc_table_import(sql_conn, sql_query, dict_param=None)[source]
insert_with_progress(engine, df, table)[source]

validation