Open kevinykuo opened 5 years ago
Which cell were you running?
# Run the FM directly via Python code.
# This can enable more complex analytical operations. In the example below, we
# estimate the damage level (as a % of TIV) at which the portfolio attachs and exhausts.
from oasislmf.manager import OasisManager
om = OasisManager()
# At what level of loss do the accounts attach?
last_loss = 0
attachment = 0
exhaustion = 0
# Cycle through all percentage loss levels in 1% increments
for i in range (0, 100):
# Generate the losses
(gul_losses, il_losses, ri_losses) = om.run_deterministic(
src_dir='/tmp/exercise_1_oed',
loss_percentage_of_tiv=i/100)
total_loss = il_losses.loss.sum()
# Has the portfolio attached?
if attachment == 0 and total_loss > 0:
attachment = i
# Has the portfolio exhasuted?
if i > 0 and total_loss > 0 and total_loss == last_loss:
exhaustion = i
break
last_loss = total_loss
print("Attaching loss level: {}%; Exhausting loss level: {}%".format(attachment, exhaustion))
@sr-murthy have you encountered any similar issues with the MDK on Mac?
I have never seen this error because I haven't run any of these notebooks. Which notebook/exercise does this relate to, and which step?
I meant more generally, but it should be easy to run. As per note above, it is exercise 1 and I think the last cell.
No, this error hasn't come up in any other context of running the MDK.
The last step in exercise 1 could well cause a problem because of the starting value of the for
loop
for i in range (0, 100):
# Generate the losses
(gul_losses, il_losses, ri_losses) = om.run_deterministic(
src_dir='/tmp/exercise_1_oed',
loss_percentage_of_tiv=i/100)
total_loss = il_losses.loss.sum()
If i
is 0
then loss_percentage_of_tiv
is 0
in the manager's generate_deterministic_losses
method, which means that all the initially created GUL items will have loss values of 0
https://github.com/OasisLMF/OasisLMF/blob/develop/oasislmf/manager.py#L641
As only GUL items with non-zero losses are selected, with a loss factor of 0 there wouldn't be any final stage GUL items, which means empty dataframes and indexing errors.
Perhaps this is the problem, but I don't know for sure. I would have to reproduce the problem.
@kevinykuo Please try exercise 1 again. I've made a small change to the for
loop in the last step.
Did you replicate this issue? I haven't had any problem running with loss-factor=0, and this should probably be allowed and just create zero losses.
I haven't been able to replicate it because of issues with Jupyter - it seems unable to find oasislmf
in the notebook environment. I tried to add the usual location of site-packages
in the virtual env. to sys.path
in the notebook directly, but that didn't work.
Still hitting the same error with the update.
I will have another look at it.
@kevinykuo Please try again - the problem appears to have been related to a typo in the oasislmf
package Git branch URI in the original version of the requirements file. I have fixed this, and it should now install the develop
branch rather than the release.
I have managed to complete all the exercise 1 steps, including the last one (I added some extra print statements in the for
loop for debugging, but this can be removed). Here's the output of the last step
Generating losses using loss factor 0.0: no attachment found
Generating losses using loss factor 0.01: no attachment found
Generating losses using loss factor 0.02: no attachment found
Generating losses using loss factor 0.03: no attachment found
Generating losses using loss factor 0.04: no attachment found
Generating losses using loss factor 0.05: no attachment found
Generating losses using loss factor 0.06: no attachment found
Generating losses using loss factor 0.07: no attachment found
Generating losses using loss factor 0.08: no attachment found
Generating losses using loss factor 0.09: found attachment
....
Attaching loss level: 9%; Exhausting loss level: 27%
Stack trace below. Note I'm running on mac but this might not be OS specific.