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

72 statements  

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

1 

2from datetime import datetime 

3from rivapy.tools.enums import SecuritizationLevel, Currency 

4#from rivapy.enums import Currency 

5from rivapy import _pyvacon_available 

6if _pyvacon_available: 

7 import pyvacon.finance.specification as _spec 

8 

9 ComboSpecification = _spec.ComboSpecification 

10 #Equity/FX 

11 PayoffStructure = _spec.PayoffStructure 

12 ExerciseSchedule = _spec.ExerciseSchedule 

13 BarrierDefinition = _spec.BarrierDefinition 

14 BarrierSchedule = _spec.BarrierSchedule 

15 BarrierPayoff = _spec.BarrierPayoff 

16 BarrierSpecification = _spec.BarrierSpecification 

17 # EuropeanVanillaSpecification = _spec.EuropeanVanillaSpecification 

18 # AmericanVanillaSpecification = _spec.AmericanVanillaSpecification 

19 #RainbowUnderlyingSpec = _spec.RainbowUnderlyingSpec 

20 #RainbowBarrierSpec = _spec.RainbowBarrierSpec 

21 LocalVolMonteCarloSpecification = _spec.LocalVolMonteCarloSpecification 

22 RainbowSpecification = _spec.RainbowSpecification 

23 #MultiMemoryExpressSpecification = _spec.MultiMemoryExpressSpecification 

24 #MemoryExpressSpecification = _spec.MemoryExpressSpecification 

25 ExpressPlusSpecification = _spec.ExpressPlusSpecification 

26 AsianVanillaSpecification = _spec.AsianVanillaSpecification 

27 RiskControlStrategy = _spec.RiskControlStrategy 

28 AsianRiskControlSpecification = _spec.AsianRiskControlSpecification 

29 

30 

31 #Interest Rates 

32 IrSwapLegSpecification = _spec.IrSwapLegSpecification 

33 IrFixedLegSpecification = _spec.IrFixedLegSpecification 

34 IrFloatLegSpecification = _spec.IrFloatLegSpecification 

35 InterestRateSwapSpecification = _spec.InterestRateSwapSpecification 

36 InterestRateBasisSwapSpecification = _spec.InterestRateBasisSwapSpecification 

37 DepositSpecification = _spec.DepositSpecification 

38 InterestRateFutureSpecification = _spec.InterestRateFutureSpecification 

39 

40 InflationLinkedBondSpecification = _spec.InflationLinkedBondSpecification 

41 CallableBondSpecification = _spec.CallableBondSpecification 

42 

43 #GasStorageSpecification = _spec.GasStorageSpecification 

44 

45 #ScheduleSpecification = _spec.ScheduleSpecification 

46 

47 #SpecificationManager = _spec.SpecificationManager 

48 

49 #Bonds/Credit 

50 CouponDescription = _spec.CouponDescription 

51 BondSpecification = _spec.BondSpecification 

52else: 

53 #empty placeholder... 

54 class BondSpecification: 

55 pass 

56 class ComboSpecification: 

57 pass 

58 class BarrierSpecification: 

59 pass 

60 class RainbowSpecification: 

61 pass 

62 class MemoryExpressSpecification: 

63 pass 

64 

65class EuropeanVanillaSpecification: 

66 def __init__(self, 

67 id: str, 

68 type: str, 

69 expiry: datetime, 

70 strike: float, 

71 issuer: str = '', 

72 sec_lvl: str = SecuritizationLevel.COLLATERALIZED, 

73 curr: str = Currency.EUR, 

74 udl_id: str = '', 

75 share_ratio: float = 1.0, 

76 # holidays: str = '', 

77 # ex_settle: int = 0, not implemented 

78 # trade_settle: int = 0 not implemented 

79 ): 

80 

81 """Constructor for european vanilla option 

82 

83 Args: 

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

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

86 expiry (datetime): Expiration date. 

87 strike (float): Strike price. 

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

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

90 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. 

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

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

93 """ 

94 

95 self.id = id 

96 self.issuer = issuer 

97 self.sec_lvl = sec_lvl 

98 self.curr = curr 

99 self.udl_id = udl_id 

100 self.type = type 

101 self.expiry = expiry 

102 self.strike = strike 

103 self.share_ratio = share_ratio 

104 # self.holidays = holidays 

105 # self.ex_settle = ex_settle 

106 # self.trade_settle = trade_settle 

107 

108 self._pyvacon_obj = None 

109 

110 def _get_pyvacon_obj(self): 

111 if self._pyvacon_obj is None: 

112 self._pyvacon_obj = _spec.EuropeanVanillaSpecification(self.id, 

113 self.issuer, 

114 self.sec_lvl, 

115 self.curr, 

116 self.udl_id, 

117 self.type, 

118 self.expiry, 

119 self.strike, 

120 self.share_ratio, 

121 '', 

122 0, 

123 0) 

124 

125 return self._pyvacon_obj 

126 

127class AmericanVanillaSpecification: 

128 def __init__(self 

129 ,id: str 

130 ,type: str 

131 ,expiry: datetime 

132 ,strike: float 

133 ,issuer: str = '' 

134 ,sec_lvl: str = SecuritizationLevel.COLLATERALIZED 

135 ,curr: str = Currency.EUR 

136 ,udl_id: str = '' 

137 ,share_ratio: float = 1.0 

138 ,exercise_before_ex_date: bool = False 

139 # ,holidays: str 

140 # ,ex_settle: str 

141 # ,trade_settle: str 

142 ): 

143 """Constructor for american vanilla option 

144 

145 Args: 

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

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

148 expiry (datetime): Expiration date. 

149 strike (float): Strike price. 

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

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

152 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. 

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

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

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

156 """ 

157 

158 self.id = id 

159 self.type = type 

160 self.expiry = expiry 

161 self.strike = strike 

162 self.issuer = issuer 

163 self.sec_lvl = sec_lvl 

164 self.curr = curr 

165 self.udl_id = udl_id 

166 self.share_ratio = share_ratio 

167 self.exercise_before_ex_date = exercise_before_ex_date 

168 # self.holidays = holidays 

169 # self.ex_settle = ex_settle 

170 # self.trade_settle = trade_settle 

171 

172 self._pyvacon_obj = None 

173 

174 def _get_pyvacon_obj(self): 

175 if self._pyvacon_obj is None: 

176 self._pyvacon_obj = _spec.AmericanVanillaSpecification(self.id 

177 ,self.issuer 

178 ,self.sec_lvl 

179 ,self.curr 

180 ,self.udl_id 

181 ,self.type 

182 ,self.expiry 

183 ,self.strike 

184 ,self.share_ratio 

185 ,self.exercise_before_ex_date 

186 ,'' 

187 ,0 

188 ,0) 

189 

190 return self._pyvacon_obj 

191 

192