-
Notifications
You must be signed in to change notification settings - Fork 21
Create CAT bond module #186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KaiOBerg
wants to merge
157
commits into
develop
Choose a base branch
from
feature/cat_bonds
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
157 commits
Select commit
Hold shift + click to select a range
93e924f
initial commit CAT Bonds
KaiOBerg f502208
change subarea building to resolution input
KaiOBerg 2c23ff5
alter subarea creation test notebook
KaiOBerg 3e9457e
take crs from exposure
KaiOBerg efe9a75
dont save exp_gdf and adjust plotting
KaiOBerg cbd9b94
add buffer to create subareas
KaiOBerg 716d3a0
streamline calculations
KaiOBerg 96c26c4
change calculation of attachment and prinipal
KaiOBerg cc4fdee
keep only grids with exposure point within
KaiOBerg 16caea0
fix bugs
KaiOBerg 6533b49
adjust calc savings
KaiOBerg bf54f9b
adjust test notebook to changed classes
KaiOBerg 688027d
inititate bond simulation class
KaiOBerg 0a35b87
delete pay_dam_subarea class
KaiOBerg 519dcb4
update function descriptions
KaiOBerg 8a2accf
fix bugs
KaiOBerg 08bd04e
add total payout and damage
KaiOBerg 3d59693
update function description
KaiOBerg edf6598
add net cash flow and premium simulation
KaiOBerg 2388d7c
adjust metric naming
KaiOBerg 7db291c
update test to classes
KaiOBerg f9c6cab
change function naming
KaiOBerg 1168e62
inititate premium class
KaiOBerg 8ef65cb
add IBRD CAT bonds data file
KaiOBerg 6d30ad7
add ibrd based premium calculation
KaiOBerg fc3edc8
improve logging and fix bug chatoro
KaiOBerg c7d1134
fix path to data dir
KaiOBerg 6bf627e
remove premium input
KaiOBerg c93b862
adjust test notebook to classes
KaiOBerg b820b8c
add benchmark premium calculation
KaiOBerg ce9952c
include all premium methods in test notebook
KaiOBerg 0d5fbcd
remove buffer grid size
KaiOBerg 82d185d
define variables
KaiOBerg d6a494c
rename bond_simulation to sng_bond_simulation
KaiOBerg 7322e02
initialize multi country bond simulation
KaiOBerg d6250ff
add function to derive VaR and ES
KaiOBerg ac4c317
add jamaica bond
KaiOBerg c4d2d99
fix bugs exp and haz jamaica
KaiOBerg 78e8b8e
test multi-country bond in notebook
KaiOBerg 4b9c735
add minimum simulation year
KaiOBerg a440927
Update climada_petals/engine/cat_bonds/mlt_bond_simulation.py
KaiOBerg 616bf60
make init loss more pythonic
KaiOBerg d50ceb5
change var es function
KaiOBerg ac20d79
adjust test notebook for confidence intervals
KaiOBerg 50ac5ef
remove nested loop from bond simulation
KaiOBerg da53e8a
change fucntion description
KaiOBerg c02d1eb
fix type of single events in df_loss_month
KaiOBerg 7c6458b
adjust to chanings in sng_simulation
KaiOBerg ad92d39
implement return simulation mlt bonds
KaiOBerg 9c5ca13
rename funciton names
KaiOBerg 0e95f18
init function to calculate returns with trances
KaiOBerg 805bbe1
add required principal calculation
KaiOBerg d692bea
save required principal to mlt_bond class
KaiOBerg 05a88ee
rename functions
KaiOBerg 61802b5
make bond term function private
KaiOBerg 2b3484b
adapt changes in mlt class to test notebook
KaiOBerg 1d5897d
fix min year in requ_principal and initialze min_year at class init
KaiOBerg 499bf97
add function for overlapping subareas
KaiOBerg 0fef13e
add belize
KaiOBerg a53e32e
make build_subareas optional
KaiOBerg 0b09fe5
minor adjustments
KaiOBerg 6051337
rename class names
KaiOBerg d2ec6c4
initialize pooling optimization problems
KaiOBerg edfb591
add function to derive optimal fixed pools
KaiOBerg 7efc9a2
move allocate tranche payout to utils
KaiOBerg 5a29cc3
rename test notebook to tutorial
KaiOBerg 58bf8e1
move tutorial
KaiOBerg 9166134
initialize subareas with resolution
KaiOBerg e5d2d47
initiate subareas by resolution
KaiOBerg 5abe3c1
implement pooling n pools
KaiOBerg d8f70a0
initialise class with optimized n pools
KaiOBerg fc1a62f
rename n to n_pools
KaiOBerg 7186418
rename fct process_n to process_n_pools
KaiOBerg 62e4808
add maximum principal wrapper function
KaiOBerg f5c774b
fix iterration bug
KaiOBerg 5e14044
return whole dictionary conatining multiple class instances
KaiOBerg b311758
add logging to simulate_bond_pool_n
KaiOBerg b262e71
add max_principal pooling optimization function
KaiOBerg 4dbea02
adapt to changes in mlt_cty_bond
KaiOBerg 20b08fa
update funciton descriptions
KaiOBerg c486f9c
comment tutorial script
KaiOBerg ad94804
change inital guess values to percentiles of hazard intensity
KaiOBerg df09dd3
implement option to plug in manuall init guess
KaiOBerg a84e767
add function to initialize subarea class with a gdf
KaiOBerg d422c83
update function description
KaiOBerg 9c4a252
move turotial to docs and create init
KaiOBerg e9078d4
fix file paths
KaiOBerg f30d74b
move explode into exp_gdf function
KaiOBerg fa871c8
initialize subaarea unit tests
KaiOBerg 16ce43d
remove padding of exposure resolution
KaiOBerg d784b82
add 1.2 padding to exposure resolution
KaiOBerg b7e95b4
add testing of merging polygons
KaiOBerg c1f5d4d
add more test cases to merging polyons
KaiOBerg 70cd21d
fromatting
KaiOBerg e5d515a
init test subarea_calculations
KaiOBerg 9635151
clearify variable origin
KaiOBerg b353942
fix bug
KaiOBerg f2e8f90
add pay_vs_dam test function
KaiOBerg cd7432a
add test objective_function
KaiOBerg b264001
initiate test script for single country bonds
KaiOBerg 56bee84
fix loop bug and remove simulated years
KaiOBerg 5de50d6
test simulate loss
KaiOBerg a7305bd
finish tests for single country bonds
KaiOBerg f7aae42
formatting
KaiOBerg 76b10bc
adjust descriptions
KaiOBerg f53bc2e
initialize test for premium calculations
KaiOBerg bcd29f7
format
KaiOBerg e63caaa
test benchmark sharpe ration function
KaiOBerg b8b65f1
formatting
KaiOBerg 9434653
update function description
KaiOBerg bd5b76d
test multi_level_es function
KaiOBerg a3ca2a0
formatting
KaiOBerg 64c233c
update logging to petals LOGGER
KaiOBerg 301b485
restructure tests
KaiOBerg d857f33
changed structure of tests
KaiOBerg 675f460
change structure of tests
KaiOBerg c8c5e24
adjust test structure
KaiOBerg 8eaa0c0
change test structure
KaiOBerg da8d4c4
remove bug of missing last term
KaiOBerg c24c18e
fix bug of starting year
KaiOBerg ef05eae
test multi country cat bond class
KaiOBerg 43dc34e
ensure valid results
KaiOBerg 007155d
get country location even if risk concentration does not improve
KaiOBerg 819677e
finsih mlt_bond_class tests
KaiOBerg e9917d7
remove unnecessary packages
KaiOBerg cdd99cd
reomve logging
KaiOBerg 64830e7
remove unnecessary impf_set lines
KaiOBerg b7245ec
finish doc strings
KaiOBerg 56998ec
finish doc strings and parameter types for premium_class
KaiOBerg 305cc8c
add types to init
KaiOBerg ea3bb7e
finsih doc strings
KaiOBerg 51be90f
finish doc strings for subarea_calculations
KaiOBerg ba0e777
finsih docstrings for subareas
KaiOBerg 20f454f
finsih doc strings for utils
KaiOBerg dbaafb0
ensure cur_nominal is array
KaiOBerg 051873f
add minimalistic doc strings
KaiOBerg 1655f03
finalize testin script for premium class
KaiOBerg b921ec4
add test for monoexp
KaiOBerg 2081797
add edge case for same month events and doc stings
KaiOBerg cef1d2f
test create_pay_vs_dam and _calc_impact and add doc stings
KaiOBerg 3e7549b
fix naming inconsistencies
KaiOBerg a2c08cf
add test functions for from_resolution and from_geodataframe and doc …
KaiOBerg 70b1425
add doc strings to test script for utils in cat_bonds
KaiOBerg 5fffab7
remove ElementwiseProblem inheritance
KaiOBerg 56ecb4a
initiate test function for pooling
KaiOBerg dbd66bb
clean up pooling_functions.py
KaiOBerg 7d3c8af
add principal calculation to class methods
KaiOBerg 8c2eb95
remove not necessary logging messages
KaiOBerg abeb227
update docstrings
KaiOBerg f1ad7f5
raise error if tranches share of principal does not equal 1
KaiOBerg 1d8f207
insert comments and descriptions; add single-country vs multi-country…
KaiOBerg 56e424c
small fixes
KaiOBerg 5526149
review docstrings
KaiOBerg 83ba37a
improve naming convettions and add comments for better clarity
KaiOBerg b559945
last bug fixes and renaming
KaiOBerg a3f0431
Add pymoo dependency
27b434f
Correct typo
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
initialize test for premium calculations
- Loading branch information
commit f53bc2e34c1624e3c3bca240eb53591055e13481
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
climada_petals/engine/cat_bonds/test/test_premium_class.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import numpy as np | ||
| import pandas as pd | ||
| import logging | ||
| from climada_petals.engine.cat_bonds.premium_class import PremiumCalculations | ||
|
|
||
| logging.basicConfig( | ||
| format="{asctime} - {levelname} - {message}", | ||
| style="{", | ||
| datefmt="%Y-%m-%d %H:%M", | ||
| level=logging.INFO, | ||
| ) | ||
| LOGGER = logging.getLogger(__name__) | ||
|
|
||
| class DummyBondSim: | ||
| """Minimum mock needed for PremiumCalculations.""" | ||
| def __init__(self, EL_ann, term, df_loss_month=None): | ||
| self.loss_metrics = {"EL_ann": EL_ann} | ||
| self.term = term | ||
| self.df_loss_month = df_loss_month | ||
|
|
||
|
|
||
| # --------------------------------------------------------- | ||
| # TEST SHARPE OPTIMIZATION | ||
| # --------------------------------------------------------- | ||
|
|
||
| def test_find_sharpe_single_loss_event(): | ||
| """ | ||
| Validate net cash flow logic. | ||
| 1 year, 1 loss in June, simple numbers. | ||
| """ | ||
| df = pd.DataFrame({ | ||
| "losses": [[0.2]], | ||
| "months": [[6]] | ||
| }) | ||
|
|
||
| bond = DummyBondSim(EL_ann=0.02, term=1, df_loss_month=df) | ||
| pc = PremiumCalculations(bond) | ||
|
|
||
| # manually compute NCF: | ||
| # Pre-event premium: (1 * p)/12 * 6 | ||
| # Post-event premium: (0.8 * p)/12 * (12 - 6) - 0.2 loss | ||
| # NCF = p/2 + (0.8p/2 - 0.2) = 0.9p - 0.2 | ||
| p = 0.05 | ||
| expected_ncf = 0.9 * p - 0.2 | ||
|
|
||
| sharpe = pc.find_sharpe(premium=p, monthly_losses=df, target_sharpe=0) | ||
|
|
||
| # extracted NCF from method | ||
| ncf = [] | ||
| cur_nominal = 1 | ||
| losses = [0.2] | ||
| months = [6] | ||
| ncf_pre = (cur_nominal * p) / 12 * 6 | ||
| cur_nominal -= 0.2 | ||
| ncf_post = (cur_nominal * p) / 12 * 6 - 0.2 | ||
| manual_list = [ncf_pre + ncf_post] | ||
|
|
||
| manual_sharpe = (np.mean(manual_list) / np.std(manual_list + [manual_list[0] * 1.0001]))**2 # std>0 | ||
|
|
||
| assert np.isclose(sharpe, manual_sharpe, rtol=1e-6) # just ensure valid number | ||
| assert np.isclose(expected_ncf, manual_list[0], rtol=1e-6) | ||
|
|
||
|
|
||
| def test_calc_benchmark_premium_converges(): | ||
| """ | ||
| Test that optimization finds higher premium when losses > 0. | ||
| """ | ||
|
|
||
| df = pd.DataFrame({ | ||
| "losses": [[0.1], [0.2], [0.0]], | ||
| "months": [[3], [6], [0]] | ||
| }) | ||
|
|
||
| bond = DummyBondSim(EL_ann=0.02, term=1, df_loss_month=df) | ||
| pc = PremiumCalculations(bond) | ||
|
|
||
| pc.calc_benchmark_premium(target_sharpe=0.2) | ||
|
|
||
| assert pc.benchmark_prem_rate > 0 | ||
| assert pc.benchmark_prem_rate < 1.0 # sanity bound | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| test_calc_benchmark_premium_converges() | ||
| LOGGER.info("test_calc_benchmark_premium_converges passed") | ||
| test_find_sharpe_single_loss_event() | ||
| LOGGER.info("test_find_sharpe_single_loss_event passed") | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.