-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stock.py
29 lines (26 loc) · 1.19 KB
/
Stock.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
from StockEnums import SSymbol,SType
#define class of Stock
class Stock(object):
def __init__(self, stockSymbol,Type,lastDividend,fixedDividend,parValue):
self.stockSymbol = stockSymbol
self.Type = Type
self.lastDividend = lastDividend
self.fixedDividend = fixedDividend
self.parValue = parValue
self.flagprice = 1 #used for optimization for calculating the geometric mean(check StoreTrade.py for details)
self.cnt = 0 #also used for optimization for calculating the geometric mean(check StoreTrade.py for details)
#calculate divendyield for a given price
def calcDivendyield(self,price):
try:
if SType(self.Type).name=="Common":
return self.lastDividend/price
elif SType(self.Type).name=="Preferred":
return ((self.fixedDividend/100)*self.parValue)/price
except ZeroDivisionError:
return float('Inf')
#calculate the P/E Ratio for a given price
def calcperatio(self,price):
try:
return price/self.calcDivendyield(price)
except ZeroDivisionError:
return float('Inf')