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 | #On the name of ALLAH
#Author : Fouad Teniou
#Date : 07/03/09
#version :2.6.1
"""
collections module's extras in python 2.6.1 were used in my program, DVMextrapolating
DVMgordonsModel and CAPM subclasses of namedtuple Python class provide the cost of equity
the calculation of the dividend growth g in two different ways, and the value of the company
if the cost of equity Ke is known.
I used an utility method and the try/exceptions statements to raise errors
"""
import math as m
from collections import namedtuple
class MyError:
""" Demonstrate imporper operation on negative number"""
def _negativeNumberException(self,*args):
""" Utility method to raise a negative number exception"""
for item in args:
if item <0:
raise ValueError,\
" <The value %s should be a positive number " % item
class DVMextrapolating(namedtuple('DVMextrapolating','dividend_just_paid,dividend_n_years,n,share_price,Ke'),MyError):
""" DVMeModel class inherits from tuple and MyError class """
#set __slots__ to an empty tuple keep memory requirements low
__slots__ = ()
#Pick Myerror method
_negativeNumberException =MyError._negativeNumberException
@property
def g_extrapolatingModel(self):
""" Compute g using extrapolating """
try:
#Test for negative numbers input and raise the exception
self._negativeNumberException(self.dividend_just_paid,self.dividend_n_years,self.n)
return "%2.2f" % ((float(m.pow((self.dividend_just_paid/self.dividend_n_years),(1/float(self.n)))) -1))
#Raise TypeError if input is not numerical
except TypeError:
print "\n<The entered value is not a number"
#division by zero raises ZeroDivisionError exception
except ZeroDivisionError:
raise ZeroDivisionError, "\n<Please check and re-enter the values"
@property
def valueOfShare(self):
""" Compute the share value """
try:
#Test for negative numbers input and raise the exception
self._negativeNumberException(self.dividend_just_paid,self.dividend_n_years,self.Ke)
return "%2.2f" % (((self.dividend_just_paid*
(1+float(self.g_extrapolatingModel)))/(self.Ke-float(self.g_extrapolatingModel))))
#Raise TypeError if input is not numerical
except TypeError:
print "\n<The entered value is not a number"
#division by zero raises ZeroDivisionError exception
except ZeroDivisionError:
raise ZeroDivisionError, "\n<Please check and re-enter the values"
@property
def costOfEquity(self):
""" Compute cost of equity using DVM Model """
try:
#Test for negative numbers input and raise the exception
self._negativeNumberException(self.dividend_just_paid,self.share_price)
return "%2.1f" % ((((self.dividend_just_paid*
(1+float(self.g_extrapolatingModel))/self.share_price))+ float(self.g_extrapolatingModel))*100)
#Raise TypeError if input is not numerical
except TypeError:
print "\n<The entered value is not a number"
#division by zero raises ZeroDivisionError exception
except ZeroDivisionError:
raise ZeroDivisionError, "\n<Please check and re-enter the values"
def __str__(self):
""" String representation of DVMeModel"""
if self.Ke == None:
return "\n< Extrapolating Growth Model g = %s\n \
\n< Cost of equity Ke = %s \n\
\n< Market value of the share Po = %s" % \
(self.g_extrapolatingModel,(self.costOfEquity+'%'),('$'+ str(self.share_price)))
else:
return "\n< Extrapolating Growth Model g = %s\n \
\n< Cost of equity Ke = %s \n\
\n< Market value of the share Po = %s" % \
(self.g_extrapolatingModel,self.Ke,('$'+ str(self.valueOfShare)))
class DVMgordonsModel(namedtuple('DVMgordonsModel','dividend_just_paid,return_on_equity,dividend_payout,share_price,Ke'),MyError):
""" DVMgModel class inherits from tuple and MyError classes """
#set __slots__ to an empty tuple keep memory requirements low
__slots__ = ()
#Pick Myerror method
_negativeNumberException =MyError._negativeNumberException
@property
def g_gordonsModel(self):
""" Compute g using Gordons growth Model """
try:
#Test for negative numbers input and raise the exception
self._negativeNumberException(self.return_on_equity,self.dividend_payout)
return self.return_on_equity * (1-self.dividend_payout)
#Raise TypeError if input is not numerical
except TypeError:
print "\n<The entered value is not a number"
@property
def valueOfShare(self):
""" Compute the share value """
try:
#Test for negative numbers input and raise the exception
self._negativeNumberException(self.dividend_just_paid,self.Ke)
return "%2.2f" % (((self.dividend_just_paid*
(1+float(self.g_gordonsModel)))/(self.Ke-self.g_gordonsModel)))
#Raise TypeError if input is not numerical
except TypeError:
print "\n<The entered value is not a number"
#division by zero raises ZeroDivisionError exception
except ZeroDivisionError:
raise ZeroDivisionError, "\n<Please check and re-enter the values"
@property
def costOfEquity(self):
""" Compute cost of equity using DVM Model """
try:
#Test for negative numbers input and raise the exception
self._negativeNumberException(self.dividend_just_paid,self.share_price)
return "%2.1f" % ((((self.dividend_just_paid*
(1+float(self.g_gordonsModel)))/(self.share_price))+ float(self.g_gordonsModel))*100 )
#Raise TypeError if input is not numerical
except TypeError:
print "\n<The entered value is not a number"
#division by zero raises ZeroDivisionError exception
except ZeroDivisionError:
raise ZeroDivisionError, "\n<Please check and re-enter the values"
def __str__(self):
""" String representation of DVMgModel"""
if self.Ke == None:
return "\n< Gordon's Growth Model g = %s\n \
\n< Cost of equity Ke = %s \n\
\n< Market value of the share Po = %s" % \
(self.g_gordonsModel,(self.costOfEquity+'%'),('$'+ str(self.share_price)))
else:
return "\n< Gordon's Growth Model g = %s\n \
\n< Cost of equity Ke = %s \n\
\n< Market value of the share Po = %s" % \
(self.g_gordonsModel,self.Ke,('$'+ str(self.valueOfShare)))
class CAPM(namedtuple('CAPM','Rf,Beta,Rm'),MyError):
""" CAPM class inherits from tuple and MyError class """
#set __slots__ to an empty tuple keep memory requirements low
__slots__ = ()
#Pick Myerror method
_negativeNumberException =MyError._negativeNumberException
@property
def Ke(self):
""" Compute cost of equity using CAPM model """
try:
#Test for negative numbers input and raise the exception
self._negativeNumberException(self.Rf,self.Beta,self.Rm)
return self.Rf + self.Beta*(self.Rm - self.Rf)
#Raise ValueError if input is not numerical
except TypeError:
print "\n<The entered value is not a number"
def __str__(self):
""" String representation of CAPM"""
return "\n< Ke = %s" % self.Ke+"%"
if __name__ == '__main__':
a = CAPM('Rf','Beta','Rm')
b = [7,0.7,17]
a = a._make(b)
print "\n"+"\4"*43
print a
print "\n"+"\4"*43
c = DVMextrapolating('dividend_just_paid','dividend_n_years','n','share_price','Ke')
d = [0.24,0.1525,4,None,a.Ke/100]
c = c._make(d)
print c
print "\n"+"\4"*43
e = DVMgordonsModel('dividend_just_paid','return_on_equity','dividend_payout','share_price','Ke')
f = [0.18,0.2,0.72,None,0.127]
e = e._make(f)
print e
print "\n"+"\4"*43
g = [0.25,0.17,7,17.50,None]
c = c._make(g)
print c
print "\n"+"\4"*43
h = [0.17,0.3,0.37,1.77,None]
e = e._make(h)
print e
print "\n"+"\4"*43
print
print c.g_extrapolatingModel
print c.costOfEquity
print e.g_gordonsModel
print e.costOfEquity
print "\n"+"\5"*43
m = [None,0.5,0.57,None,None]
e = e._make(m)
print e.g_gordonsModel
##########################################################################################
# c:\Python26>python "C:\Users\Fouad Teniou\Documents\python\DVM_Versus_CAPM7.py"
#♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦
#< Ke = 14.0%
#♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦
#< Extrapolating Growth Model g = 0.12
#< Cost of equity Ke = 0.14
#< Market value of the share Po = $13.44
#♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦
#< Gordon's Growth Model g = 0.056
#< Cost of equity Ke = 0.127
#< Market value of the share Po = $2.68
#♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦
#< Extrapolating Growth Model g = 0.06
#< Cost of equity Ke = 7.5%
#< Market value of the share Po = $17.5
#♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦
#< Gordon's Growth Model g = 0.189
#< Cost of equity Ke = 30.3%
#< Market value of the share Po = $1.77
#♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦♦
#0.06
#7.5
#0.189
#30.3
#♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣♣
#0.215
#c:\Python26>
|
Sign in to comment