API documentation
Main module.
RFR_dict(input_date=None, cache={})
Generates a dictionary containing filenames based on the reference date and other data derived from it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_date |
str
|
The input date in the format "%Y-%m-%d". Defaults to None, which means the current date is used. |
None
|
cache |
dict
|
A dictionary to store intermediate and final results. Defaults to an empty dictionary. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing generated filenames and other data. The dictionary includes the following keys: - "input_date": The input date in the format "%Y-%m-%d". - "reference_date": The reference date in the format "%Y%m%d". - "name_excelfile": The filename for the EIOPA RFR term structures Excel file. - "name_excelfile_spreads": The filename for the EIOPA RFR PD Cod Excel file. |
Source code in solvency2_data/rfr.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
RFR_reference_date(input_date=None, cache={})
Calculates the reference date based on the input date or the current date. If no input date is provided or if the input date is in the future, it defaults to the current date. If the current date is before the 5th of the month, it sets the reference date to the last day of the previous month. Otherwise, it sets the reference date to the next day after the input date.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_date |
str
|
The input date in the format "%Y-%m-%d". Defaults to None, which means the current date is used. |
None
|
cache |
dict
|
A dictionary to store the calculated reference date. Defaults to an empty dictionary. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the input date and the reference date. The input date is stored under the key "input_date" in the format "%Y-%m-%d". The reference date is stored under the key "reference_date" in the format "%Y%m%d". |
Source code in solvency2_data/rfr.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
|
download_RFR(input_date=None, cache={})
Downloads EIOPA RFR (Risk-Free Rate) files for a given date and saves them locally.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_date |
str
|
The input date in the format "%Y-%m-%d". Defaults to None, which means the current date is used. |
None
|
cache |
dict
|
A dictionary to store intermediate and final results. Defaults to an empty dictionary. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing information about the downloaded files and paths. The dictionary includes the following keys: - "input_date": The input date in the format "%Y-%m-%d". - "reference_date": The reference date in the format "%Y%m%d". - "name_excelfile": The filename for the downloaded EIOPA RFR term structures Excel file. - "name_excelfile_spreads": The filename for the downloaded EIOPA RFR PD Cod Excel file. - "url": The URL from which the files were downloaded. - "name_zipfile": The name of the downloaded zip file. - "path_excelfile": The path where the Excel files are saved. - "path_zipfile": The path where the zip file is saved. |
Source code in solvency2_data/rfr.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
read(input_date=None, path=None, proxies=None)
Reads data from Excel files and stores it in a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_date |
str
|
The input date in the format "%Y-%m-%d". Defaults to None, which means the current date is used. |
None
|
path |
str
|
The path to the directory containing Excel files. If None, it looks for .cfg files in the current directory or the package directory. Defaults to None. |
None
|
proxies |
Union[dict, None]
|
None or a dictionary of proxies to be used when downloading rates (None turns off proxies completely) |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the read data. The dictionary includes various keys storing downloaded files, metadata, spot data, spreadsheets, etc. |
Source code in solvency2_data/rfr.py
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
|
read_govies(xls, cache={})
Reads central government fundamental spreads from an Excel file and stores them in a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xls |
An object representing the Excel file. |
required | |
cache |
dict
|
A dictionary to store the read spreadsheets. Defaults to an empty dictionary. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the read spreadsheets. The dictionary includes the following keys: - "central government fundamental spreads": A DataFrame containing central government spreads. The DataFrame includes spreads for various financial attributes indexed by dates. |
Source code in solvency2_data/rfr.py
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
|
read_meta(xls, cache={})
Reads metadata from an Excel file and stores it in a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xls |
An object representing the Excel file. |
required | |
cache |
dict
|
A dictionary to store the read metadata. Defaults to an empty dictionary. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the read metadata. The dictionary includes the following key: - "meta": DataFrame containing metadata. The DataFrame includes metadata indexed by "meta" and may include information such as headers, column descriptions, and other relevant details. |
Source code in solvency2_data/rfr.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
|
read_spot(xls, cache={})
Reads various spot data from an Excel file and stores them in a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xls |
An object representing the Excel file. |
required | |
cache |
dict
|
A dictionary to store the read spot data. Defaults to an empty dictionary. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the read spot data. The dictionary includes the following keys: - "RFR_spot_no_VA": DataFrame containing spot data without VA. - "RFR_spot_with_VA": DataFrame containing spot data with VA. - "Spot_NO_VA_shock_UP": DataFrame containing spot data without VA with UP shock. - "Spot_NO_VA_shock_DOWN": DataFrame containing spot data without VA with DOWN shock. - "Spot_WITH_VA_shock_UP": DataFrame containing spot data with VA with UP shock. - "Spot_WITH_VA_shock_DOWN": DataFrame containing spot data with VA with DOWN shock. Each DataFrame contains spot data indexed by duration. |
Source code in solvency2_data/rfr.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
|
read_spreads(xls, cache={})
Reads financial and non-financial fundamental spreads from an Excel file and stores them in a dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xls |
ExcelFile
|
An ExcelFile object containing the spreadsheets. |
required |
cache |
dict
|
A dictionary to store the read spreadsheets. Defaults to an empty dictionary. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the read spreadsheets. The dictionary includes the following keys: - "financial fundamental spreads": A dictionary containing financial spreadsheets for different currencies. - "non-financial fundamental spreads": A dictionary containing non-financial spreadsheets for different currencies. Each sub-dictionary contains DataFrames with financial or non-financial spreads for the respective currencies. |
Source code in solvency2_data/rfr.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|
Downloads rfr and stores in sqlite database for future reference
add_to_db(ref_date, db, data_type='rfr', workspace=None, proxies=None)
Adds data to the EIOPA database, to use when you are missing data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref_date |
str
|
The reference date in the format "%Y-%m-%d". |
required |
db |
EiopaDB
|
The EIOPA database instance. |
required |
data_type |
str
|
The type of data to add. Options: "rfr" (default), "meta", "spreads", "govies", "sym_adj". |
'rfr'
|
workspace |
dict
|
A dictionary containing workspace directories and paths. If None, it retrieves workspace information using get_workspace() function. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
None |
Source code in solvency2_data/eiopa_data.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
download_EIOPA_rates(url, ref_date, workspace=None, proxies=None)
Downloads EIOPA RFR (Risk-Free Rate) files from a given URL and extracts them.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The URL from which to download the EIOPA RFR files. |
required |
ref_date |
str
|
The reference date in the format "%Y-%m-%d". |
required |
workspace |
dict
|
A dictionary containing workspace directories and paths. If None, it retrieves workspace information using get_workspace() function. Defaults to None. |
None
|
proxies |
dict or None
|
proxies to be used when downloading EIOPA rates |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the paths to the downloaded files. The dictionary includes the following keys: - "rfr": The path to the downloaded EIOPA RFR term structures Excel file. - "meta": The path to the downloaded EIOPA RFR meta Excel file. - "spreads": The path to the downloaded EIOPA RFR PD Cod Excel file. - "govies": The path to the downloaded EIOPA RFR govvies Excel file. |
Source code in solvency2_data/eiopa_data.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
download_file(url, raw_folder, filename='', proxies=None)
Downloads a file from a URL and saves it in a specified folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The URL of the file to download. |
required |
raw_folder |
str
|
The path to the directory where the file will be saved. |
required |
filename |
str
|
The desired filename. If not provided, the filename will be derived from the URL. Defaults to "". |
''
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The path to the downloaded file. |
Source code in solvency2_data/eiopa_data.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
extract_govies(govies_filepath)
Extracts government spreads data from an EIOPA RFR spreads Excel file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
govies_filepath |
str
|
The path to the EIOPA RFR spreads Excel file containing government spreads. |
required |
Returns:
Type | Description |
---|---|
pandas.DataFrame or None: A DataFrame containing extracted government spreads data, indexed by country code and duration. Returns None if no government spreads are found. |
Source code in solvency2_data/eiopa_data.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
extract_meta(rfr_filepath)
Extracts metadata from an EIOPA RFR Excel file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rfr_filepath |
str
|
The path to the EIOPA RFR Excel file. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing extracted metadata. The dictionary includes metadata indexed by country. |
Source code in solvency2_data/eiopa_data.py
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
extract_spot_rates(rfr_filepath)
Extracts spot rates from an EIOPA RFR Excel file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rfr_filepath |
str
|
The path to the EIOPA RFR Excel file. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing extracted spot rates. The dictionary includes spot rates indexed by scenario, currency code, and duration. |
Source code in solvency2_data/eiopa_data.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
extract_spreads(spread_filepath)
Extracts spreads data from an EIOPA RFR spreads Excel file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
spread_filepath |
str
|
The path to the EIOPA RFR spreads Excel file. |
required |
Returns:
Type | Description |
---|---|
pandas.DataFrame: A DataFrame containing extracted spreads data. The DataFrame includes spreads indexed by type, currency code, credit curve step, and duration. |
Source code in solvency2_data/eiopa_data.py
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
|
extract_sym_adj(sym_adj_filepath, ref_date)
Extracts symmetric adjustment data from a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sym_adj_filepath |
str
|
The path to the file containing symmetric adjustment data. |
required |
ref_date |
str
|
The reference date in the format "%Y-%m-%d". |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
pd.DataFrame or None: A DataFrame containing symmetric adjustment data. Returns None if there is a date mismatch between the reference date provided and the date in the file. |
Source code in solvency2_data/eiopa_data.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
|
get(ref_date, data_type='rfr', workspace=None, proxies=None)
Retrieves data from the EIOPA database for a given reference date and data type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref_date |
str
|
The reference date in the format "%Y-%m-%d". |
required |
data_type |
str
|
The type of data to retrieve. Options: "rfr" (default), "meta", "spreads", "govies", "sym_adj". |
'rfr'
|
workspace |
dict
|
A dictionary containing workspace directories and paths. If None, it retrieves workspace information using get_workspace() function. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
pandas.DataFrame or None: A DataFrame containing retrieved data. Returns None if no data is found for the given reference date and data type. |
Source code in solvency2_data/eiopa_data.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 |
|
get_workspace()
Retrieves workspace directories and paths from the configuration.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing workspace directories and paths. The dictionary includes the following keys: - "database": The path to the EIOPA database file. - "raw_data": The path to the directory containing raw data. |
Source code in solvency2_data/eiopa_data.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
|
refresh(proxies=None)
Refreshes the EIOPA database by updating data for each month from January 2016 to the current month.
Returns:
Name | Type | Description |
---|---|---|
str |
A message indicating that the database has been successfully rebuilt. |
Source code in solvency2_data/eiopa_data.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
|
validate_date_string(ref_date)
Validates the input date string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref_date |
str or date
|
The input date string or datetime.date object. |
required |
Returns:
Type | Description |
---|---|
str or None: A validated date string in the format "%Y-%m-%d". Returns None if the input date type is not recognized or cannot be converted. |
Source code in solvency2_data/eiopa_data.py
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
|
Returns links for EIOPA files
check_if_download(url, proxies=None)
Checks if the URL points to a downloadable resource.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The URL to check. |
required |
proxies |
Union[dict, None]
|
None or a dictionary of proxies to pass in requests.get |
None
|
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the resource is downloadable, False otherwise. |
Source code in solvency2_data/scraping.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
eiopa_link(ref_date, data_type='rfr', proxies=None)
Generates the link for downloading the selected type of data for a given date.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ref_date |
str
|
The reference date in the format 'YYYY-MM-DD'. |
required |
data_type |
str
|
The type of the dataset. Defaults to 'rfr'. |
'rfr'
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The valid link to the dataset. |
Example
from datetime import date import pandas as pd dr = pd.date_range(date(2016, 1, 31), date(2023, 5, 31), freq='M') rfr_links = {i.strftime('%Y%m%d'): eiopa_link(i.strftime('%Y-%m-%d')) for i in dr} sym_adj_links = {i.strftime('%Y%m%d'): eiopa_link(i.strftime('%Y-%m-%d'), 'sym_adj') for i in dr}
Source code in solvency2_data/scraping.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
|
get_links(urls, r, proxies=None)
Retrieves valid download links from a list of URLs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urls |
str
|
A list of URLs to search for links. |
required |
r |
str
|
The pattern to match for links. |
required |
proxies |
Union[dict, None]
|
None or a dictionary of proxies to pass in requests.get |
None
|
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
A list of valid download links. |
Source code in solvency2_data/scraping.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
lookthrough_redirect(url)
Looks through redirects and returns the final URL.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
str
|
The URL to look through. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The final URL after following redirects. |
Source code in solvency2_data/scraping.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
This module contains all the handler functions for the sqlite database storing the data
EiopaDB
Bases: object
Database object to store the EIOPA data.
Attributes:
Name | Type | Description |
---|---|---|
database |
str
|
Path to the database file. |
Methods:
Name | Description |
---|---|
__init__ |
Initialize database object. |
reset |
Hard reset of the database. |
set_conn |
Set database connection. |
_close_conn |
Close database connection. |
get_set_id |
Get the URL ID for a URL. |
_add_set |
Add a new URL to the catalog. |
update_catalog |
Update the catalog with new values. |
Source code in solvency2_data/sqlite_handler.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
|
__init__(database)
Initialize the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
database |
str
|
Path to the database file. |
required |
Returns:
Type | Description |
---|---|
None |
Source code in solvency2_data/sqlite_handler.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
get_set_id(url)
Get the url id for a url If not there, check if valid then add
Parameters:
Name | Type | Description | Default |
---|---|---|---|
url |
url to be found |
required |
Returns:
Type | Description |
---|---|
None |
Source code in solvency2_data/sqlite_handler.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
reset()
Hard reset of the database
Returns:
Type | Description |
---|---|
None |
Source code in solvency2_data/sqlite_handler.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
set_conn()
Set database connection
Returns:
Type | Description |
---|---|
None |
Source code in solvency2_data/sqlite_handler.py
64 65 66 67 68 69 70 71 72 73 74 75 |
|
create_connection(database)
create a database connection to the SQLite database
Parameters:
Name | Type | Description | Default |
---|---|---|---|
database |
str
|
database specified by database file path |
required |
Returns:
Type | Description |
---|---|
connection object or None |
Source code in solvency2_data/sqlite_handler.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
|
create_eiopa_db(database='eiopa.db')
Create the EIOPA database
Parameters:
Name | Type | Description | Default |
---|---|---|---|
database |
str
|
name of the database to be created |
'eiopa.db'
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in solvency2_data/sqlite_handler.py
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
exec_sql(conn, sql)
Execute sql in connection
Parameters:
Name | Type | Description | Default |
---|---|---|---|
conn |
database connection |
required | |
sql |
str
|
sql statement to be executed |
required |
Returns:
Type | Description |
---|---|
None |
Source code in solvency2_data/sqlite_handler.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
|
Calculates Smith-Wilson parameters and returns output based on the specified parameters.
Note: Prices of all instruments are set to 1 by construction. Hence 1: if Instrument = Zero then for Zero i there is only one pay-off of (1+r(i))^u(i) at time u(i). Hence 2: if Instrument = Swap or Bond then for Swap/Bond i there are pay-offs of r(i)/nrofcoup at time 1/nrofcoup, 2/nrofcoup, ... u(i)-1/nrofcoup plus a final pay-off of 1+r(i)/nrofcoup at time u(i).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
instrument |
str
|
Type of financial instrument. Default is "Zero". |
'Zero'
|
liquid_maturities |
list
|
Liquid maturities. |
[]
|
RatesIn |
dict
|
Input dictionary for RatesIn. |
{}
|
nrofcoup |
int
|
Number of Coupon Payments per Year. Default is 1. |
1
|
cra |
float
|
Credit Risk Adjustment in basispoints. Default is 0. |
0
|
ufr |
float
|
Ultimate Forward Rate annual compounded (perunage). Default is 0. |
0
|
min_alfa |
float
|
Minimum value for alfa. Default is 0.05. |
0.05
|
tau |
float
|
Tau value. Default is 1. |
1
|
T2 |
int
|
Convergence Maturity. Default is 60. |
60
|
precision |
int
|
Precision value. Default is 6. |
6
|
method |
str
|
Calculation method. Default is "brute_force". |
'brute_force'
|
output_type |
str
|
Type of output. Default is "zero rates annual compounding". |
'zero rates annual compounding'
|
Returns:
Name | Type | Description |
---|---|---|
output |
Calculated output based on the specified parameters. |
Example
instrument = "Zero" liquid_maturities = [1, 2, 3, 4, 5] RatesIn = {0: 0.02, 1: 0.025, 2: 0.03, 3: 0.035, 4: 0.04, 5: 0.045} nrofcoup = 2 cra = 0.01 ufr = 0.05 min_alfa = 0.05 tau = 1 T2 = 60 precision = 6 method = "brute_force" output_type = "zero rates annual compounding" smith_wilson(instrument, liquid_maturities, RatesIn, nrofcoup, cra, ufr, min_alfa, tau, T2, precision, method, output_type) array([0. , 0.01984642, 0.04040711, 0.06171705, 0.08381221, 0.10672926, 0.13050535, 0.15517806, 0.18078504, 0.20736481, 0.23495648, 0.26360038, 0.29333873, 0.3242144 , 0.35627157, 0.3895553 , 0.42411294, 0.4599934 , 0.49724737, 0.53592752, 0.57608986, 0.61779295, 0.66109833, 0.70607181, 0.75278461, 0.80131366, 0.85174183, 0.90415729, 0.95865366, 1.01533039, 1.0742924 , 1.13564943, 1.19951555, 1.26601055, 1.33526045, 1.40739786, 1.48256135, 1.5608958 , 1.6425528 , 1.72769014, 1.81647324, 1.90907556, 2.00567914, 2.10647707, 2.21167306, 2.32148215, 2.43613139, 2.55586064, 2.68092039, 2.81157657, 2.94810739, 3.09080731, 3.23998602, 3.39596949, 3.559099 , 3.72973118, 3.90823814, 4.09500861, 4.29045285, 4.49400082, 4.70510529, 4.92324198, 5.14791281, 5.37864303, 5.61498852, 5.85652901, 6.10287445, 6.35366537, 6.6085712 , 6.86728774, 7.12954064, 7.395082 , 7.66368905, 7.93516083, 8.20931788, 8.48599994, 8.76506649, 9.04639664, 9.329887 , 9.61545067, 9.90301596, 10.19252555, 10.48393262, 10.77720086, 11.07230382, 11.36922416, 11.66795383, 11.96849432, 12.27085209, 12.57503994, 12.88007745, 13.18599135, 13.49281377, 13.80058263, 14.109341 , 14.41913647, 14.73002158, 15.04205535, 15.35530365, 15.66983964, 15.98574325, 16.30310069, 16.62199494, 16.94251238, 17.2647438 , 17.5887832 , 17.91472858, 18.24268076, 18.5727421 , 18.90502131, 19.23963426, 19.57670285, 19.9163558 , 20.25872748, 20.60395864, 20.95219615, 21.30359381, 21.65831201, 22.01651854, 22.3783874 ])
Source code in solvency2_data/smith_wilson.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
|
DiscountedValue4par2forwards(sum_df=0, last_df=0, par_rate=0, forward_rate=0, t_min_k=0)
Calculates the discounted value for two-factor parallel forwards.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sum_df |
float
|
The sum of discount factors. Defaults to 0. |
0
|
last_df |
float
|
The last discount factor. Defaults to 0. |
0
|
par_rate |
float
|
The par rate. Defaults to 0. |
0
|
forward_rate |
float
|
The forward rate. Defaults to 0. |
0
|
t_min_k |
int
|
The difference between the two terms. Defaults to 0. |
0
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The calculated discounted value. |
Source code in solvency2_data/alternative_extrapolation.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
FromParToForwards(term_struct=None, span=120, max_runs=MAX_RUNS, max_error=MAX_ERROR)
Converts a par rate term structure to forward rates.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
term_struct |
Series
|
The par rate term structure. Defaults to None. |
None
|
span |
int
|
The span of the forward rates. Defaults to 120. |
120
|
max_runs |
int
|
The maximum number of iterations for convergence. Defaults to MAX_RUNS. |
MAX_RUNS
|
max_error |
float
|
The maximum error for convergence. Defaults to MAX_ERROR. |
MAX_ERROR
|
Returns:
Type | Description |
---|---|
pd.Series: The forward rates term structure. |
Source code in solvency2_data/alternative_extrapolation.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
create_swap_struct(rfr=None, additional_swaps={})
Creates a swap structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rfr |
Series
|
The risk-free rate term structure. Defaults to None. |
None
|
additional_swaps |
dict
|
Additional swaps to be included. Defaults to {}. |
{}
|
Returns:
Type | Description |
---|---|
Series(dtype=float64)
|
pd.Series: The swap structure. |
Source code in solvency2_data/alternative_extrapolation.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
forwardstruct2termstruct(forward_struct)
Converts a forward rate structure to a term structure.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
forward_struct |
Series
|
The forward rate structure. |
required |
Returns:
Type | Description |
---|---|
Series(dtype=float64)
|
pd.Series: The term structure. |
Source code in solvency2_data/alternative_extrapolation.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
|
Common utilities shared across modules
get_config()
Reads the configuration from the solvency2_data.cfg file.
Returns:
Name | Type | Description |
---|---|---|
dict |
A dictionary containing the configuration settings. |
Example
get_config() {'[Section1]': {'key1': 'value1', 'key2': 'value2'}, '[Section2]': {'key3': 'value3'}}
Source code in solvency2_data/util.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
|
set_config(new_value, existing_key='data_folder')
Sets a new value for the specified key in the configuration file solvency2_data.cfg.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_value |
str
|
The new value to set for the specified key. |
required |
existing_key |
str
|
The key whose value needs to be updated. Default is "data_folder". |
'data_folder'
|
Returns:
Name | Type | Description |
---|---|---|
int |
Returns 0 upon successful completion. |
Example
set_config("/new/data/folder", "data_folder") Download paths updated 0
Source code in solvency2_data/util.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
|