OasisLMF / ktools

In-memory simulation kernel for loss modelling.
BSD 3-Clause "New" or "Revised" License
28 stars 19 forks source link

Fix Per Sample Mean (Wheatsheaf Mean) with Period Weights Output from leccalc/ordleccalc #349

Closed hchagani-oasislmf closed 1 year ago

hchagani-oasislmf commented 1 year ago

Fix Per Sample Mean (Wheatsheaf Mean) with Period Weights Output from leccalc/ordleccalc

When a period weights file was supplied by the user, the Per Sample Mean (i.e. Wheatsheaf Mean) from leccalc and ordleccalc was incorrect. After sorting the loss vector in descending order, the vector was then reorganised by period number, nullifying the sorting. This would only yield the correct results in the very rare cases when the loss value decreased with increasing period number.

As the return periods are determined by the period weights, in order to calculate the mean losses, the data would need to traversed twice: once to determine the return periods; and the second time to fill them. However, if the return periods are known in advance, i.e. when the user supplies a return period file, the first iteration is unnecessary.

As the per sample mean with period weights does not appear to be a very useful metric, this option is only supported when a return periods file is present. Should a return periods file be missing, the following message will be written to the log file:

WARNING: Return periods file must be present if you wish to use non-uniform period weights for Wheatsheaf mean/per sample mean output.
INFO: Wheatsheaf mean/per sample mean output will not be produced.

As outlined above, the per sample mean (i.e. Wheatsheaf mean) will not be calculated and written out.

The Tail Value at Risk (TVaR) is only meaningful if the losses for all possible return periods are generated. Therefore, it has been dropped from the ordleccalc output with the following message written to the log file:

INFO: Tail Value at Risk for Wheatsheaf mean/per sample mean is not supported if you wish to use non-uniform period weights.

The decision to drop support can be revisited should the aforementioned metrics be deemed useful by the community.