import abc
from typing import List, Tuple, TYPE_CHECKING
from rivapy.instruments.components import Issuer
from rivapy.marketdata.fixing_table import FixingTable
from rivapy.tools.interfaces import FactoryObject
import datetime as dt
from dateutil.relativedelta import relativedelta
# import rivapy.tools.interfaces as interfaces
from rivapy.tools.enums import InterestRateIndex, Rating, SecuritizationLevel, Currency, DayCounterType, RollConvention, RollRule
from typing import List, Tuple, Optional as _Optional, Union as _Union
from rivapy.tools.datetools import Period, _date_to_datetime, _term_to_period, _string_to_calendar, DayCounter, Schedule, roll_day
from rivapy.tools.holidays_compat import HolidayBase as _HolidayBase, EuropeanCentralBank as _ECB
from rivapy.tools._validators import (
_check_positivity,
_check_start_before_end,
_check_start_at_or_before_end,
_string_to_calendar,
_check_non_negativity,
_is_ascending_date_list,
)
# if TYPE_CHECKING:
# from rivapy.marketdata.curves import DiscountCurve
from rivapy import _pyvacon_available
if _pyvacon_available:
import pyvacon.finance.specification as _spec
ComboSpecification = _spec.ComboSpecification
# Equity/FX
PayoffStructure = _spec.PayoffStructure
ExerciseSchedule = _spec.ExerciseSchedule
BarrierDefinition = _spec.BarrierDefinition
BarrierSchedule = _spec.BarrierSchedule
BarrierPayoff = _spec.BarrierPayoff
BarrierSpecification = _spec.BarrierSpecification
# EuropeanVanillaSpecification = _spec.EuropeanVanillaSpecification
# AmericanVanillaSpecification = _spec.AmericanVanillaSpecification
# RainbowUnderlyingSpec = _spec.RainbowUnderlyingSpec
# RainbowBarrierSpec = _spec.RainbowBarrierSpec
LocalVolMonteCarloSpecification = _spec.LocalVolMonteCarloSpecification
RainbowSpecification = _spec.RainbowSpecification
# MultiMemoryExpressSpecification = _spec.MultiMemoryExpressSpecification
# MemoryExpressSpecification = _spec.MemoryExpressSpecification
ExpressPlusSpecification = _spec.ExpressPlusSpecification
AsianVanillaSpecification = _spec.AsianVanillaSpecification
RiskControlStrategy = _spec.RiskControlStrategy
AsianRiskControlSpecification = _spec.AsianRiskControlSpecification
# Interest Rates
IrSwapLegSpecification = _spec.IrSwapLegSpecification
IrFixedLegSpecification = _spec.IrFixedLegSpecification
IrFloatLegSpecification = _spec.IrFloatLegSpecification
InterestRateSwapSpecification = _spec.InterestRateSwapSpecification
InterestRateBasisSwapSpecification = _spec.InterestRateBasisSwapSpecification
DepositSpecification = _spec.DepositSpecification
# 2025.06.30 HN test to run notebook discount_curves
# ForwardRateAgreementSpecification = _spec.ForwardRateAgreementSpecification
InterestRateFutureSpecification = _spec.InterestRateFutureSpecification
# 2025.06.30 HN test to run notebook discount_curves
# CapSpecification = _spec.CapSpecification
# 2025.06.30 HN test to run notebook discount_curves
# SwaptionSpecification = _spec.SwaptionSpecification
# 2025.06.30 HN test to run notebook discount_curves
# InflationLinkedBondSpecification = _spec.InflationLinkedBondSpecification
CallableBondSpecification = _spec.CallableBondSpecification
# GasStorageSpecification = _spec.GasStorageSpecification
# ScheduleSpecification = _spec.ScheduleSpecification
# SpecificationManager = _spec.SpecificationManager
# Bonds/Credit
CouponDescription = _spec.CouponDescription
BondSpecification = _spec.BondSpecification
else:
# empty placeholder...
class BondSpecification:
pass
[docs]
class ComboSpecification:
pass
[docs]
class BarrierSpecification:
pass
[docs]
class RainbowSpecification:
pass
[docs]
class MemoryExpressSpecification:
pass
[docs]
class EuropeanVanillaSpecification:
def __init__(
self,
id: str,
type: str,
expiry: dt,
strike: float,
issuer: str = "",
sec_lvl: str = SecuritizationLevel.COLLATERALIZED,
curr: str = Currency.EUR,
udl_id: str = "",
share_ratio: float = 1.0,
# holidays: str = '',
# ex_settle: int = 0, not implemented
# trade_settle: int = 0 not implemented
):
"""Constructor for european vanilla option
Args:
id (str): Identifier (name) of the european vanilla specification.
type (str): Type of the european vanilla option ('PUT','CALL').
expiry (dt): Expiration date.
strike (float): Strike price.
issuer (str, optional): Issuer Id. Must not be set if pricing data is manually defined. Defaults to ''.
sec_lvl (str, optional): Securitization level. Can be selected from rivapy.enums.SecuritizationLevel. Defaults to SecuritizationLevel.COLLATERALIZED.
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.
udl_id (str, optional): Underlying Id. Must not be set if pricing data is manually defined. Defaults to ''.
share_ratio (float, optional): Ratio of covered shares of the underlying by a single option contract. Defaults to 1.0.
"""
self.id = id
self.issuer = issuer
self.sec_lvl = sec_lvl
self.curr = curr
self.udl_id = udl_id
self.type = type
self.expiry = expiry
self.strike = strike
self.share_ratio = share_ratio
# self.holidays = holidays
# self.ex_settle = ex_settle
# self.trade_settle = trade_settle
self._pyvacon_obj = None
def _get_pyvacon_obj(self):
if self._pyvacon_obj is None:
self._pyvacon_obj = _spec.EuropeanVanillaSpecification(
self.id, self.issuer, self.sec_lvl, self.curr, self.udl_id, self.type, self.expiry, self.strike, self.share_ratio, "", 0, 0
)
return self._pyvacon_obj
[docs]
class AmericanVanillaSpecification:
def __init__(
self,
id: str,
type: str,
expiry: dt,
strike: float,
issuer: str = "",
sec_lvl: str = SecuritizationLevel.COLLATERALIZED,
curr: str = Currency.EUR,
udl_id: str = "",
share_ratio: float = 1.0,
exercise_before_ex_date: bool = False,
# ,holidays: str
# ,ex_settle: str
# ,trade_settle: str
):
"""Constructor for american vanilla option
Args:
id (str): Identifier (name) of the american vanilla specification.
type (str): Type of the american vanilla option ('PUT','CALL').
expiry (dt): Expiration date.
strike (float): Strike price.
issuer (str, optional): Issuer Id. Must not be set if pricing data is manually defined. Defaults to ''.
sec_lvl (str, optional): Securitization level. Can be selected from rivapy.enums.SecuritizationLevel. Defaults to SecuritizationLevel.COLLATERALIZED.
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.
udl_id (str, optional): Underlying Id. Must not be set if pricing data is manually defined. Defaults to ''.
share_ratio (float, optional): Ratio of covered shares of the underlying by a single option contract. Defaults to 1.0.
exercise_before_ex_date (bool, optional): Indicates if option can be exercised within two days before dividend ex-date. Defaults to False.
"""
self.id = id
self.type = type
self.expiry = expiry
self.strike = strike
self.issuer = issuer
self.sec_lvl = sec_lvl
self.curr = curr
self.udl_id = udl_id
self.share_ratio = share_ratio
self.exercise_before_ex_date = exercise_before_ex_date
# self.holidays = holidays
# self.ex_settle = ex_settle
# self.trade_settle = trade_settle
self._pyvacon_obj = None
def _get_pyvacon_obj(self):
if self._pyvacon_obj is None:
self._pyvacon_obj = _spec.AmericanVanillaSpecification(
self.id,
self.issuer,
self.sec_lvl,
self.curr,
self.udl_id,
self.type,
self.expiry,
self.strike,
self.share_ratio,
self.exercise_before_ex_date,
"",
0,
0,
)
return self._pyvacon_obj