Spaces:
Running
Running
Commit
·
d77ae08
1
Parent(s):
ac64c34
Update app.py
Browse files
app.py
CHANGED
@@ -67,8 +67,112 @@ def get_income_hvplot(ticker):
|
|
67 |
# return ( DF.hvplot.line(y='Net Income') * DF.hvplot.scatter(y='Net Income').opts(color="red") )+ (DF.hvplot.line(y='Gross Profit') * DF.hvplot.scatter(y='Gross Profit').opts(color="red") )+
|
68 |
# (DF.hvplot.line(y='Total Revenue') * DF.hvplot.scatter(y='Total Revenue').opts(color="red") )
|
69 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
70 |
|
|
|
|
|
71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
# tickers = ['AAPL', 'META', 'GOOG', 'IBM', 'MSFT','NKE','DLTR','DG']
|
74 |
# ticker = pn.widgets.Select(name='Ticker', options=tickers)
|
|
|
67 |
# return ( DF.hvplot.line(y='Net Income') * DF.hvplot.scatter(y='Net Income').opts(color="red") )+ (DF.hvplot.line(y='Gross Profit') * DF.hvplot.scatter(y='Gross Profit').opts(color="red") )+
|
68 |
# (DF.hvplot.line(y='Total Revenue') * DF.hvplot.scatter(y='Total Revenue').opts(color="red") )
|
69 |
|
70 |
+
def lookup_discountedrate(betavalue):
|
71 |
+
betavsdiscountedrate = {1: 5, 1: 6, 1.1: 6.5, 1.2: 7, 1.3: 7.5, 1.4: 8, 1.5: 8.5, 1.6: 9}
|
72 |
+
if betavalue < 1:
|
73 |
+
return betavsdiscountedrate[1] # Return the value for key 1 if key is below 1
|
74 |
+
elif betavalue > 1.6:
|
75 |
+
return betavsdiscountedrate[1.6] # Return the value for key 1.6 if key is above 1.6
|
76 |
+
else:
|
77 |
+
# Find the closest key to the given key
|
78 |
+
closest_key = min(betavsdiscountedrate.keys(), key=lambda x: abs(x - betavalue))
|
79 |
|
80 |
+
# Get the corresponding value
|
81 |
+
value = betavsdiscountedrate[closest_key]
|
82 |
|
83 |
+
return value
|
84 |
+
|
85 |
+
|
86 |
+
def calc_fairprice_CDF(ticker):
|
87 |
+
import yfinance as yf
|
88 |
+
yfobj = yf.Ticker(ticker)
|
89 |
+
|
90 |
+
#calculate eps growing next 5 years
|
91 |
+
EPSnext5Y = yfobj.get_info()['trailingPE'] / yfobj.get_info()['trailingPegRatio']
|
92 |
+
|
93 |
+
years = 10
|
94 |
+
#
|
95 |
+
cashflowinitial = yfobj.get_info()['operatingCashflow']
|
96 |
+
|
97 |
+
cashflowlst=[]
|
98 |
+
cashflow = cashflowinitial
|
99 |
+
for i in range(1,years+1):
|
100 |
+
cashflow = cashflow*(1+EPSnext5Y/100)
|
101 |
+
cashflowlst.append(cashflow)
|
102 |
+
|
103 |
+
discountedrate = lookup_discountedrate(yfobj.get_info()['beta'])
|
104 |
+
|
105 |
+
discountedfactorlst =[]
|
106 |
+
discountedvaluelst=[]
|
107 |
+
discountedfactor =1
|
108 |
+
|
109 |
+
for i in range(1,years+1):
|
110 |
+
discountedfactor =( 1 / (1+ discountedrate/100)**i)
|
111 |
+
discountedfactorlst.append(discountedfactor)
|
112 |
+
discountedvalue = discountedfactor * cashflowlst[i-1]
|
113 |
+
discountedvaluelst.append(discountedvalue)
|
114 |
+
|
115 |
+
PV10yearsCashFlow =0
|
116 |
+
for i in range(0,years):
|
117 |
+
PV10yearsCashFlow += discountedvaluelst[i]
|
118 |
+
|
119 |
+
#intrinsic value before cash/debt
|
120 |
+
intrinsicvaluebeforecashdebt = PV10yearsCashFlow / yfobj.get_info()['sharesOutstanding']
|
121 |
+
|
122 |
+
debtpershare = yfobj.get_info()['totalDebt'] / yfobj.get_info()['sharesOutstanding']
|
123 |
+
cashpershare = yfobj.get_info()['totalCash'] / yfobj.get_info()['sharesOutstanding']
|
124 |
+
intrinsicvalue = intrinsicvaluebeforecashdebt + cashpershare - debtpershare
|
125 |
+
|
126 |
+
previousClose = yfobj.get_info()['previousClose']
|
127 |
+
deviation = 100*(intrinsicvalue - previousClose) / previousClose
|
128 |
+
return intrinsicvalue , previousClose , deviation
|
129 |
+
|
130 |
+
|
131 |
+
def calc_fairprice_DnetP(ticker):
|
132 |
+
import yfinance as yf
|
133 |
+
yfobj = yf.Ticker(ticker)
|
134 |
+
|
135 |
+
#calculate eps growing next 5 years
|
136 |
+
EPSnext5Y = yfobj.get_info()['trailingPE'] / yfobj.get_info()['trailingPegRatio']
|
137 |
+
|
138 |
+
years = 5
|
139 |
+
#
|
140 |
+
cashflowinitial = yfobj.get_info()['netIncomeToCommon']
|
141 |
+
|
142 |
+
cashflowlst=[]
|
143 |
+
cashflow = cashflowinitial
|
144 |
+
for i in range(1,years+1):
|
145 |
+
cashflow = cashflow*(1+EPSnext5Y/100)
|
146 |
+
cashflowlst.append(cashflow)
|
147 |
+
|
148 |
+
discountedrate = lookup_discountedrate(yfobj.get_info()['beta'])
|
149 |
+
|
150 |
+
discountedfactorlst =[]
|
151 |
+
discountedvaluelst=[]
|
152 |
+
discountedfactor =1
|
153 |
+
|
154 |
+
for i in range(1,years+1):
|
155 |
+
discountedfactor =( 1 / (1+ discountedrate/100)**i)
|
156 |
+
discountedfactorlst.append(discountedfactor)
|
157 |
+
discountedvalue = discountedfactor * cashflowlst[i-1]
|
158 |
+
discountedvaluelst.append(discountedvalue)
|
159 |
+
|
160 |
+
PV10yearsCashFlow =0
|
161 |
+
for i in range(0,years):
|
162 |
+
PV10yearsCashFlow += discountedvaluelst[i]
|
163 |
+
|
164 |
+
#intrinsic value before cash/debt
|
165 |
+
intrinsicvaluebeforecashdebt = PV10yearsCashFlow / yfobj.get_info()['sharesOutstanding']
|
166 |
+
|
167 |
+
debtpershare = yfobj.get_info()['totalDebt'] / yfobj.get_info()['sharesOutstanding']
|
168 |
+
cashpershare = yfobj.get_info()['totalCash'] / yfobj.get_info()['sharesOutstanding']
|
169 |
+
intrinsicvalue = intrinsicvaluebeforecashdebt + cashpershare - debtpershare
|
170 |
+
|
171 |
+
previousClose = yfobj.get_info()['previousClose']
|
172 |
+
intrinsicvalue= intrinsicvalue + previousClose
|
173 |
+
|
174 |
+
deviation = 100*(intrinsicvalue - previousClose) / previousClose
|
175 |
+
return intrinsicvalue , previousClose , deviation
|
176 |
|
177 |
# tickers = ['AAPL', 'META', 'GOOG', 'IBM', 'MSFT','NKE','DLTR','DG']
|
178 |
# ticker = pn.widgets.Select(name='Ticker', options=tickers)
|