Coverage for rivapy / instruments / specifications.py: 37%

81 statements  

« prev     ^ index     » next       coverage.py v7.12.0, created at 2025-11-27 14:36 +0000

1import abc 

2from typing import List, Tuple, TYPE_CHECKING 

3from rivapy.instruments.components import Issuer 

4from rivapy.marketdata.fixing_table import FixingTable 

5from rivapy.tools.interfaces import FactoryObject 

6import datetime as dt 

7from dateutil.relativedelta import relativedelta 

8 

9# import rivapy.tools.interfaces as interfaces 

10from rivapy.tools.enums import InterestRateIndex, Rating, SecuritizationLevel, Currency, DayCounterType, RollConvention, RollRule 

11from typing import List, Tuple, Optional as _Optional, Union as _Union 

12from rivapy.tools.datetools import Period, _date_to_datetime, _term_to_period, _string_to_calendar, DayCounter, Schedule, roll_day 

13from rivapy.tools.holidays_compat import HolidayBase as _HolidayBase, EuropeanCentralBank as _ECB 

14from rivapy.tools._validators import ( 

15 _check_positivity, 

16 _check_start_before_end, 

17 _check_start_at_or_before_end, 

18 _string_to_calendar, 

19 _check_non_negativity, 

20 _is_ascending_date_list, 

21) 

22 

23# if TYPE_CHECKING: 

24# from rivapy.marketdata.curves import DiscountCurve 

25 

26from rivapy import _pyvacon_available 

27 

28if _pyvacon_available: 

29 import pyvacon.finance.specification as _spec 

30 

31 ComboSpecification = _spec.ComboSpecification 

32 # Equity/FX 

33 PayoffStructure = _spec.PayoffStructure 

34 ExerciseSchedule = _spec.ExerciseSchedule 

35 BarrierDefinition = _spec.BarrierDefinition 

36 BarrierSchedule = _spec.BarrierSchedule 

37 BarrierPayoff = _spec.BarrierPayoff 

38 BarrierSpecification = _spec.BarrierSpecification 

39 # EuropeanVanillaSpecification = _spec.EuropeanVanillaSpecification 

40 # AmericanVanillaSpecification = _spec.AmericanVanillaSpecification 

41 # RainbowUnderlyingSpec = _spec.RainbowUnderlyingSpec 

42 # RainbowBarrierSpec = _spec.RainbowBarrierSpec 

43 LocalVolMonteCarloSpecification = _spec.LocalVolMonteCarloSpecification 

44 RainbowSpecification = _spec.RainbowSpecification 

45 # MultiMemoryExpressSpecification = _spec.MultiMemoryExpressSpecification 

46 # MemoryExpressSpecification = _spec.MemoryExpressSpecification 

47 ExpressPlusSpecification = _spec.ExpressPlusSpecification 

48 AsianVanillaSpecification = _spec.AsianVanillaSpecification 

49 RiskControlStrategy = _spec.RiskControlStrategy 

50 AsianRiskControlSpecification = _spec.AsianRiskControlSpecification 

51 

52 # Interest Rates 

53 IrSwapLegSpecification = _spec.IrSwapLegSpecification 

54 IrFixedLegSpecification = _spec.IrFixedLegSpecification 

55 IrFloatLegSpecification = _spec.IrFloatLegSpecification 

56 InterestRateSwapSpecification = _spec.InterestRateSwapSpecification 

57 InterestRateBasisSwapSpecification = _spec.InterestRateBasisSwapSpecification 

58 DepositSpecification = _spec.DepositSpecification 

59 # 2025.06.30 HN test to run notebook discount_curves 

60 # ForwardRateAgreementSpecification = _spec.ForwardRateAgreementSpecification 

61 InterestRateFutureSpecification = _spec.InterestRateFutureSpecification 

62 # 2025.06.30 HN test to run notebook discount_curves 

63 # CapSpecification = _spec.CapSpecification 

64 # 2025.06.30 HN test to run notebook discount_curves 

65 # SwaptionSpecification = _spec.SwaptionSpecification 

66 

67 # 2025.06.30 HN test to run notebook discount_curves 

68 # InflationLinkedBondSpecification = _spec.InflationLinkedBondSpecification 

69 CallableBondSpecification = _spec.CallableBondSpecification 

70 

71 # GasStorageSpecification = _spec.GasStorageSpecification 

72 

73 # ScheduleSpecification = _spec.ScheduleSpecification 

74 

75 # SpecificationManager = _spec.SpecificationManager 

76 

77 # Bonds/Credit 

78 CouponDescription = _spec.CouponDescription 

79 BondSpecification = _spec.BondSpecification 

80else: 

81 # empty placeholder... 

82 class BondSpecification: 

83 pass 

84 

85 class ComboSpecification: 

86 pass 

87 

88 class BarrierSpecification: 

89 pass 

90 

91 class RainbowSpecification: 

92 pass 

93 

94 class MemoryExpressSpecification: 

95 pass 

96 

97 

98class EuropeanVanillaSpecification: 

