|
From: David D. <nh...@gm...> - 2020-11-23 10:12:17
|
Hi,
First, the ZeroCurve constructor already expects continuously compounded
rates (and uses linear interpolation), so if you just define it as:
spotCurve = ZeroCurve(spotDates, spotRates, dayCount, calendar)
you will get the right result.
Second, the way you are inputting the conventions is not correct. The
alternatives for the compounding are:
- Simple
- Compounded
- Continuous
- SimpleThenCompounded
These "objects" in python actually just return an int. To see what I mean,
try:
print(Simple, Compounded, Continuous, SimpleThenCompounded)
# 0 1 2 3
If you specify Compounded, you can then specify the frequency: Annual,
Semiannual, etc (these frequencies also just return an int)
So you where actually building a curve with semiannually compounded rates,
and that's why your calculations were off
You were building the curve as (Compounded = 1, Semiannual = 2):
spotCurve = ZeroCurve(spotDates, spotRates, dayCount,
calendar, interpolation, Compounded, Semiannual)
when what you wanted was (Continuous = 2):
spotCurve = ZeroCurve(spotDates, spotRates, dayCount, calendar,
interpolation, Continuous)
Hope this helps
David
On Sun, 22 Nov 2020 at 21:22, Brian Smith <bri...@gm...>
wrote:
> 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?
>
>
> _______________________________________________
> QuantLib-users mailing list
> Qua...@li...
> https://lists.sourceforge.net/lists/listinfo/quantlib-users
>
|