-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautocall.py
90 lines (70 loc) · 2.87 KB
/
autocall.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
def int_to_date(date):
"""
Transform date to string
"""
nbr_years = int(date)
nbr_months = int((date - nbr_years)*12)
maturity_string = ''
if nbr_years != 0:
if nbr_years > 1:
maturity_string += str(nbr_years) + ' Years'
else:
maturity_string += str(nbr_years) + ' Year'
if nbr_months != 0:
if nbr_months > 1:
maturity_string += ', ' + str(nbr_months) + ' Months'
else:
maturity_string += ', ' + str(nbr_months) + ' Month'
else:
if nbr_months > 1:
maturity_string += str(nbr_months) + ' Months'
else:
maturity_string += str(nbr_months) + ' Month'
return maturity_string
def underlyings_to_string(underlyings):
"""
Convert the list of tickers to a string
"""
if len(underlyings) == 1:
underlyings_info = underlyings[0]
else:
underlyings_info = ""
for index, underlying in enumerate(underlyings):
if index != len(underlyings)-1:
underlyings_info += underlying + ' / '
else:
underlyings_info += underlying
return underlyings_info
class Autocall:
def __init__(self, underlyings, maturity, frequency, strike, barrier,
barrier_type, coupon, autocall_trigger, coupon_trigger, nbr_non_callable_obs=1,
coupon_guaranteed=False, memory_effect=False):
"""
Store each caracteristic in the object
"""
Autocall.underlyings = underlyings
Autocall.underlyings_string = underlyings_to_string(underlyings)
Autocall.maturity = maturity
Autocall.frequency = frequency
Autocall.strike = strike
Autocall.barrier = barrier
Autocall.coupon = coupon
Autocall.barrier_type = barrier_type
Autocall.autocall_trigger = autocall_trigger
Autocall.coupon_trigger = coupon_trigger
Autocall.nbr_non_callable_obs = nbr_non_callable_obs
Autocall.coupon_guaranteed = coupon_guaranteed
Autocall.memory_effect = memory_effect
def get_info(self):
"""
Returns a formated info table to display on the PDF
"""
return [{'field':'Underlyings','value':self.underlyings_string},
{'field':'Maturity','value':int_to_date(self.maturity)},
{'field':'Period','value':int_to_date(self.frequency)},
{'field':'Barrier','value':str(self.barrier) + ' %'},
{'field':'Barrier type','value':self.barrier_type},
{'field':'Strike','value':str(self.strike) + ' %'},
{'field':'Coupon (p.a.)','value':str(self.coupon) + ' %'},
{'field':'Autocall trigger','value':str(self.autocall_trigger) + ' %'},
{'field':'Coupon trigger','value':str(self.coupon_trigger) + ' %'},]