Quantlib

使用 Quantlib 計算遠期掉期利率

  • September 17, 2020

在這裡,我們有一個計算遠期掉期利率的例子——如何計算遠期掉期利率?

以下是我的前向交換 -

from QuantLib import *
import datetime
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

calc_date = Date(29, 3, 2019)
start = 10
length = 10
start_date =  TARGET().advance(calc_date, start, Years)
maturity_date = start_date + Period(length, Years)

spot_curve = FlatForward(calc_date, QuoteHandle(SimpleQuote(0.01)), Actual365Fixed())
termStructure = YieldTermStructureHandle(spot_curve)
index = Euribor6M(termStructure)

fixedSchedule = Schedule(start_date,     ## pd.DataFrame({'date': list(fixedSchedule)})
                        maturity_date, 
                        Period(1, Years),  
                        TARGET(), 
                        Unadjusted,  
                        Unadjusted, 
                        DateGeneration.Forward,  
                        False
                   )
floatingSchedule = Schedule(start_date,  ## pd.DataFrame({'date': list(floatingSchedule)})
                           maturity_date, 
                           Period(6, Months),  
                           TARGET(), 
                           ModifiedFollowing,  
                           ModifiedFollowing, 
                           DateGeneration.Forward,  
                           True
                        )

swap = VanillaSwap(VanillaSwap.Receiver,  
                     10000000, 
                     fixedSchedule,  
                     1.45 / 100,
                     Thirty360(Thirty360.BondBasis), 
                     floatingSchedule,  
                     index,  
                     0.0, 
                     index.dayCounter()
                   )

有什麼方法可以直接獲得遠期掉期利率QuantLib?我試圖避免使用給定的連結進行顯式計算。

非常感謝您的指點。

您不能直接獲得 Forward Swap,因為您必須為您想要的內容提供一些約定。然而,有一種不那麼冗長的方式來建構遠期互換並獲得它的 fairRate。請注意,大多數約定將來自您指定的索引。

import QuantLib as ql

calc_date = ql.Date(29, 3, 2019)

spot_curve = ql.FlatForward(calc_date, ql.QuoteHandle(ql.SimpleQuote(0.01)), ql.Actual365Fixed())
termStructure = ql.YieldTermStructureHandle(spot_curve)
index = ql.Euribor6M(termStructure)
engine = ql.DiscountingSwapEngine(termStructure)

start = 10
length = 10
swapTenor = ql.Period(length, ql.Years)
forwardStart = ql.Period(start, ql.Years)
swap = ql.MakeVanillaSwap(swapTenor, index, 0.0, forwardStart, pricingEngine=engine)

print(f"Forward Rate Swap Rate: {swap.fairRate():.3%}")

遠期利率掉期利率:1.006%

(編輯) 查看交換詳細資訊:

print(swap.fixedDayCount().name())
print([dt.ISO() for dt in swap.fixedSchedule()])
print(swap.floatingDayCount().name())
print([dt.ISO() for dt in swap.floatingSchedule()])

30/360(債券基礎)

$$ ‘2030-09-23’, ‘2031-09-23’, ‘2032-09-23’, ‘2033-09-23’, ‘2034-09-25’, ‘2035-09-24’, ‘2036-09-23’, ‘2037-09-23’, ‘2038-09-23’, ‘2039-09-23’, ‘2040-09-24’ $$

實際/360

$$ ‘2030-09-23’, ‘2031-03-24’, ‘2031-09-23’, ‘2032-03-23’, ‘2032-09-23’, ‘2033-03-23’, ‘2033-09-23’, ‘2034-03-23’, ‘2034-09-25’, ‘2035-03-27’, ‘2035-09-24’, ‘2036-03-24’, ‘2036-09-23’, ‘2037-03-23’, ‘2037-09-23’, ‘2038-03-23’, ‘2038-09-23’, ‘2039-03-23’, ‘2039-09-23’, ‘2040-03-23’, ‘2040-09-24’ $$

引用自:https://quant.stackexchange.com/questions/58053