|
From: Brian S. <bri...@gm...> - 2020-11-22 21:21:46
|
Hi,
I use QL to calculate the Rate of Interest between 2 forward dates as below -
from QuantLib import *
import math
# Settings
todaysDate = Date(1, 9, 2019)
Settings.instance().evaluationDate = todaysDate
dayCount = Actual365Fixed()
calendar = Canada()
interpolation = Linear()
compounding = Compounded
compoundingFrequency = Continuous
# Definitions
spotDates = [todaysDate, todaysDate + Period("1y"), todaysDate +
Period("2y"), todaysDate + Period("3y")]
spotRates = [0, 0.066682, 0.067199, 0.067502]
spotCurve = ZeroCurve(spotDates, spotRates, dayCount, calendar,
interpolation, compounding, compoundingFrequency)
spotCurveHandle = YieldTermStructureHandle(spotCurve)
spotCurveHandle.forwardRate(spotDates[1], spotDates[2], dayCount,
Continuous).rate() # Forward rate
# 0.06659636746440421
However when I manually calculate the same, I see visible difference -
math.log(math.exp(spotRates[2] * dayCount.yearFraction(todaysDate,
spotDates[2])) / math.exp(spotRates[1] *
dayCount.yearFraction(todaysDate, spotDates[1]))) /
dayCount.yearFraction(spotDates[1], spotDates[2])
#0.06771741643835603
Can you please help me to understand what actually attributes that
difference between QL's number and my calculation?
|