Source code for finpricing.market.lgd_curve
import datetime
from typing import Union
from ..utils import Date
[docs]
class LGDCurve:
def __init__(self, *args, **kwargs):
if len(kwargs) == 1 and "lgd" in kwargs:
self.curve = LGDCurveConstant(kwargs["lgd"])
elif len(kwargs) == 1 and "recovery_rate" in kwargs:
self.curve = LGDCurveConstant.from_recovery_rate(kwargs["recovery_rate"])
else:
raise TypeError("Invalid LGDCurve initialization")
[docs]
def loss(self, date: Union[Date, datetime.date]):
return self.curve.loss(date)
[docs]
class LGDCurveConstant:
def __init__(self, lgd: float):
self.lgd = lgd
[docs]
@classmethod
def from_recovery_rate(cls, recovery_rate: float):
return cls(1 - recovery_rate)
[docs]
def loss(self, date: Union[Date, datetime.date]):
return self.lgd