[docs]def__init__(self,firm_returns:np.ndarray,market_returns:np.ndarray)->None:"""__init__ Args: firm_returns (np.ndarray): ``(n_days,)`` array of the returns (equity or CDS) for the firm. market_returns (np.ndarray): ``(n_days,)`` array of the returns (equity or CDS) for the market as a whole. """assertfirm_returns.shape==market_returns.shapeself.firm_returns=firm_returnsself.market_returns=market_returns
[docs]defestimate(self,q:float=0.05)->float:"""estiamte Args: q (float, optional): The percentile. Range is [0, 1]. Deaults to 0.05. Returns: float: The marginal expected shortfall of firm :math:`i` at time :math:`t`. """assert0<=q<=1low_threshold=np.percentile(self.market_returns,q*100)worst_days=np.argwhere(self.market_returns<low_threshold)returnnp.mean(self.firm_returns[worst_days])