Calcolo del tasso forward swap utilizzando Quantlib
Ecco un esempio per il calcolo del tasso di swap a termine - Come calcolare i tassi di swap a termine?
Di seguito è riportato il mio Forward Swap -
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()
)
Esiste un modo per ottenere direttamente il tasso Forward Swap utilizzando QuantLib? Sto cercando di evitare calcoli espliciti utilizzando il collegamento fornito.
Molte grazie per il tuo suggerimento.
Risposte
Non puoi ottenere il Forward Swap direttamente poiché dovrai dare alcune convenzioni per quello che vuoi. Tuttavia esiste un modo meno prolisso per costruire uno scambio in avanti e ottenere il suo fairRate. Nota che la maggior parte delle convenzioni proverrà dall'indice che hai specificato.
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%}")
Tasso swap a termine: 1,006%
(Modifica) Per vedere i dettagli dello scambio:
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 (Base obbligazionaria)
['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 "]
Effettivo / 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 "]