forked from romsey67/faspy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_customfloat_structures.py
executable file
·94 lines (79 loc) · 2.48 KB
/
test_customfloat_structures.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 2 21:02:58 2020
@author: RMS671214
"""
from faspy.interestrate.fixincome import date_structures, calc_customfix_structures, \
value_customfix_structures
import numpy as np
from faspy.interestrate import rmp_dates as rd
from faspy.interestrate import discount_curve as dcurve
# %%
mybond = {}
mybond['issue_date'] = np.datetime64('2018-10-22')
mybond['value_date'] = np.datetime64('2021-10-22')
mybond['maturity'] = np.datetime64('2028-10-22')
mybond['day_count'] = 'Actual/365 Fixed'
mybond['frequency'] = 'Semi-Annual'
mybond['business_day'] = 'No Adjustment'
mybond['date_generation'] = rd.date_gen_method[1]
mybond['face_value'] = 1000000
mybond['coupon'] = 10
mybond['ytm'] = None
mybond['type'] = 'Fixed Rate Bond'
structures = list(date_structures(mybond))
print("DATES")
print("=====")
print(structures)
try:
import pandas as pd
pd1 = pd.DataFrame(structures)
except:
pass
# %%
# Create Sample structure
lenstruc = len(structures)
for i in range(lenstruc):
structure = structures[i]
if i == 0:
structure["face_value"] = 10_000_000
structure["fv_flow"] = 1_000_000
structure["coupon"] = 5.00
else:
prevstruc = structures[i-1]
structure["face_value"] = prevstruc["face_value"] + prevstruc["fv_flow"]
structure["fv_flow"] = 1_000_000
structure["coupon"] = prevstruc["coupon"] + 0.25
structures[-1]["fv_flow"] = structures[-1]["face_value"]
new_structures = calc_customfix_structures(structures,
mybond["day_count"],
mybond["frequency"],
mybond["business_day"])
print("CUSTOM STRUCTURE")
print("================")
print(new_structures)
try:
import pandas as pd
pd2 = pd.DataFrame(new_structures)
except:
pass
# %%
# valuing the structures using flat curve
flatcurve = dcurve.flat_curve(mybond['value_date'], mybond['value_date'] + 50,
3.5)
print(flatcurve)
newstruct = value_customfix_structures(mybond["value_date"], new_structures,
mybond["day_count"],
mybond["frequency"], flatcurve)
print("VALUING CUSTOM STRUCTURE")
print("========================")
print(newstruct)
try:
import pandas as pd
pd3 = pd.DataFrame(newstruct)
except:
pass
# %%
coupon_dates = list(date_structures(mybond))
print(coupon_dates)