def test_create_swap_rate_helper_from_index(self): calendar = UnitedStates() settlement_days = 2 currency = USDCurrency() fixed_leg_tenor = Period(12, Months) fixed_leg_convention = ModifiedFollowing fixed_leg_daycounter = Actual360() family_name = currency.name + 'index' ibor_index = Libor( "USDLibor", Period(3,Months), settlement_days, USDCurrency(), UnitedStates(), Actual360() ) rate = SimpleQuote(0.005681) tenor = Period(1, Years) index = SwapIndex ( family_name, tenor, settlement_days, currency, calendar, fixed_leg_tenor, fixed_leg_convention, fixed_leg_daycounter, ibor_index) helper_from_quote = SwapRateHelper.from_index(rate, index) helper_from_float = SwapRateHelper.from_index(0.005681, index) #self.fail( # 'Make this pass: create and ask for the .quote property' # ' Test the from_index and from_tenor methods' #) self.assertIsNotNone(helper_from_quote, helper_from_float) self.assertAlmostEqual(rate.value, helper_from_quote.quote.value) self.assertAlmostEqual(helper_from_float.quote.value, helper_from_quote.quote.value) with self.assertRaises(RuntimeError): self.assertAlmostEqual(rate.value, helper_from_quote.implied_quote)
def test_create_libor_index(self): settings = Settings.instance() # Market information calendar = UnitedStates(LiborImpact) # must be a business day eval_date = calendar.adjust(today()) settings.evaluation_date = eval_date settlement_days = 2 settlement_date = calendar.advance(eval_date, settlement_days, Days) # must be a business day settlement_date = calendar.adjust(settlement_date) term_structure = YieldTermStructure(relinkable=True) term_structure.link_to(FlatForward(settlement_date, 0.05, Actual365Fixed())) index = Libor('USDLibor', Period(6, Months), settlement_days, USDCurrency(), calendar, Actual360(), term_structure) default_libor = USDLibor(Period(6, Months)) for attribute in ["business_day_convention", "end_of_month", "fixing_calendar", "joint_calendar", "tenor", "fixing_days", "day_counter", "family_name", "name"]: self.assertEqual(getattr(index, attribute), getattr(default_libor, attribute))
def setUp(self): atm_option_tenors = [Period(1, Months), Period(6, Months)] + \ [Period(i, Years) for i in [1, 5, 10, 30]] atm_swap_tenors = [Period(1, Years), Period(5, Years), Period(10, Years), Period(30, Years)] m = np.array([[.1300, .1560, .1390, .1220], [.1440, .1580, .1460, .1260], [.1600, .1590, .1470, .1290], [.1640, .1470, .1370, .1220], [.1400, .1300, .1250, .1100], [.1130, .1090, .1070, .0930]]) M = Matrix.from_ndarray(m) calendar = UnitedStates() self.atm_vol = SwaptionVolatilityMatrix(calendar, Following, atm_option_tenors, atm_swap_tenors, M, Actual365Fixed()) reference_date = calendar.adjust(today()) Settings().evaluation_date = reference_date self.term_structure = FlatForward(reference_date, 0.05, Actual365Fixed()) self.swap_index = EuriborSwapIsdaFixA(Period(10, Years), forwarding=self.term_structure)
def test_create_swap_rate_helper_from_tenor(self): calendar = UnitedStates() settlement_days = 2 rate = SimpleQuote(0.005681) ibor_index = Libor("USDLibor", Period(3, Months), settlement_days, USDCurrency(), UnitedStates(), Actual360()) helper_from_quote = SwapRateHelper.from_tenor(rate, Period(12, Months), calendar, Annual, ModifiedFollowing, Actual360(), ibor_index) helper_from_float = SwapRateHelper.from_tenor(0.005681, Period(12, Months), calendar, Annual, ModifiedFollowing, Actual360(), ibor_index) self.assertIsNotNone(helper_from_float, helper_from_quote) self.assertEqual(rate.value, helper_from_quote.quote.value) self.assertEqual(helper_from_quote.quote.value, helper_from_float.quote.value) with self.assertRaises(RuntimeError): self.assertAlmostEqual(rate.value, helper_from_quote.implied_quote)
def test_create_libor_index(self): settings = Settings.instance() # Market information calendar = UnitedStates(LiborImpact) # must be a business day eval_date = calendar.adjust(today()) settings.evaluation_date = eval_date settlement_days = 2 settlement_date = calendar.advance(eval_date, settlement_days, Days) # must be a business day settlement_date = calendar.adjust(settlement_date) term_structure = YieldTermStructure(relinkable=True) term_structure.link_to( FlatForward(settlement_date, 0.05, Actual365Fixed())) index = Libor('USDLibor', Period(6, Months), settlement_days, USDCurrency(), calendar, Actual360(), term_structure) default_libor = USDLibor(Period(6, Months)) for attribute in [ "business_day_convention", "end_of_month", "fixing_calendar", "joint_calendar", "tenor", "fixing_days", "day_counter", "family_name", "name" ]: self.assertEqual(getattr(index, attribute), getattr(default_libor, attribute))
def testFxMarketConventionsForCrossRate(self): """ Testing if FxSwapRateHelper obeys the fx spot market conventions for cross rates. """ today = Date(1, 7, 2016) spot_date = Date(5, 7, 2016) self.build_curves(today) us_calendar = UnitedStates() joint_calendar = JointCalendar(TARGET(), Poland()) settlement_calendar = JointCalendar(joint_calendar, us_calendar) # Settlement should be on a day where all three centers are operating # and follow EndOfMonth rule maturities = [ settlement_calendar.advance(spot_date, n, unit, convention=ModifiedFollowing, end_of_month=True) for n, unit in self.fx_swap_quotes ] for m, helper in zip(maturities, self.eur_pln_fx_swap_helpers): self.assertEqual(m, helper.latest_date)
def bootstrap_term_structure(self, interpolator=LogLinear): tolerance = 1.0e-15 settings = Settings() calendar = JointCalendar(UnitedStates(), UnitedKingdom()) # must be a business day eval_date = self._eval_date settings.evaluation_date = eval_date settlement_days = self._params.settlement_days settlement_date = calendar.advance(eval_date, settlement_days, Days) # must be a business day settlement_date = calendar.adjust(settlement_date) ts = PiecewiseYieldCurve[BootstrapTrait.Discount, interpolator].from_reference_date( settlement_date, self._rate_helpers, DayCounter.from_name( self._termstructure_daycount), accuracy=tolerance) self._term_structure = ts self._discount_term_structure = YieldTermStructure() self._discount_term_structure.link_to(ts) self._forecast_term_structure = YieldTermStructure() self._forecast_term_structure.link_to(ts) return ts
def setUp(self): Settings().evaluation_date = Date(27, 4, 2018) self.yc = FlatForward(forward=0.03, settlement_days=2, daycounter=Actual365Fixed(), calendar=UnitedStates()) self.index = UsdLiborSwapIsdaFixAm(Period(10, Years), self.yc) self.factory = (MakeSwaption(self.index, Period(2, Years), strike=0.0206). with_underlying_type(Receiver). with_settlement_type(Cash). with_settlement_method(ParYieldCurve))
def test_create_swap_index(self): term_structure = YieldTermStructure() term_structure.link_to( FlatForward(forward=0.05, daycounter=Actual365Fixed(), settlement_days=2, calendar=UnitedStates())) ibor_index = USDLibor(Period(3, Months), term_structure) index = SwapIndex('UsdLiborSwapIsdaFixAm', Period(10, Years), 2, USDCurrency(), UnitedStates(GovernmentBond), Period(6, Months), ModifiedFollowing, Thirty360(), ibor_index) index2 = UsdLiborSwapIsdaFixAm(Period(10, Years), term_structure) for attr in [ 'name', 'family_name', 'fixing_calendar', 'tenor', 'day_counter', 'currency' ]: self.assertEqual(getattr(index, attr), getattr(index2, attr))
def _set_evaluation_date(self, dt_obs): if not isinstance(dt_obs, Date): dt_obs = pydate_to_qldate(dt_obs) settings = Settings() calendar = JointCalendar(UnitedStates(), UnitedKingdom()) # must be a business day eval_date = calendar.adjust(dt_obs) settings.evaluation_date = eval_date self._eval_date = eval_date return eval_date
def test_create_swap_rate_helper_from_index(self): from quantlib.currency import USDCurrency from quantlib.indexes.swap_index import SwapIndex from quantlib.indexes.libor import Libor from quantlib.time.api import Years, UnitedStates, Actual360 calendar = UnitedStates() settlement_days = 2 currency = USDCurrency() fixed_leg_tenor = Period(12, Months) fixed_leg_convention = ModifiedFollowing fixed_leg_daycounter = Actual360() family_name = currency.name + 'index' ibor_index = Libor( "USDLibor", Period(3,Months), settlement_days, USDCurrency(), UnitedStates(), Actual360() ) rate = 0.005681 tenor = Period(1, Years) index = SwapIndex ( family_name, tenor, settlement_days, currency, calendar, fixed_leg_tenor, fixed_leg_convention, fixed_leg_daycounter, ibor_index) helper = SwapRateHelper.from_index(rate, index) #self.fail( # 'Make this pass: create and ask for the .quote property' # ' Test the from_index and from_tenor methods' #) self.assertIsNotNone(helper) self.assertAlmostEquals(rate, helper.quote) with self.assertRaises(RuntimeError): self.assertAlmostEquals(rate, helper.implied_quote)
def build_pln_fx_swap_curve(self, base_ccy_yts, fx_swaps, fx_spot): """ Build curve implied from fx swap curve. :param base_ccy_yts: Relinkable yield term structure handle to curve in base currency. :param fx_swaps: Dictionary with swap points, already divided by 10,000 :param fx_spot: Float value of fx spot exchange rate. :return: tuple consisting of objects related to fx swap implied curve: PiecewiseFlatForward, YieldTermStructureHandle RelinkableYieldTermStructureHandle list of FxSwapRateHelper """ todaysDate = base_ccy_yts.reference_date # I am not sure if that is required, but I guss it is worth setting # up just in case somewhere another thread updates this setting. Settings.instance().evaluation_date = todaysDate calendar = JointCalendar(TARGET(), Poland()) spot_date_lag = 2 trading_calendar = UnitedStates() # build rate helpers spotFx = SimpleQuote(fx_spot) fxSwapHelpers = [ FxSwapRateHelper( SimpleQuote(fx_swaps[(n, unit)]), spotFx, Period(n, unit), spot_date_lag, calendar, ModifiedFollowing, True, True, base_ccy_yts, trading_calendar, ) for n, unit in fx_swaps ] # term-structure construction fxSwapCurve = PiecewiseYieldCurve[ForwardRate, BackwardFlat].from_reference_date(todaysDate, fxSwapHelpers, Actual365Fixed()) fxSwapCurve.extrapolation = True return fxSwapCurve, fxSwapHelpers
def setUp(self): atm_option_tenors = [Period(1, Months), Period(6, Months)] + \ [Period(i, Years) for i in [1, 5, 10, 30]] atm_swap_tenors = [Period(1, Years), Period(5, Years), Period(10, Years), Period(30, Years)] m = np.array([[.1300, .1560, .1390, .1220], [.1440, .1580, .1460, .1260], [.1600, .1590, .1470, .1290], [.1640, .1470, .1370, .1220], [.1400, .1300, .1250, .1100], [.1130, .1090, .1070, .0930]]) M = Matrix.from_ndarray(m) calendar = UnitedStates() self.atm_vol_matrix = SwaptionVolatilityMatrix(calendar, Following, atm_option_tenors, atm_swap_tenors, M, Actual365Fixed()) term_structure = FlatForward(forward=0.05, settlement_days=2, calendar=calendar, daycounter=Actual365Fixed()) self.swap_index_base = EuriborSwapIsdaFixA(Period(2, Years), term_structure) self.short_swap_index_base = EuriborSwapIsdaFixA(Period(1, Years), term_structure) self.vega_weighted_smile_fit = False class Cube: def __init__(self): self.option_tenors = [Period(1, Years), Period(10, Years), Period(30, Years)] self.swap_tenors = [Period(2, Years), Period(10, Years), Period(30, Years)] self.strike_spreads = [-0.02, -0.005, 0, 0.005, 0.02] self.vol_spreads = np.array([[0.0599, 0.0049, 0.0000, -0.0001, 0.0127], [0.0729, 0.0086, 0.0000, -0.0024, 0.0098], [0.0738, 0.0102, 0.0000, -0.0039, 0.0065], [0.0465, 0.0063, 0.0000, -0.0032, -0.0010], [0.0558, 0.0084, 0.0000, -0.0050, -0.0057], [0.0576, 0.0083, 0.0000, -0.0043, -0.0014], [0.0437, 0.0059, 0.0000, -0.0030, -0.0006], [0.0533, 0.0078, 0.0000, -0.0045, -0.0046], [0.0545, 0.0079, 0.0000, -0.0042, -0.0020]]) self.vol_spreads_handle = [] for vs in self.vol_spreads: self.vol_spreads_handle.append([SimpleQuote(v) for v in vs]) self.cube = Cube()
def make_rate_helper(label, rate, dt_obs, currency='USD'): """ Wrapper for deposit and swaps rate helpers makers For Swaps: assume USD swap fixed rates vs. 6M Libor TODO: make this more general """ if(currency.upper() != 'USD'): raise Exception("Only supported currency is USD.") rate_type, tenor, period = _parse_rate_label(label) if not isinstance(dt_obs, Date): dt_obs = pydate_to_qldate(dt_obs) settings = Settings() calendar = JointCalendar(UnitedStates(), UnitedKingdom()) # must be a business day eval_date = calendar.adjust(dt_obs) settings.evaluation_date = eval_date settlement_days = 2 settlement_date = calendar.advance(eval_date, settlement_days, Days) # must be a business day settlement_date = calendar.adjust(settlement_date) end_of_month = True if((rate_type == 'SWAP') & (period == 'Y')): liborIndex = Libor( 'USD Libor', Period(6, Months), settlement_days, USDCurrency(), calendar, Actual360() ) spread = SimpleQuote(0) fwdStart = Period(0, Days) helper = SwapRateHelper.from_tenor(rate, Period(tenor, Years), calendar, Annual, Unadjusted, Thirty360(), liborIndex, spread, fwdStart) elif((rate_type == 'LIBOR') & (period == 'M')): helper = DepositRateHelper(rate, Period(tenor, Months), settlement_days, calendar, ModifiedFollowing, end_of_month, Actual360()) else: raise Exception("Rate type %s not supported" % label) return (helper)
def bootstrap_term_structure(self, interpolator='loglinear'): tolerance = 1.0e-15 settings = Settings() calendar = JointCalendar(UnitedStates(), UnitedKingdom()) # must be a business day eval_date = self._eval_date settings.evaluation_date = eval_date settlement_days = self._params.settlement_days settlement_date = calendar.advance(eval_date, settlement_days, Days) # must be a business day settlement_date = calendar.adjust(settlement_date) ts = PiecewiseYieldCurve( 'discount', interpolator, settlement_date, self._rate_helpers, DayCounter.from_name(self._termstructure_daycount), tolerance) self._term_structure = ts self._discount_term_structure = YieldTermStructure(relinkable=True) self._discount_term_structure.link_to(ts) self._forecast_term_structure = YieldTermStructure(relinkable=True) self._forecast_term_structure.link_to(ts) return ts
def testFxMarketConventionsForDatesInEURUSD_ShortEnd(self): """ Testing if FxSwapRateHelper obeys the fx spot market conventions for EURUSD settlement dates on the 3M tenor. """ today = Date(1, 7, 2016) Settings.instance().evaluation_date = today expected_3M_date = Date(5, 10, 2016) fwd_points = 4.0 # critical for ON rate helper period = Period("3M") fixing_days = 2 # empty RelinkableYieldTermStructureHandle is sufficient for testing # dates base_ccy_yts = YieldTermStructure() # In EURUSD, there must be two days to spot date in Target calendar # and one day in US, therefore it is sufficient to pass only Target # as a base calendar. Passing joint calendar would result in wrong # spot date of the trade calendar = TARGET() trading_calendar = UnitedStates() rate_helper = FxSwapRateHelper( SimpleQuote(fwd_points), SimpleQuote(self.fx_spot_quote_EURUSD), period, fixing_days, calendar, ModifiedFollowing, True, True, base_ccy_yts, trading_calendar, ) self.assertEqual(expected_3M_date, rate_helper.latest_date)
def testFxMarketConventionsForDatesInEURUSD_ON_Period(self): """ Testing if FxSwapRateHelper obeys the fx spot market conventions for EURUSD settlement dates on the ON Period. """ today = Date(1, 7, 2016) Settings.instance().evaluation_date = today spot_date = Date(5, 7, 2016) fwd_points = 4.0 # critical for ON rate helper on_period = Period("1d") fixing_days = 0 # empty RelinkableYieldTermStructureHandle is sufficient for testing # dates base_ccy_yts = YieldTermStructure() # In EURUSD, there must be two days to spot date in Target calendar # and one day in US, therefore it is sufficient to pass only Target # as a base calendar calendar = TARGET() trading_calendar = UnitedStates() on_rate_helper = FxSwapRateHelper( SimpleQuote(fwd_points), SimpleQuote(self.fx_spot_quote_EURUSD), on_period, fixing_days, calendar, ModifiedFollowing, False, True, base_ccy_yts, trading_calendar, ) self.assertEqual(spot_date, on_rate_helper.latest_date)
def testFxMarketConventionsForCrossRateONPeriod(self): """ Testing if FxSwapRateHelper obeys the fx spot market conventions for cross rates' ON Period. """ today = Date(1, 7, 2016) Settings.instance().evaluation_date = today spot_date = Date(5, 7, 2016) fwd_points = 4.0 # critical for ON rate helper on_period = Period("1d") fixing_days = 0 # empty RelinkableYieldTermStructureHandle is sufficient for testing # dates base_ccy_yts = YieldTermStructure() us_calendar = UnitedStates() joint_calendar = JointCalendar(TARGET(), Poland()) # Settlement should be on a day where all three centers are operating # and follow EndOfMonth rule on_rate_helper = FxSwapRateHelper( SimpleQuote(fwd_points), SimpleQuote(self.fx_spot_quote_EURPLN), on_period, fixing_days, joint_calendar, ModifiedFollowing, False, True, base_ccy_yts, us_calendar, ) self.assertEqual(spot_date, on_rate_helper.latest_date)
def test_zero_curve_on_swap_index(self): todays_date = today() calendar = UnitedStates() # INPUT dayCounter = Actual360() # INPUT currency = USDCurrency() # INPUT Settings.instance().evaluation_date = todays_date settlement_days = 2 settlement_date = calendar.advance( todays_date, period=Period(settlement_days, Days) ) liborRates = [ SimpleQuote(0.002763), SimpleQuote(0.004082), SimpleQuote(0.005601), SimpleQuote(0.006390), SimpleQuote(0.007125), SimpleQuote(0.007928), SimpleQuote(0.009446), SimpleQuote(0.01110)] liborRatesTenor = [Period(tenor, Months) for tenor in [1,2,3,4,5,6,9,12]] Libor_dayCounter = Actual360(); swapRates = [SimpleQuote(0.005681), SimpleQuote(0.006970), SimpleQuote(0.009310), SimpleQuote(0.012010), SimpleQuote(0.014628), SimpleQuote(0.016881), SimpleQuote(0.018745), SimpleQuote(0.020260), SimpleQuote(0.021545)] swapRatesTenor = [Period(i, Years) for i in range(2, 11)] # description of the fixed leg of the swap Swap_fixedLegTenor = Period(12, Months) # INPUT Swap_fixedLegConvention = ModifiedFollowing # INPUT Swap_fixedLegDayCounter = Actual360() # INPUT # description of the float leg of the swap Swap_iborIndex = Libor( "USDLibor", Period(3, Months), settlement_days, USDCurrency(), UnitedStates(), Actual360() ) SwapFamilyName = currency.name + "swapIndex" instruments = [] # ++++++++++++++++++++ Creation of the vector of RateHelper (need for the Yield Curve construction) # ++++++++++++++++++++ Libor LiborFamilyName = currency.name + "Libor" instruments = [] for rate, tenor in zip(liborRates, liborRatesTenor): # Index description ___ creation of a Libor index liborIndex = Libor( LiborFamilyName, tenor, settlement_days, currency, calendar, Libor_dayCounter ) # Initialize rate helper # the DepositRateHelper link the recording rate with the Libor # index instruments.append(DepositRateHelper(rate, index=liborIndex)) for tenor, rate in zip(swapRatesTenor, swapRates): # swap description ___ creation of a swap index. The floating leg is described in the index 'Swap_iborIndex' swapIndex = SwapIndex ( SwapFamilyName, tenor, settlement_days, currency, calendar, Swap_fixedLegTenor, Swap_fixedLegConvention, Swap_fixedLegDayCounter, Swap_iborIndex ) # Initialize rate helper __ the SwapRateHelper links the swap index width his rate instruments.append(SwapRateHelper.from_index(rate,swapIndex)) # ++++++++++++++++++ Now the creation of the yield curve tolerance = 1.0e-15 ts = PiecewiseYieldCurve( 'zero', 'linear', settlement_date, instruments, dayCounter, tolerance ) self.assertEqual(settlement_date, ts.reference_date)
def test_zero_curve_on_swap_index(self): todays_date = today() calendar = UnitedStates() # INPUT dayCounter = Actual360() # INPUT currency = USDCurrency() # INPUT Settings.instance().evaluation_date = todays_date settlement_days = 2 settlement_date = calendar.advance( todays_date, period=Period(settlement_days, Days) ) liborRates = [ SimpleQuote(0.002763), SimpleQuote(0.004082), SimpleQuote(0.005601), SimpleQuote(0.006390), SimpleQuote(0.007125), SimpleQuote(0.007928), SimpleQuote(0.009446), SimpleQuote(0.01110)] liborRatesTenor = [Period(tenor, Months) for tenor in [1,2,3,4,5,6,9,12]] Libor_dayCounter = Actual360(); swapRates = [SimpleQuote(0.005681), SimpleQuote(0.006970), SimpleQuote(0.009310), SimpleQuote(0.012010), SimpleQuote(0.014628), SimpleQuote(0.016881), SimpleQuote(0.018745), SimpleQuote(0.020260), SimpleQuote(0.021545)] swapRatesTenor = [Period(i, Years) for i in range(2, 11)] # description of the fixed leg of the swap Swap_fixedLegTenor = Period(12, Months) # INPUT Swap_fixedLegConvention = ModifiedFollowing # INPUT Swap_fixedLegDayCounter = Actual360() # INPUT # description of the float leg of the swap Swap_iborIndex = Libor( "USDLibor", Period(3, Months), settlement_days, USDCurrency(), UnitedStates(), Actual360() ) SwapFamilyName = currency.name + "swapIndex" instruments = [] # ++++++++++++++++++++ Creation of the vector of RateHelper (need for the Yield Curve construction) # ++++++++++++++++++++ Libor LiborFamilyName = currency.name + "Libor" instruments = [] for rate, tenor in zip(liborRates, liborRatesTenor): # Index description ___ creation of a Libor index liborIndex = Libor( LiborFamilyName, tenor, settlement_days, currency, calendar, Libor_dayCounter ) # Initialize rate helper # the DepositRateHelper link the recording rate with the Libor # index instruments.append(DepositRateHelper(rate, index=liborIndex)) for tenor, rate in zip(swapRatesTenor, swapRates): # swap description ___ creation of a swap index. The floating leg is described in the index 'Swap_iborIndex' swapIndex = SwapIndex ( SwapFamilyName, tenor, settlement_days, currency, calendar, Swap_fixedLegTenor, Swap_fixedLegConvention, Swap_fixedLegDayCounter, Swap_iborIndex ) # Initialize rate helper __ the SwapRateHelper links the swap index width his rate instruments.append(SwapRateHelper.from_index(rate,swapIndex)) # ++++++++++++++++++ Now the creation of the yield curve tolerance = 1.0e-15 ts = PiecewiseYieldCurve.from_reference_date( BootstrapTrait.ZeroYield, Interpolator.Linear, settlement_date, instruments, dayCounter, tolerance ) self.assertEqual(settlement_date, ts.reference_date)
def get_term_structure(df_libor, dtObs): settings = Settings() # libor as fixed in London, but cash-flows are determined according to # US calendar, hence the need to combine both holidays lists calendar = JointCalendar(UnitedStates(), UnitedKingdom()) # must be a business day eval_date = calendar.adjust(dateToDate(dtObs)) settings.evaluation_date = eval_date settlement_days = 2 settlement_date = calendar.advance(eval_date, settlement_days, Days) # must be a business day settlement_date = calendar.adjust(settlement_date) depositData = [[1, Months, 'Libor1M'], [3, Months, 'Libor3M'], [6, Months, 'Libor6M']] swapData = [[1, Years, 'Swap1Y'], [2, Years, 'Swap2Y'], [3, Years, 'Swap3Y'], [4, Years, 'Swap4Y'], [5, Years, 'Swap5Y'], [7, Years, 'Swap7Y'], [10, Years, 'Swap10Y'], [30, Years, 'Swap30Y']] rate_helpers = [] end_of_month = True for m, period, label in depositData: tenor = Period(m, Months) rate = df_libor.get_value(dtObs, label) helper = DepositRateHelper(float(rate / 100), tenor, settlement_days, calendar, ModifiedFollowing, end_of_month, Actual360()) rate_helpers.append(helper) endOfMonth = True liborIndex = Libor('USD Libor', Period(6, Months), settlement_days, USDCurrency(), calendar, Actual360()) spread = SimpleQuote(0) fwdStart = Period(0, Days) for m, period, label in swapData: rate = df_libor.get_value(dtObs, label) helper = SwapRateHelper.from_tenor(rate / 100., Period(m, Years), calendar, Annual, Unadjusted, Thirty360(), liborIndex, spread, fwdStart) rate_helpers.append(helper) ts_day_counter = ActualActual(ISDA) tolerance = 1.0e-15 ts = term_structure_factory('discount', 'loglinear', settlement_date, rate_helpers, ts_day_counter, tolerance) return ts
import numpy as np from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from matplotlib import cm from quantlib.quotes import SimpleQuote from quantlib.settings import Settings from quantlib.time.api import (TARGET, Actual365Fixed, Date, UnitedStates, NullCalendar) from quantlib.math.matrix import Matrix from quantlib.termstructures.yields.flat_forward import FlatForward from quantlib.termstructures.volatility.equityfx.black_variance_surface import BlackVarianceSurface from quantlib.termstructures.volatility.equityfx.local_vol_surface import LocalVolSurface dc = Actual365Fixed() calendar = UnitedStates() calculation_date = Date(6, 11, 2015) spot = 659.37 Settings.instance().evaluation_date = calculation_date dividend_yield = SimpleQuote(0.0) risk_free_rate = 0.01 dividend_rate = 0.0 # bootstrap the yield/dividend/vol curves flat_term_structure = FlatForward(reference_date=calculation_date, forward=risk_free_rate, daycounter=dc) flat_dividend_ts = FlatForward(reference_date=calculation_date,