99 def __init__( 

100 self, 

101 id: str, 

102 type: str, 

103 expiry: dt, 

104 strike: float, 

105 issuer: str = "", 

106 sec_lvl: str = SecuritizationLevel.COLLATERALIZED, 

107 curr: str = Currency.EUR, 

108 udl_id: str = "", 

109 share_ratio: float = 1.0, 

110 # holidays: str = '', 

111 # ex_settle: int = 0, not implemented 

112 # trade_settle: int = 0 not implemented 

113 ): 

114 """Constructor for european vanilla option 

115 

116 Args: 

117 id (str): Identifier (name) of the european vanilla specification. 

118 type (str): Type of the european vanilla option ('PUT','CALL'). 

119 expiry (dt): Expiration date. 

120 strike (float): Strike price. 

121 issuer (str, optional): Issuer Id. Must not be set if pricing data is manually defined. Defaults to ''. 

122 sec_lvl (str, optional): Securitization level. Can be selected from rivapy.enums.SecuritizationLevel. Defaults to SecuritizationLevel.COLLATERALIZED. 

123 curr (str, optional): Currency (ISO-4217 Code). Must not be set if pricing data is manually defined. Can be selected from rivapy.enums.Currency. Defaults to Currency.EUR. 

124 udl_id (str, optional): Underlying Id. Must not be set if pricing data is manually defined. Defaults to ''. 

125 share_ratio (float, optional): Ratio of covered shares of the underlying by a single option contract. Defaults to 1.0. 

126 """ 

127 

128 self.id = id 

129 self.issuer = issuer 

130 self.sec_lvl = sec_lvl 

131 self.curr = curr 

132 self.udl_id = udl_id 

133 self.type = type 

134 self.expiry = expiry 

135 self.strike = strike 

136 self.share_ratio = share_ratio 

137 # self.holidays = holidays 

138 # self.ex_settle = ex_settle 

139 # self.trade_settle = trade_settle 

140 

141 self._pyvacon_obj = None 

142 

143 def _get_pyvacon_obj(self): 

144 if self._pyvacon_obj is None: 

145 self._pyvacon_obj = _spec.EuropeanVanillaSpecification( 

146 self.id, self.issuer, self.sec_lvl, self.curr, self.udl_id, self.type, self.expiry, self.strike, self.share_ratio, "", 0, 0 

147 ) 

148 

149 return self._pyvacon_obj 

150 

151 

152class AmericanVanillaSpecification: 

153 def __init__( 

154 self, 

155 id: str, 

156 type: str, 

157 expiry: dt, 

158 strike: float, 

159 issuer: str = "", 

160 sec_lvl: str = SecuritizationLevel.COLLATERALIZED, 

161 curr: str = Currency.EUR, 

162 udl_id: str = "", 

163 share_ratio: float = 1.0, 

164 exercise_before_ex_date: bool = False, 

165 # ,holidays: str 

166 # ,ex_settle: str 

167 # ,trade_settle: str 

168 ): 

169 """Constructor for american vanilla option 

170 

171 Args: 

172 id (str): Identifier (name) of the american vanilla specification. 

173 type (str): Type of the american vanilla option ('PUT','CALL'). 

174 expiry (dt): Expiration date. 

175 strike (float): Strike price. 

176 issuer (str, optional): Issuer Id. Must not be set if pricing data is manually defined. Defaults to ''. 

177 sec_lvl (str, optional): Securitization level. Can be selected from rivapy.enums.SecuritizationLevel. Defaults to SecuritizationLevel.COLLATERALIZED. 

178 curr (str, optional): Currency (ISO-4217 Code). Must not be set if pricing data is manually defined. Can be selected from rivapy.enums.Currency. Defaults to Currency.EUR. 

179 udl_id (str, optional): Underlying Id. Must not be set if pricing data is manually defined. Defaults to ''. 

180 share_ratio (float, optional): Ratio of covered shares of the underlying by a single option contract. Defaults to 1.0. 

181 exercise_before_ex_date (bool, optional): Indicates if option can be exercised within two days before dividend ex-date. Defaults to False. 

182 """ 

183 

184 self.id = id 

185 self.type = type 

186 self.expiry = expiry 

187 self.strike = strike 

188 self.issuer = issuer 

189 self.sec_lvl = sec_lvl 

190 self.curr = curr 

191 self.udl_id = udl_id 

192 self.share_ratio = share_ratio 

193 self.exercise_before_ex_date = exercise_before_ex_date 

194 # self.holidays = holidays 

195 # self.ex_settle = ex_settle 

196 # self.trade_settle = trade_settle 

197 

198 self._pyvacon_obj = None 

199 

200 def _get_pyvacon_obj(self): 

201 if self._pyvacon_obj is None: 

202 self._pyvacon_obj = _spec.AmericanVanillaSpecification( 

203 self.id, 

204 self.issuer, 

205 self.sec_lvl, 

206 self.curr, 

207 self.udl_id, 

208 self.type, 

209 self.expiry, 

210 self.strike, 

211 self.share_ratio, 

212 self.exercise_before_ex_date, 

213 "", 

214 0, 

215 0, 

216 ) 

217 

218 return self._pyvacon_obj