def __init__(self, timeseries, *args, **kwargs): super().__init__(timeseries) self.base_currency = to_ql_currency(self.ts_attributes[BASE_CURRENCY]) self.counter_currency = to_ql_currency( self.ts_attributes[COUNTER_CURRENCY]) self.maturity_date = to_ql_date(self.ts_attributes[MATURITY_DATE]) self.quotes = self.timeseries.price.ts_values self.calendar = to_ql_calendar(self.ts_attributes[CALENDAR]) self.base_rate_day_counter = to_ql_day_counter( self.ts_attributes[BASE_RATE_DAY_COUNTER]) self.counter_rate_day_counter = to_ql_day_counter( self.ts_attributes[COUNTER_RATE_DAY_COUNTER]) self.base_rate_compounding = to_ql_compounding( self.ts_attributes[BASE_RATE_COMPOUNDING]) self.counter_rate_compounding = to_ql_compounding( self.ts_attributes[COUNTER_RATE_COMPOUNDING]) self.base_rate_frequency = to_ql_frequency( self.ts_attributes[BASE_RATE_FREQUENCY]) self.counter_rate_frequency = to_ql_frequency( self.ts_attributes[COUNTER_RATE_FREQUENCY]) self.settlement_days = int(self.ts_attributes[SETTLEMENT_DAYS]) self.base_currency_future = BaseCurrencyFuture( self.base_currency, self.counter_currency, self.maturity_date, self.calendar, self.base_rate_day_counter, self.base_rate_compounding, self.base_rate_frequency, self.counter_rate_day_counter, self.counter_rate_compounding, self.counter_rate_frequency, self.settlement_days)
def __init__(self, timeseries): super().__init__(timeseries) self._maturity = None # Swap Database Attributes self._index_tenor = ql.PeriodParser.parse( self.ts_attributes[INDEX_TENOR]) self.fixed_business_convention = to_ql_business_convention( self.ts_attributes[BUSINESS_CONVENTION]) self.settlement_days = int(self.ts_attributes[SETTLEMENT_DAYS]) self.fixed_calendar = to_ql_calendar(self.ts_attributes[CALENDAR]) self.fixed_leg_tenor = ql.PeriodParser.parse( self.ts_attributes[FIXED_LEG_TENOR]) self.fixed_leg_day_counter = to_ql_day_counter( self.ts_attributes[DAY_COUNTER]) # QuantLib Objects self.index = to_ql_rate_index(self.ts_attributes[INDEX], self._index_tenor, self.term_structure) # QuantLib Attributes self.calendar = ql.JointCalendar(self.fixed_calendar, self.index.fixingCalendar()) self.day_counter = self.index.dayCounter() self.business_convention = self.index.businessDayConvention() self.fixing_days = self.index.fixingDays() self.month_end = self.index.endOfMonth() # Swap Index self.swap_index = ql.SwapIndex(self.ts_name, self._tenor, self.settlement_days, self.currency, self.calendar, self.fixed_leg_tenor, self.fixed_business_convention, self.fixed_leg_day_counter, self.index) # Rate Helper self.helper_rate = ql.SimpleQuote(0) self.helper_convexity = ql.SimpleQuote(0)
def __init__(self, timeseries): super().__init__(timeseries=timeseries) self.option_type = self.ts_attributes[OPTION_TYPE] self.strike = float(self.ts_attributes[STRIKE_PRICE]) self.contract_size = float(self.ts_attributes[CONTRACT_SIZE]) self._maturity = to_ql_date(to_datetime(self.ts_attributes[MATURITY_DATE])) self.calendar = to_ql_calendar(self.ts_attributes[CALENDAR]) self.day_counter = to_ql_day_counter(self.ts_attributes[DAY_COUNTER]) self.exercise_type = self.ts_attributes[EXERCISE_TYPE] self.underlying_name = self.ts_attributes[UNDERLYING_INSTRUMENT] try: self.earliest_date = to_ql_date(self.ts_attributes[EARLIEST_DATE]) except KeyError: self.earliest_date = ql.Date.minDate() self.exercise = to_ql_option_exercise_type(self.exercise_type, self.earliest_date, self._maturity) self.payoff = to_ql_option_payoff(self.ts_attributes[PAYOFF_TYPE], to_ql_option_type(self.option_type), self.strike) self.option = to_ql_one_asset_option(self.payoff, self.exercise) self.risk_free_yield_curve_ts = None self.underlying_instrument = None # engine setup self.engine_name = 'FINITE_DIFFERENCES' self.base_equity_process = None self._implied_volatility = dict() self._implied_volatility_prices = dict()
def __init__(self, start_date, end_date, tenor, calendar, day_counter): self.start_date = to_ql_date(start_date) self.end_date = to_ql_date(end_date) self.tenor = ql.PeriodParser.parse(tenor) self.calendar = to_ql_calendar(calendar) self.day_counter = to_ql_day_counter(day_counter) self.schedule = ql.Schedule(self.start_date, self.end_date, self.tenor, self.calendar, ql.Unadjusted, ql.Unadjusted, ql.DateGeneration.Forward, False)
def __init__(self, timeseries, is_deposit_rate=True): super().__init__(timeseries, is_deposit_rate=is_deposit_rate) self._tenor = ql.PeriodParser.parse(self.ts_attributes[TENOR_PERIOD]) self.calendar = to_ql_calendar(self.ts_attributes[CALENDAR]) self.day_counter = to_ql_day_counter(self.ts_attributes[DAY_COUNTER]) self.business_convention = to_ql_business_convention( self.ts_attributes[BUSINESS_CONVENTION]) self.fixing_days = int(self.ts_attributes[FIXING_DAYS]) self.month_end = False # Rate Helper self.helper_rate = ql.SimpleQuote(0)
def __init__(self, timeseries, telescopic_value_dates=True): super().__init__(timeseries, telescopic_value_dates=telescopic_value_dates) self.calendar = to_ql_calendar(self.ts_attributes[CALENDAR]) self.day_counter = to_ql_day_counter(self.ts_attributes[DAY_COUNTER]) self.business_convention = to_ql_business_convention(self.ts_attributes[BUSINESS_CONVENTION]) self._maturity = to_ql_date(self.ts_attributes[MATURITY_DATE]) self.fixing_days = int(self.ts_attributes[FIXING_DAYS]) self.month_end = False self.index = to_ql_ibor_index(index=self.ts_attributes[SPREAD_TAG], fixing_days=self.fixing_days, currency=self.currency, calendar=self.calendar, day_counter=self.day_counter, overnight_index=True) # Rate Helper self.helper_rate = ql.SimpleQuote(0)
def __init__(self, timeseries, ql_process): super().__init__(timeseries) self.opt_type = self.ts_attributes[OPTION_TYPE] self.strike = self.ts_attributes[STRIKE_PRICE] self.contract_size = self.ts_attributes[OPTION_CONTRACT_SIZE] self.option_maturity = to_ql_date(to_datetime(self.ts_attributes[MATURITY_DATE])) self.payoff = ql_option_payoff(to_ql_option_type(self.opt_type), self.strike) self.calendar = to_ql_calendar(self.ts_attributes[CALENDAR]) self.day_counter = to_ql_day_counter(self.ts_attributes[DAY_COUNTER]) self.exercise_type = self.ts_attributes[EXERCISE_TYPE] self.underlying_instrument = self.ts_attributes[UNDERLYING_INSTRUMENT] self.ql_process = ql_process self.option = None
def __init__(self, timeseries, first_cc): super().__init__(timeseries) self.first_cc = first_cc self.calendar = to_ql_calendar(self.attributes[CALENDAR]) try: self._tenor = ql.PeriodParser.parse(self.attributes[TENOR_PERIOD]) except KeyError: # If the deposit rate has no tenor, it must have a maturity. self._maturity = to_ql_date(to_datetime(self.attributes[MATURITY_DATE])) self.day_counter = to_ql_day_counter(self.attributes[DAY_COUNTER]) self.compounding = to_ql_compounding(self.attributes[COMPOUNDING]) self.frequency = to_ql_frequency(self.attributes[FREQUENCY]) self.business_convention = to_ql_business_convention(self.attributes[BUSINESS_CONVENTION]) self.fixing_days = int(self.attributes[FIXING_DAYS])
def update_spread_from_timeseries(self, date, last_available=True): date = to_ql_date(date) self.spreads[date] = dict() for ts in self.ts_collection: spread = ts.get_values(date, last_available=last_available) calendar = to_ql_calendar(ts.ts_attributes[CALENDAR]) try: spread_date_or_tenor = calendar.advance( date, ql.PeriodParser.parse(ts.ts_attributes[TENOR_PERIOD])) except AttributeError: spread_date_or_tenor = calendar.adjust( to_ql_date(ts.ts_attributes[MATURITY_DATE])) day_counter = to_ql_day_counter(ts.ts_attributes[DAY_COUNTER]) compounding = to_ql_compounding(ts.ts_attributes[COMPOUNDING]) frequency = to_ql_frequency(ts.ts_attributes[FREQUENCY]) self.spreads[date][spread_date_or_tenor] = ql.InterestRate( spread, day_counter, compounding, frequency)
def __init__(self, timeseries, currency_ts): super().__init__(timeseries) self._maturity = None # Swap Database Attributes self.currency_ts = currency_ts self._tenor = ql.PeriodParser.parse(self.ts_attributes[TENOR_PERIOD]) self.calendar = to_ql_calendar(self.ts_attributes[CALENDAR]) self.day_counter = to_ql_day_counter(self.ts_attributes[DAY_COUNTER]) self.business_convention = to_ql_business_convention( self.ts_attributes[BUSINESS_CONVENTION]) self.fixing_days = int(self.ts_attributes[FIXING_DAYS]) self.base_currency = self.ts_attributes[BASE_CURRENCY] self.base_calendar = to_ql_calendar(self.ts_attributes[BASE_CALENDAR]) self.country = self.ts_attributes[COUNTRY] self.month_end = False # Rate Helper self.currency_spot_rate = ql.SimpleQuote(1) self.currency_spot_handle = ql.RelinkableQuoteHandle( self.currency_spot_rate) self.helper_rate = ql.SimpleQuote(0) self.helper_spread = ql.SimpleQuote(0) self.helper_convexity = ql.SimpleQuote(0)
def __init__(self, timeseries): super().__init__(timeseries) self._tenor = ql.PeriodParser.parse(self.ts_attributes[TENOR_PERIOD]) self.calendar = to_ql_calendar(self.ts_attributes[CALENDAR]) self.day_counter = to_ql_day_counter(self.ts_attributes[DAY_COUNTER]) self.business_convention = to_ql_business_convention( self.ts_attributes[BUSINESS_CONVENTION]) self.fixing_days = int(self.ts_attributes[FIXING_DAYS]) self.date_generation = to_ql_date_generation( self.ts_attributes[DATE_GENERATION]) self.coupon_frequency = ql.Period( to_ql_frequency(self.ts_attributes[FREQUENCY])) self.recovery_rate = float(self.ts_attributes[RECOVERY_RATE]) self.coupon = float(self.ts_attributes[COUPONS]) self.base_yield = self.ts_attributes[BASE_SPREAD_TAG] try: self.first_accrual_date = to_ql_date( self.ts_attributes[FIRST_ACCRUAL_DATE]) except KeyError: self.first_accrual_date = None self.month_end = False # Rate Helper self.helper_rate = ql.SimpleQuote(0)