Ejemplo n.º 1
0
def InterpolateProbsLinearFromSurvivalProbs(TenoredSeries,
                                            Tenors,
                                            isSurvival=True):
    i = 0
    fnd2 = FindClosestKeyInDicAndReturnKeyBoundsAlgorithm(TenoredSeries)
    res = dict()
    res[0] = 1
    prevT = 0
    prevIntRate = 1
    for t in Tenors:
        res[t] = fnd2(t)
        if len(res[t]) > 1:
            tiplus1 = res[t][1]
            ti = res[t][0]
            intRate = (t - ti) / (tiplus1 - ti) * (
                TenoredSeries[tiplus1] - TenoredSeries[ti]) + TenoredSeries[ti]
            if isSurvival:
                res[t] = intRate
            else:
                res[t] = prevIntRate - intRate
                prevIntRate = intRate
        else:
            if isSurvival:
                res[t] = TenoredSeries[res[t]].values[0]
            else:
                survivalProb = TenoredSeries[res[t]].values[0]
                res[t] = prevIntRate - survivalProb
                prevIntRate = survivalProb
        prevT = t

    return res
Ejemplo n.º 2
0
def DiscountFactorFn(DF: dict):
    fnd = FindClosestKeyInDicAndReturnKeyBoundsAlgorithm(DF)

    def f(val):
        res = fnd(val)
        if len(res) > 1:
            return math.exp((val - res[0]) /
                            (res[1] - res[0]) * math.log(DF[res[1]]) +
                            (res[1] - val) /
                            (res[1] - res[0]) * math.log(DF[res[0]]))
        else:
            return DF[res[0]]

    return f
Ejemplo n.º 3
0
def InterpolateHazrateLinear(TenoredSeries, Tenors):
    i = 0
    fnd2 = FindClosestKeyInDicAndReturnKeyBoundsAlgorithm(TenoredSeries)

    res = dict()
    res[0] = 1
    for t in Tenors:
        res[t] = fnd2(t)
        if len(res[t]) > 1:
            tiplus1 = res[t][1]
            ti = res[t][0]
            intRate = (t - ti) / (tiplus1 - ti) * (
                TenoredSeries[tiplus1] - TenoredSeries[ti]) + TenoredSeries[ti]
            res[t] = intRate
        else:
            res[t] = TenoredSeries[res[t]].values[0]

    return res
Ejemplo n.º 4
0
def InterpolateDFLogLinear(TenoredSeries, Tenors):
    i = 0
    fnd = FindClosestKeyInDicAndReturnKeyBoundsAlgorithm(TenoredSeries)

    res = dict()
    res[0] = 1
    for t in Tenors:
        res[t] = fnd(t)
        if len(res[t]) > 1:
            tiplus1 = res[t][1]
            ti = res[t][0]
            lnDiscFac = ((t - ti) /
                         (tiplus1 - ti) * math.log(TenoredSeries[tiplus1])) + (
                             (tiplus1 - t) /
                             (tiplus1 - ti) * math.log(TenoredSeries[ti]))
            res[t] = math.exp(lnDiscFac)
        else:
            res[t] = res[t][0]

    return res
Ejemplo n.º 5
0
 def __init__(self, DF: dict):
     self.fnd = FindClosestKeyInDicAndReturnKeyBoundsAlgorithm(DF)
     self.cache = dict()
     self.DF = DF