Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -54,8 +54,12 @@ def get_financial_statements(ticker):
|
|
54 |
q_balance_statement = pd.DataFrame(get_jsonparsed_data(base_url+'balance-sheet-statement/' + ticker + '?period=quarter' + '&apikey=' + apiKey))
|
55 |
q_balance_statement = q_balance_statement.set_index('date').drop(columns_drop, axis=1)
|
56 |
q_balance_statement = q_balance_statement.apply(pd.to_numeric, errors='coerce')
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
return q_cash_flow_statement, cash_flow_statement, final_cash_flow_statement, q_balance_statement, latest_year
|
59 |
|
60 |
|
61 |
# check stability of cash flows
|
@@ -90,7 +94,7 @@ def get_statements_data(final_cash_flow_statement, q_balance_statement):
|
|
90 |
# EPS next 5Y is the estimated earnings growth for next 5 years (if this is not present on finviz, we will use EPS next Y instead)
|
91 |
# Beta captures the volatility of the stock, used for estimating discount rate later
|
92 |
# Shs Outstand is the number of shares present in the market
|
93 |
-
metric = ['Price', 'EPS next Y', 'EPS next 5Y', 'Beta'
|
94 |
|
95 |
def fundamental_metric(soup, metric):
|
96 |
# the table which stores the data in Finviz has html table attribute class of 'snapshot-td2'
|
@@ -136,35 +140,33 @@ def parse_finviz_dict(finviz_dict):
|
|
136 |
EPS_growth_6Y_to_10Y = EPS_growth_5Y/2 # Half the previous growth rate, conservative estimate
|
137 |
# Long term = previous growth rate or around long term inflation rate, whichever is lower to be conservative estimate
|
138 |
long_term_growth_rate = np.minimum(EPS_growth_6Y_to_10Y, 3)
|
139 |
-
shares_outstanding = finviz_dict['Shs Outstand']
|
140 |
beta = finviz_dict['Beta']
|
141 |
current_price = finviz_dict['Price']
|
142 |
|
143 |
-
return EPS_growth_5Y, EPS_growth_6Y_to_10Y, long_term_growth_rate, beta,
|
144 |
|
145 |
|
146 |
## Estimate Discount Rate from Beta
|
147 |
def estimate_discount_rate(beta):
|
148 |
# Beta shows the volatility of the stock,
|
149 |
# the higher the beta, we want to be more conservative by increasing the discount rate also.
|
150 |
-
discount_rate =
|
151 |
if(beta<0.80):
|
152 |
-
discount_rate =
|
153 |
elif(beta>=0.80 and beta<1):
|
154 |
-
discount_rate =
|
155 |
elif(beta>=1 and beta<1.1):
|
156 |
-
discount_rate =
|
157 |
elif(beta>=1.1 and beta<1.2):
|
158 |
-
discount_rate =
|
159 |
elif(beta>=1.2 and beta<1.3):
|
160 |
-
discount_rate =
|
161 |
elif(beta>=1.3 and beta<1.4):
|
162 |
-
discount_rate =
|
163 |
elif(beta>=1.4 and beta<1.6):
|
164 |
-
discount_rate =
|
165 |
elif(beta>=1.61):
|
166 |
-
discount_rate =
|
167 |
-
|
168 |
return discount_rate
|
169 |
|
170 |
|
@@ -285,7 +287,7 @@ def plot_forecasted_cash_flows(ticker, forecast_cash_flows_df):
|
|
285 |
def run_all_steps(ticker):
|
286 |
ticker = ticker.upper() # make sure ticker is caps
|
287 |
|
288 |
-
q_cash_flow_statement, cash_flow_statement, final_cash_flow_statement, q_balance_statement, latest_year = get_financial_statements(ticker)
|
289 |
|
290 |
fig_cash_flow = plot_cash_flow(ticker, cash_flow_statement)
|
291 |
|
@@ -293,7 +295,7 @@ def run_all_steps(ticker):
|
|
293 |
|
294 |
finviz_dict = get_finviz_data(ticker)
|
295 |
|
296 |
-
EPS_growth_5Y, EPS_growth_6Y_to_10Y, long_term_growth_rate, beta,
|
297 |
|
298 |
discount_rate = estimate_discount_rate(beta)
|
299 |
|
|
|
54 |
q_balance_statement = pd.DataFrame(get_jsonparsed_data(base_url+'balance-sheet-statement/' + ticker + '?period=quarter' + '&apikey=' + apiKey))
|
55 |
q_balance_statement = q_balance_statement.set_index('date').drop(columns_drop, axis=1)
|
56 |
q_balance_statement = q_balance_statement.apply(pd.to_numeric, errors='coerce')
|
57 |
+
|
58 |
+
# shares outstanding
|
59 |
+
shs_data = get_jsonparsed_data('https://financialmodelingprep.com/api/v4/shares_float?symbol=' + ticker + '&apikey=' + apiKey)
|
60 |
+
shares_outstanding = shs_data[0]['outstandingShares']
|
61 |
|
62 |
+
return q_cash_flow_statement, cash_flow_statement, final_cash_flow_statement, q_balance_statement, latest_year, shares_outstanding
|
63 |
|
64 |
|
65 |
# check stability of cash flows
|
|
|
94 |
# EPS next 5Y is the estimated earnings growth for next 5 years (if this is not present on finviz, we will use EPS next Y instead)
|
95 |
# Beta captures the volatility of the stock, used for estimating discount rate later
|
96 |
# Shs Outstand is the number of shares present in the market
|
97 |
+
metric = ['Price', 'EPS next Y', 'EPS next 5Y', 'Beta']
|
98 |
|
99 |
def fundamental_metric(soup, metric):
|
100 |
# the table which stores the data in Finviz has html table attribute class of 'snapshot-td2'
|
|
|
140 |
EPS_growth_6Y_to_10Y = EPS_growth_5Y/2 # Half the previous growth rate, conservative estimate
|
141 |
# Long term = previous growth rate or around long term inflation rate, whichever is lower to be conservative estimate
|
142 |
long_term_growth_rate = np.minimum(EPS_growth_6Y_to_10Y, 3)
|
|
|
143 |
beta = finviz_dict['Beta']
|
144 |
current_price = finviz_dict['Price']
|
145 |
|
146 |
+
return EPS_growth_5Y, EPS_growth_6Y_to_10Y, long_term_growth_rate, beta, current_price
|
147 |
|
148 |
|
149 |
## Estimate Discount Rate from Beta
|
150 |
def estimate_discount_rate(beta):
|
151 |
# Beta shows the volatility of the stock,
|
152 |
# the higher the beta, we want to be more conservative by increasing the discount rate also.
|
153 |
+
discount_rate = 9
|
154 |
if(beta<0.80):
|
155 |
+
discount_rate = 7
|
156 |
elif(beta>=0.80 and beta<1):
|
157 |
+
discount_rate = 8
|
158 |
elif(beta>=1 and beta<1.1):
|
159 |
+
discount_rate = 8.5
|
160 |
elif(beta>=1.1 and beta<1.2):
|
161 |
+
discount_rate = 9
|
162 |
elif(beta>=1.2 and beta<1.3):
|
163 |
+
discount_rate = 9.5
|
164 |
elif(beta>=1.3 and beta<1.4):
|
165 |
+
discount_rate = 10
|
166 |
elif(beta>=1.4 and beta<1.6):
|
167 |
+
discount_rate = 10.5
|
168 |
elif(beta>=1.61):
|
169 |
+
discount_rate = 11
|
|
|
170 |
return discount_rate
|
171 |
|
172 |
|
|
|
287 |
def run_all_steps(ticker):
|
288 |
ticker = ticker.upper() # make sure ticker is caps
|
289 |
|
290 |
+
q_cash_flow_statement, cash_flow_statement, final_cash_flow_statement, q_balance_statement, latest_year, shares_outstanding = get_financial_statements(ticker)
|
291 |
|
292 |
fig_cash_flow = plot_cash_flow(ticker, cash_flow_statement)
|
293 |
|
|
|
295 |
|
296 |
finviz_dict = get_finviz_data(ticker)
|
297 |
|
298 |
+
EPS_growth_5Y, EPS_growth_6Y_to_10Y, long_term_growth_rate, beta, current_price = parse_finviz_dict(finviz_dict)
|
299 |
|
300 |
discount_rate = estimate_discount_rate(beta)
|
301 |
|