-
Notifications
You must be signed in to change notification settings - Fork 0
/
enterprice_valuation.py
313 lines (244 loc) · 8.37 KB
/
enterprice_valuation.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
import pandas as pd
from data_repo import DataRepo as dr
from data_repo import Enterprice
from rates import Rates
COMPEDITOR_PORTFOLIO = []
class Beta(Enterprice):
def __init__(self, ):#TARGET):
self.all_E = False # True if the TARGET is 100% Equity based (no debt)
'''
self.TARGET = TARGET
self.D = self.TARGET.balance['D']
self.E = self.TARGET.balance['E']
'''
#print(self.balance['D'], self.balance['E'])
self.D = self.balance['D']
self.E = self.balance['E']
self.wD = self.D / (self.E+self.D)
self.wE = self.E / (self.E+self.D)
@property
def Bu(self,):
''' Beta for selskap uten Gjeld
'''
#self.Bu = self.Be # når det ikke finnes gjeld, så er Be hele Beta for hele selskapet
return self.Be
@property
def Bd(self,):
''' Debt Beta
Be = Bu + ( (G/E) * (Bu+Bg) )
==> self.Bd = self.Bu + ( (self.Bu - self.Be) / (self.D/self.E) )
'''
return self.Bu + ( (self.Bu - self.Be) / (self.D/self.E) )
@property
def Bg(self,):
'''bare så det ikke blir forvirring og engelsk og norsk kan forveksles
'''
return self.Bd
@property
def Be(self):
''' Beta of Equity
self.Be = self.Bu + ((self.D/self.E)*(self.Bu+self.Bg))
'''
# I ASSUME THAT THIS IS THE RIGHT ONE
# IF not, then this might also be the Beta for the whole Bi I think? regardless, its a combined beta for Bd and Be
#return self.TARGET.statistics['beta']
return TARGET.statistics['beta']
@property
def Bi(self):
''' Beta for investment
Bi = (Be * wE) + (Bg * wG)
'''
return (self.Be * self.wE) + (self.Bd* self.wD)
class WeightOf:
def __init__(self, E, D): # r, beta): #SHOULD BE REPLACED WITH SUPER
#print(E,D)
self.E = E
self.D = D
@property
#def wE(self, ):
def equity(self, ):
''' weight of equity; how much % of the capital is equity'''
return self.E / (self.E + self.D)
@property
#def wD(self, ):
def debt(self, ):
''' weight of debt; how much % of the capital is debt
'''
return self.D / (self.E + self.D)
class CapitalCost(Beta, Rates, Enterprice):
def __init__(self, ): # r, beta): #SHOULD BE REPLACED WITH SUPER
'''TARGET = enterprice to valuate'''
self.country = TARGET.statistics['country']
'''
FORTSATT MULGI JEG MÅ GJØRE DET SÅNN
self.TARGET = TARGET
self.country = TARGET.statistics['country']
'''
@property
def ErM(self,):
''' market interest rate'''
roas = [COMPEDITOR.statistics['returnOnAssets'] for COMPEDITOR in COMPEDITOR_PORTFOLIO]
return sum(roas)/len(roas)
@property
def rE(self,):
'''Ke: cost of equity'''
return self.Rfm + (self.Be * (self.ErM - self.Rfm))
#return self.Rfm + Beta(self.TARGET).Be * (self.rM - self.Rfm) #Alternative
@property
def rD(self,):
'''Kg: cost of debt'''
'''
Bd = Bg = DebtBeta
or
Kg = Interest Expenses * (1 - Tax Rate)
'''
'''
- Selskapsskatt (Sb) = 0,25
- Kreditorskatt (Sk) = 0,25
- Investorskatt (SEd) = 0,11
- Investorskatt (SEd) = 0,3168 regner med det er det samme som aksjegevinst skatt
'''
return self.Rfm + (self.Bd * (self.ErM - self.Rfm))
#return self.Rfm + Beta(self.TARGET).Bd * (self.rM - self.Rfm) #Alternative
@property
def rU(self,):
''' cost of company without debt'''
# print(self.Rfm)
# print(self.ErM )
# print(self.Bu)
# print((self.ErM - self.Rfm))
# print("==========================")
return self.Rfm * self.Bu * (self.ErM - self.Rfm)
@property
def wacc(self, ):
w = WeightOf(self.E, self.D )
return ((w.equity)*self.rE) + (w.debt)*(self.rD)*(1-self.tax)
#return ((self.wE)*self.rE) + (self.wD)*(self.rD)*(1-self.tax)
#class EnterpriceValue(CapitalCost):
class EnterpriceValue(CapitalCost, Enterprice):
def __init__(self,): #SHOULD BE REPLACED WITH SUPER
'''TARGET = enterprice to valuate'''
''' FORTSATT MULGI JEG MÅ GJØRE DET SÅNN
self.TARGET = TARGET
self.country = TARGET.statistics['country']
'''
self.E, self.D = TARGET.balance['E'], TARGET.balance['D']
self.country = TARGET.statistics['country']
@property
def Vm(self, ):
''' Value of TARGET '''
'''
Vm = Vu + Vx
or
Vm =E(FKS) / ((1+Kwacc)**t)
or
Vm = Vu + PG * N* [nb: N* = N-stjere]
'''
return self.Vu + (self.PG * self.N_star)
@property
def Vu(self, ):
''' Value of TARGET '''
'''
Vu = SUM : E(FKS) / ((1+Ku)**t)
or
(E(OFRS)*(1-Sb)) / Ku ofrs = ebit
'''
ebit = TARGET.income_statement['ebit']
#return last_fks /((1+self.rU))
# print(self.rU)
# print(self.tax, " ", 1-self.tax)
# print(ebit)
# print("_________________________")
#return (ebit*(1-self.tax)) / self.rU
fks = TARGET.cash_flow['fks']
return (fks ) / ((1+self.rU))
@property
def N_star(self,) -> float:
'''
represents N*, and means "the tax value factor"/"skatteverdifaktoren"
formula: N* = 1-(1-Sb)*(1-Se)] / (1-Sk)
Sb = bedriftskatt? aka vanlig fra regnskapet
Se = eierskatt / investorskatt
Sk = kreditorskatt
'''
Sb = self.tax
Se = self.investor_tax
Sk = self.tax
return (1-(1-Sb)*(1-Se)) / (1-Sk)
@property
def rX(self, ):
''' Kx cost of Renteskattegevinst '''
'''
Vx = SUM : E(s*Rt) / (1+Kx)
'''
'''kapitalkostnad av: Renteskattegevinst '''
'''
= (r * PG * s)/r = PG*s
'''
#print(TARGET.cash_flow)
return
def check_arbitrage_opportunity(self):
'''
if left side and right side is NOT equal: then there is a opportunity
(Vu/Vm)*Ku + (Vx/Vm)*kx = (E/Vm)*Ke + (G/Vm)*Kg
'''
@property
def Vx(self, ):
'''kapitalkostnad av: Renteskattegevinst '''
'''
= (r * PG * s)/r = PG*s
'''
self.tax
self.i = TARGET.income_statement['interest_expence']
self.r = self.i/self.D
print("(",self.r, "*", self.PG,"*", self.tax,")","/",self.r)
return (self.r*self.PG*self.tax)/self.r #formelen sier self.r men det virker som self.i gir mer mening
@property
def PG(self, ):
'''
PG = pålydende gjeld =AKA=> dagens gjeldssum
'''
return TARGET.balance['net_debt'] # kan også være current debt og logn term debt
def main():
'''
User requirements:
in order to use this software you will need:
- target stock ticker
- COMPEDITOR stock tickers
- stock exchange ticker
- Full TARGET names or org number
- nationality
-
'''
#NOTE: indexes cant be used as COMPEDITOR need more work
#ISSUE NOTE: SOLUTION --> I solved the inheritence issue by making the Objects into global variables: TARGET and *COMPEDITORS
COMPEDITORs = {
'auss':['AUSS','OL'],
'salm':['SALM','OL'],
'mowi':['MOWI','OL'],
'gsf':['GSF','OL'],
#'obsfx':['OBSFX','OL'],
}
for COMPEDITOR, val in COMPEDITORs.items():
globals()[COMPEDITOR] = Enterprice(val[0], val[1])
COMPEDITOR_PORTFOLIO.append(globals()[COMPEDITOR])
global TARGET
TARGET = Enterprice('lsg', 'OL')
country = "Norway"
r = Rates(country)
E = EnterpriceValue()# r, beta)
print(E.Vu)
print(E.Vm)
##### NOTE NOT CORRECT
#print(E.wacc)
if __name__ == '__main__':
main()
'''
return ((self.E/self.d_e)*self.rE) + (self.D/self.d_e)*(self.rD)*(1-self.tax)
return self.Rfm + self.Beta.Bd * (self.rM - self.Rfm)
return self.Bd
Bu = self.Be
return self.TARGET.statistics['beta']
stat = self.TARGET.info
return self.get_info()
'''