簡體   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