"""Average sample tail losses.

This uses observations at or below the interpolated cutoff, so the selected tail mass can exceed 1-confidence.
All inputs are synthetic teaching examples. Run: python 32_expected-shortfall.py
"""
from tv_math import *

v=historical_risk([-.05,-.03,0,.02,.04],.75)
assert abs(v['expected_shortfall_loss']-.04)<1e-12 and v['tail_count']==2
print(v)
