Coverage for rivapy/instruments/cds_specification.py: 29%

17 statements  

« prev     ^ index     » next       coverage.py v7.8.2, created at 2025-06-05 14:27 +0000

1from datetime import datetime 

2from typing import List 

3 

4 

5class CDSSpecification: 

6 def __init__(self, premium: float, 

7 premium_pay_dates: List[datetime], 

8 protection_start: datetime, 

9 notional: float = 1.0, 

10 expiry: datetime=None, 

11 recovery: float = None, 

12 issuer: str = '', cash_settled: bool = True): 

13 """Constructor for credit default swap 

14 

15 Args: 

16 premium (float): The premium as fraction of notional paid at each premium date. 

17 premium_pay_dates (List[datetime]): List of dates for premium payments. 

18 protection_start (datetime): Date when protection starts 

19 notional (foat): Notional 

20 expiry (datetime, optional): [description]. Defaults to None. 

21 recovery (float, optional): The protection is only paid for the real loss (notional minus recovery). If recovery is not specified, it is assumed that recovery as specified in contract. If no fixed recovery is specified[description]. Defaults to None. 

22 issuer (str, optional): [description]. Defaults to ''. 

23 cash_settled (bool, optional): Flag indicating o instrument is physical settled (the protection buyer ) 

24 

25 """ 

26 self.expiry = expiry 

27 self.premium = premium 

28 self.premium_pay_dates = premium_pay_dates 

29 self.protection_start = protection_start 

30 self.notional = notional 

31 if expiry is None: 

32 self.expiry = premium_pay_dates[-1] 

33 self.recovery = recovery 

34 self.issuer = issuer 

35 self.validate() 

36 

37 def validate(self): 

38 """Some simple validation 

39 """ 

40 if len(self.premium_pay_dates) == 0: 

41 raise Exception('Premium payment dates must not be empty.') 

42 

43 

44