-
Notifications
You must be signed in to change notification settings - Fork 0
/
transformator.py
110 lines (91 loc) · 2.99 KB
/
transformator.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from enum import Enum, EnumMeta
from MathEasyReverse.functions import CompositeFunction, MyltiplyBy, RaiseToAPower, FunctionWithReverse, Add
from MathEasyReverse.loss_transformations import LessThenTo, MoreThenTo
class Multiplier(Enum):
p_to_e = "P/E"
e_to_p = "E/P"
p_to_b = "P/B"
p_to_s = "P/S"
p_to_cf = "P/CF"
l_to_a = "L/A"
netDebt_to_ebitda = "NetDebt / EBITDA"
ev_to_ebitda = "EV / EBITDA"
roa = "ROA"
roe = "ROE"
ros = "ROS"
@classmethod
def contains(cls, value):
return any(value == item.value for item in cls)
def construct_bender(power=1., norm_max=100.):
return CompositeFunction(MyltiplyBy(1./norm_max),
RaiseToAPower(power),
MyltiplyBy(norm_max))
def construct_linear(shift, multiplier, revers = False):
return CompositeFunction(MyltiplyBy(-1 if revers else 1),
Add(shift),
MyltiplyBy(multiplier))
p_to_e_atomic_transformator = CompositeFunction(
LessThenTo(0, 33),
MoreThenTo(33,33),
construct_linear(34, 3, True),
construct_bender(4)
)
e_to_p_atomic_transformator = LessThenTo(0,0)
p_to_b_const = 5
p_to_b_atomic_transformator = CompositeFunction(
LessThenTo(0, p_to_b_const),
MoreThenTo(p_to_b_const, p_to_b_const),
construct_linear(p_to_b_const, 20, True),
construct_bender(3)
)
p_to_s_atomic_transformator = CompositeFunction(
LessThenTo(0, 5),
MoreThenTo(5, 5),
construct_linear(5, 20, True),
construct_bender(3)
)
p_to_cf_atomic_transformator = CompositeFunction(
LessThenTo(0,30),
MoreThenTo(30,30),
construct_linear(30, 3, True),
construct_bender(1.5)
)
l_to_a_atomic_transformator = CompositeFunction(
LessThenTo(0, 100),
MoreThenTo(100,100),
construct_linear(100, 1, True)
)
net_debt_to_ebitda_atomic_transformator = CompositeFunction(
LessThenTo(0, 5),
MoreThenTo(5, 5),
construct_linear(5, 20, True),
construct_bender(3)
)
ev_to_ebitda_atomic_transformator = CompositeFunction(
LessThenTo(0, 33),
MoreThenTo(33, 33),
construct_linear(34, 3, True),
construct_bender(4)
)
roa_atomic_transformator = Add(0)
roe_atomic_transformator = Add(0)
ros_atomis_transformator = Add(0)
transformators = {
Multiplier.p_to_e: p_to_e_atomic_transformator,
Multiplier.e_to_p: e_to_p_atomic_transformator,
Multiplier.p_to_b: p_to_b_atomic_transformator,
Multiplier.p_to_s: p_to_s_atomic_transformator,
Multiplier.p_to_cf: p_to_cf_atomic_transformator,
Multiplier.l_to_a: l_to_a_atomic_transformator,
Multiplier.netDebt_to_ebitda: net_debt_to_ebitda_atomic_transformator,
Multiplier.ev_to_ebitda: ev_to_ebitda_atomic_transformator,
Multiplier.roa: roa_atomic_transformator,
Multiplier.roe: roe_atomic_transformator,
Multiplier.ros: ros_atomis_transformator
}
if __name__ == "__main__":
v = 10
tr = construct_bender(3, 100)
v_t = tr(v)
v_r = tr.restore(v_t)
print(v, v_t, v_r)