aboutsummaryrefslogtreecommitdiffstats
path: root/python/analytics/tranche_functions.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/analytics/tranche_functions.py')
-rw-r--r--python/analytics/tranche_functions.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/python/analytics/tranche_functions.py b/python/analytics/tranche_functions.py
index 21c7b328..24f06484 100644
--- a/python/analytics/tranche_functions.py
+++ b/python/analytics/tranche_functions.py
@@ -2,8 +2,8 @@ import numpy as np
from ctypes import *
from numpy.ctypeslib import ndpointer
from quantlib.time.schedule import Schedule, CDS2015
-from quantlib.time.api import Actual360, Period, WeekendsOnly, ModifiedFollowing, Unadjusted, today
-from quantlib.util.converter import qldate_to_pydate, pydate_to_qldate
+from quantlib.time.api import Actual360, Period, WeekendsOnly, ModifiedFollowing, Unadjusted
+from quantlib.util.converter import pydate_to_qldate
import pandas as pd
from scipy.special import h_roots
import os
@@ -293,7 +293,7 @@ def tranche_cl(L, R, cs, K1, K2, scaled=False):
else:
support = np.linspace(0, 1, L.shape[0])
size = K2 - K1 - np.dot(trancheloss(support, K1, K2), L) - \
- np.dot(trancherecov(support, K1, K2), R)
+ np.dot(trancherecov(support, K1, K2), R)
sizeadj = 0.5 * (size + np.hstack((K2-K1, size[:-1])))
if scaled:
return 1 / (K2-K1) * np.dot(sizeadj * cs["coupons"], cs["df"])
@@ -343,7 +343,8 @@ def cds_accrued(tradedate, coupon):
start_protection = tradedate + 1
DC = Actual360()
cal = WeekendsOnly()
- sched = Schedule(tradedate, end, Period('3M'), cal, date_generation_rule=CDS2015)
+ sched = Schedule.from_rule(tradedate, end, Period('3M'), cal,
+ date_generation_rule=CDS2015)
prevpaydate = sched.previous_date(start_protection)
return DC.year_fraction(prevpaydate, start_protection) * coupon
@@ -377,15 +378,14 @@ def dist_transform2(q):
return distDR
def compute_pv(q, strike):
- """ compute E(1_{R^\bar \leq strike} * D)"""
- D = 0
+ r""" compute E(1_{R^\bar \leq strike} * D)"""
for i in range(q.shape):
- val += sum(v for k, v in q[i].items() if k < strike) * 1/Ngrid
+ val += sum(v for k, v in q[i].items() if k < strike) * 1 / Ngrid
return val
def average_recov(p, R, Ngrid):
- q = np.zeros((p.shape[0]+1, Ngrid))
- q[0,0] = 1
+ q = np.zeros((p.shape[0] + 1, Ngrid))
+ q[0, 0] = 1
lu = 1 / (Ngrid-1)
weights = np.empty(Ngrid)
index = np.empty(Ngrid)