繁体   English   中英

QuantLib:面值掉期率计算

[英]QuantLib: par swap rate calculation

我想计算以面值交易的掉期(即市场价值 = 0)的面值掉期利率(即固定腿利率),给定观察到的到期期限为 3 个月至 120 个月的零息票曲线。

这是我所做的:

# define constants
face_amount = 100
settlementDays = 0
calendar = ql.NullCalendar()
fixedLegAdjustment = ql.Unadjusted
floatingLegAdjustment = ql.Unadjusted
fixedLegDayCounter = ql.SimpleDayCounter()
floatingLegDayCounter = ql.SimpleDayCounter()
end_of_month = False
floating_rate = ql.IborIndex("MyIndex", ql.Period("3m"), settlementDays, ql.USDCurrency(), calendar, floatingLegAdjustment, end_of_month, floatingLegDayCounter)

# pre-allocate
irs = {}

# calculate dates
curve_date = ql.DateParser.parseFormatted("2020-05-26", "%Y-%m-%d")
ql.Settings.instance().evaluationDate = curve_date
spot_date = calendar.advance(curve_date, settlementDays, ql.Days)

# pre-allocate
irs_rate = []
tenors = []
maturity_dates = []
# loop over maturities
for tenor in np.arange(3, 120 + 1, 3):
    # maturity date
    maturity_date = calendar.advance(spot_date, ql.Period(int(tenor), ql.Months))
    # gather maturity dates
    maturity_dates.append(maturity_date)

# build zero coupon curve object
zero_curve = ql.YieldTermStructureHandle(ql.ZeroCurve(maturity_dates, zero_rates, fixedLegAdjustment, calendar))

# build swap curve
# loop over maturities
for tenor in np.arange(3, 120 + 1, 3):
    # fixed leg tenor
    fixedLegTenor = ql.Period(tenor, ql.Months)
    # fixed leg coupon schedule
    fixedLegSchedule = ql.Schedule(spot_date, maturity_date, 
                                 fixedLegTenor, calendar,
                                 fixedLegAdjustment, fixedLegAdjustment,
                                 ql.DateGeneration.Forward, end_of_month)

    # floating leg tenor
    floatingLegTenor = ql.Period(3, ql.Months)
    # floating leg coupon schedule
    floatingLegSchedule = ql.Schedule(spot_date, maturity_date,
                                  floatingLegTenor, calendar,
                                  floatingLegAdjustment, floatingLegAdjustment,
                                  ql.DateGeneration.Forward, end_of_month)

    # build swap pricer
    irs = ql.VanillaSwap(ql.VanillaSwap.Receiver, face_amount, fixedLegSchedule, FIXED_RATE, fixedLegDayCounter, floatingLegSchedule, floating_rate, 0, floatingLegDayCounter)

    # build swap curve
    swap_curve = ql.DiscountingSwapEngine(zero_curve)
    # get swap rate
    irs.setPricingEngine(swap_curve)
    # get par swap rate
    irs_rate.append(irs.fairRate())

但是,这是为了获得观察到的固定利率 = FIXED_RATE的掉期市场价值

相反,我想要给定观察到的市场价值(零)的汇率。

非常感谢您的帮助。

调用irs.fairRate()是正确的:它忽略传递的固定利率,并为您提供与 value = 0 对应的利率。相反, irs.NPV()会给您提供固定利率的市场利率。

但是,您创建交换的方式不正确。 第二个循环应该是这样的:

for maturity_date in maturities:

这将为您提供每次掉期的正确到期日。 目前,您正在对tenor再次进行迭代,但您没有重新定义maturity_date日期,因此您一遍又一遍地重用其当前值,而这恰好是前一个循环中的最后一个值。

在循环内部, fixedLegTenor应该设置为固定利率优惠券的长度(我猜ql.Period(3, ql.Months)就像浮动利率优惠券一样?)

最后:是的,您可以为 Libor 使用任何利率期限结构,包括ql.ZeroCurve

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM