From 7a4fa08217d9969addf54a71bf580b6850d0f2b4 Mon Sep 17 00:00:00 2001 From: Guillaume Horel Date: Thu, 11 Oct 2018 16:14:20 -0400 Subject: apply black --- example.py | 91 ++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 26 deletions(-) (limited to 'example.py') diff --git a/example.py b/example.py index a926396..8fbaa80 100644 --- a/example.py +++ b/example.py @@ -11,46 +11,85 @@ if __name__ == "__main__": today_date = datetime.date(2016, 7, 12) yc = build_yc(today_date, True) step_in_date = today_date + datetime.timedelta(days=1) - value_date = datetime.date(2016, 7, 15) # settle_date + value_date = datetime.date(2016, 7, 15) # settle_date start_date = datetime.date(2016, 6, 20) end_date = datetime.date(2021, 6, 20) upfront_quote = -0.03063 - spread = spread_from_upfront(today_date, value_date, start_date, step_in_date, - start_date, end_date, 0.05, yc, - upfront_quote, 0.3) - #benchmark_start_date should be start_date. Not sure while there are 2 parameters - upf = upfront_charge(today_date, value_date, start_date, step_in_date, - start_date, end_date, 0.05, yc, spread, 0.3) + spread = spread_from_upfront( + today_date, + value_date, + start_date, + step_in_date, + start_date, + end_date, + 0.05, + yc, + upfront_quote, + 0.3, + ) + # benchmark_start_date should be start_date. Not sure while there are 2 parameters + upf = upfront_charge( + today_date, + value_date, + start_date, + step_in_date, + start_date, + end_date, + 0.05, + yc, + spread, + 0.3, + ) print(spread) - print(upf-upfront_quote) + print(upf - upfront_quote) coupon_leg = FeeLeg(start_date, end_date, True, 1000000, 0.01) contingent_leg = ContingentLeg(start_date, end_date, 1000000) ig_spread = 0.0070 - spread = array.array('d', [ig_spread]) - recovery = array.array('d', [0.4]) - upfront = array.array('d', [-0.0164243]) + spread = array.array("d", [ig_spread]) + recovery = array.array("d", [0.4]) + upfront = array.array("d", [-0.0164243]) print("build spread curve", flush=True) - sc = SpreadCurve(today_date, yc, start_date, step_in_date, value_date, - [end_date], spread, upfront, recovery, True) - sc_data = sc.inspect()['data'] + sc = SpreadCurve( + today_date, + yc, + start_date, + step_in_date, + value_date, + [end_date], + spread, + upfront, + recovery, + True, + ) + sc_data = sc.inspect()["data"] rate = sc_data[0][1] # by default the rate is stored as annually compounded - continuous_rate = math.log(1+rate) + continuous_rate = math.log(1 + rate) sc2 = SpreadCurve.from_flat_hazard(today_date, continuous_rate) - coupon_leg_pv = coupon_leg.pv(today_date, step_in_date, - value_date, yc, sc, True) - coupon_leg_pv2 = coupon_leg.pv(today_date, step_in_date, - value_date, yc, sc2, True) + coupon_leg_pv = coupon_leg.pv(today_date, step_in_date, value_date, yc, sc, True) + coupon_leg_pv2 = coupon_leg.pv(today_date, step_in_date, value_date, yc, sc2, True) print("contingent leg pv", flush=True) - contingent_leg_pv = contingent_leg.pv(today_date, step_in_date, - value_date, yc, sc, 0.4) - contingent_leg_pv2 = contingent_leg.pv(today_date, step_in_date, - value_date, yc, sc2, 0.4) + contingent_leg_pv = contingent_leg.pv( + today_date, step_in_date, value_date, yc, sc, 0.4 + ) + contingent_leg_pv2 = contingent_leg.pv( + today_date, step_in_date, value_date, yc, sc2, 0.4 + ) print("upfront_charge", flush=True) - pv = 1000000 * upfront_charge(today_date, value_date, start_date, step_in_date, - start_date, end_date, 0.01, yc, ig_spread, 0.4) + pv = 1000000 * upfront_charge( + today_date, + value_date, + start_date, + step_in_date, + start_date, + end_date, + 0.01, + yc, + ig_spread, + 0.4, + ) - print(pv, contingent_leg_pv-coupon_leg_pv) + print(pv, contingent_leg_pv - coupon_leg_pv) -- cgit v1.2.3-70-g09d2