def __init__(
     self,
     terms,
     continuousCompoundedRates,
     day_counter=ql.Actual360(),
     calendar=ql.NullCalendar(),
     interpolation=ql.BackwardFlat(),
 ):
     today = ql.Settings.getEvaluationDate(ql.Settings.instance())
     self.terms = terms
     self.dates = [
         ql.WeekendsOnly().advance(today, ql.Period(term), ql.ModifiedFollowing)
         for term in ["0d"] + terms
     ]
     self.rates = [continuousCompoundedRates[0]] + continuousCompoundedRates
     self.yts = ql.ForwardCurve(
         self.dates, self.rates, day_counter, calendar, interpolation
     )
Example #2
0
ql.Settings.instance().evaluationDate = today
settlementDate = ql.TARGET().advance(today, ql.Period(2, ql.Days))

rts = [
    0.03145, 0.03145, 0.0278373626373627, 0.0253076923076923,
    0.0249373626373629
]
dts = [
    settlementDate,
    ql.Date(1, 2, 2020),
    ql.Date(1, 5, 2020),
    ql.Date(1, 8, 2020),
    ql.Date(1, 11, 2020)
]
c = ql.ForwardCurve(dts, rts, ql.Actual360(), ql.NullCalendar(),
                    ql.BackwardFlat())
df = [c.discount(d) for d in dts]
print(df)

for i in range(len(rts) - 1):
    r_simple = ql.InterestRate(rts[i + 1], ql.Actual360(), ql.Simple, ql.Once)
    t = ql.Actual360().yearFraction(dts[i], dts[i + 1])
    r_continuous = r_simple.equivalentRate(ql.Continuous, ql.NoFrequency, t)
    rts[i + 1] = r_continuous.rate()

# set rate for the first node
rts[0] = rts[1]
c = ql.ForwardCurve(dts, rts, ql.Actual360(), ql.NullCalendar(),
                    ql.BackwardFlat())
df = [c.discount(d) for d in dts]
print(df)
    "Actual360": ql.Actual360(),
    "Actual365Fixed": ql.Actual365Fixed(),
    "ActualActual": ql.ActualActual,
    "Actual365NoLeap": ql.Actual365NoLeap(),
    "Business252": ql.Business252(),
    "Thirty360": ql.Thirty360(),
}

CALENDARS = {
    "NullCalendar": ql.NullCalendar(),
    "BespokeCalendar": ql.BespokeCalendar("CALENDAR_NAME"),
    "JointCalendar": ql.JointCalendar,
}

INTERPOLATION_METHODS = {
    "BackwardFlat": ql.BackwardFlat(),
    "ForwardFlat": ql.ForwardFlat(),
    "MonotonicLogCubic": ql.MonotonicLogCubic(),
    "Linear": ql.Linear(),
    "LogLinear": ql.LogLinear(),
    "Cubic": ql.Cubic(),
    "MonotonicCubic": ql.MonotonicCubic(),
    "DefaultLogCubic": ql.DefaultLogCubic(),
    "SplineCubic": ql.SplineCubic(),
    "Kruger": ql.Kruger(),
    "KrugerLog": ql.KrugerLog(),
    "KrugerCubic": ql.KrugerCubic,
    "FritschButlandCubic": ql.FritschButlandCubic,
    "ConvexMonotone": ql.ConvexMonotone(),
    "CubicNaturalSpline": ql.CubicNaturalSpline,
    "LogCubicNaturalSpline": ql.LogCubicNaturalSpline,