Bojan Nikolic: Using and Understanding the QuantLib Addin

[website home] | [BN Algorithms]

qlYieldTSDiscount – Calculate discount factor from yield curve

Usage:

=qlYieldTSDiscount(<YCName>,
                   <Dates>,
                   <AllowExtrapolation>)
<YCName>

Name of the yield curve from which discount factors will be calculated

<Dates>

Sequence of dates at which to compute discount factors. Relative (“30D”, “3M, “1Y”) or absolute (in Excel convention) dates are accepted.

<AllowExtrapolation>

Boolean to signify if extrapolation past the end of the curve is permited

Returns a sequence of discount factors.

QLW/Python Example

The following example shows computation of discount curve bootstrapped from OIS (see qlOISRateHelper – create a Rate Helper referencing an overnight index swap) data.

# Copyright (C) 2012-2018 Bojan Nikolic <bojan@bnikolic.co.uk>

from qlww import *

def mkOISHelp(term,  rate):
    index=qlEonia("eonia"+term, 
                  N());
        
    oishelp=qlOISRateHelper("OISHelp"+term, 
                            2,
                            term, 
                            property_t(rate),
                            index,
                            N()  );
    return oishelp;


helpers=StringVector()
helpers.push_back(mkOISHelp("1M", 0.2))
helpers.push_back(mkOISHelp("3M", 0.2))
helpers.push_back(mkOISHelp("6M", 0.5))
helpers.push_back(mkOISHelp("12M", 0.5))

dcc=P("Actual/365 (Fixed)");

yc=qlPiecewiseYieldCurve(UU("yc"),
                         P(2), 
                         "TARGET", 
                         helpers, 
                         dcc,
                         PropertyVector(),
                         PropertyVector(),
                         P(0.0001), 
                         P("ZeroYield"),
                         P("ForwardFlat"))

periods=[str(i)+"M" for i in range(1,12)]
discounts=qlYieldTSDiscount(yc,
                            PropV(periods),
                            N())

for i in range(len(discounts)):
    print("Discount at " + periods[i] +
          " is: " + str(discounts[i]))