本文整理汇总了Python中quantlib.termstructures.yields.rate_helpers.SwapRateHelper.from_index方法的典型用法代码示例。如果您正苦于以下问题:Python SwapRateHelper.from_index方法的具体用法?Python SwapRateHelper.from_index怎么用?Python SwapRateHelper.from_index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quantlib.termstructures.yields.rate_helpers.SwapRateHelper
的用法示例。
在下文中一共展示了SwapRateHelper.from_index方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_swap_rate_helper_from_index
# 需要导入模块: from quantlib.termstructures.yields.rate_helpers import SwapRateHelper [as 别名]
# 或者: from quantlib.termstructures.yields.rate_helpers.SwapRateHelper import from_index [as 别名]
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)
示例2: test_create_swap_rate_helper_from_index
# 需要导入模块: from quantlib.termstructures.yields.rate_helpers import SwapRateHelper [as 别名]
# 或者: from quantlib.termstructures.yields.rate_helpers.SwapRateHelper import from_index [as 别名]
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)
示例3: test_zero_curve_on_swap_index
# 需要导入模块: from quantlib.termstructures.yields.rate_helpers import SwapRateHelper [as 别名]
# 或者: from quantlib.termstructures.yields.rate_helpers.SwapRateHelper import from_index [as 别名]
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)