Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -269,6 +269,33 @@ def run_all_steps(ticker):
|
|
269 |
shares_outstanding, discount_rate, current_price)
|
270 |
|
271 |
fig_cash_forecast = plot_forecasted_cash_flows(ticker, forecast_cash_flows_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
|
273 |
return q_cash_flow_statement.reset_index(), final_cash_flow_statement.reset_index(), q_balance_statement.reset_index(), fig_cash_flow, \
|
274 |
str(EPS_growth_5Y) + '%', str(EPS_growth_6Y_to_10Y) + '%', str(long_term_growth_rate) + '%', \
|
@@ -293,7 +320,14 @@ with gr.Blocks() as app:
|
|
293 |
intrinsic_value = gr.Text(label="Intrinsic Value (if this value is negative, it means current cash flow may be negative and this model WOULD NOT WORK, scroll down to check)")
|
294 |
current_price = gr.Text(label="Actual Stock Price")
|
295 |
margin_of_safety = gr.Text(label="Margin of Safety")
|
296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
# Show metrics obtained and estimated from FinViz website that were essential for calculations
|
298 |
with gr.Row():
|
299 |
gr.HTML("<h2>Metrics Obtained (and Estimated) from FinViz Website</h2>")
|
@@ -348,11 +382,11 @@ with gr.Blocks() as app:
|
|
348 |
btn.click(fn=run_all_steps, inputs=[ticker],
|
349 |
outputs=[q_cash_flow_statement, final_cash_flow_statement, q_balance_statement, fig_cash_flow, \
|
350 |
EPS_growth_5Y, EPS_growth_6Y_to_10Y, long_term_growth_rate, beta, shares_outstanding, current_price, \
|
351 |
-
discount_rate, forecast_cash_flows_df, terminal_value, intrinsic_value, fig_cash_forecast, margin_of_safety])
|
352 |
|
353 |
ticker.submit(fn=run_all_steps, inputs=[ticker],
|
354 |
outputs=[q_cash_flow_statement, final_cash_flow_statement, q_balance_statement, fig_cash_flow, \
|
355 |
EPS_growth_5Y, EPS_growth_6Y_to_10Y, long_term_growth_rate, beta, shares_outstanding, current_price, \
|
356 |
-
discount_rate, forecast_cash_flows_df, terminal_value, intrinsic_value, fig_cash_forecast, margin_of_safety])
|
357 |
|
358 |
app.launch()
|
|
|
269 |
shares_outstanding, discount_rate, current_price)
|
270 |
|
271 |
fig_cash_forecast = plot_forecasted_cash_flows(ticker, forecast_cash_flows_df)
|
272 |
+
|
273 |
+
# Discount rate and long term growth rate can change intrinsic value significantly
|
274 |
+
# So we estimate the intrinsic values for the different discount rates and long term growth rates below and store them in a DataFrame
|
275 |
+
discount_rates = [discount_rate-2, discount_rate-1.5,
|
276 |
+
discount_rate-1, discount_rate-0.5,
|
277 |
+
discount_rate,
|
278 |
+
discount_rate+0.5, discount_rate+1,
|
279 |
+
discount_rate+1.5, discount_rate+2]
|
280 |
+
|
281 |
+
long_term_growth_rates = [long_term_growth_rate-1, long_term_growth_rate-0.5,
|
282 |
+
long_term_growth_rate,
|
283 |
+
long_term_growth_rate+0.5, long_term_growth_rate+1]
|
284 |
+
|
285 |
+
|
286 |
+
intrinsic_values = {}
|
287 |
+
for dr in discount_rates:
|
288 |
+
intrinsic_values[dr] = {}
|
289 |
+
for lr in long_term_growth_rates:
|
290 |
+
_, _, intrinsic_value, _ = calculate_intrinsic_value(latest_year, cash_flow, total_debt, cash_and_ST_investments,
|
291 |
+
EPS_growth_5Y, EPS_growth_6Y_to_10Y, lr,
|
292 |
+
shares_outstanding, dr, current_price)
|
293 |
+
intrinsic_values[dr][lr] = intrinsic_value
|
294 |
+
|
295 |
+
df_intrinsic_values = pd.DataFrame(intrinsic_values).T
|
296 |
+
df_intrinsic_values.index.name = 'Discount Rates'
|
297 |
+
df_intrinsic_values = df_intrinsic_values.reset_index()
|
298 |
+
|
299 |
|
300 |
return q_cash_flow_statement.reset_index(), final_cash_flow_statement.reset_index(), q_balance_statement.reset_index(), fig_cash_flow, \
|
301 |
str(EPS_growth_5Y) + '%', str(EPS_growth_6Y_to_10Y) + '%', str(long_term_growth_rate) + '%', \
|
|
|
320 |
intrinsic_value = gr.Text(label="Intrinsic Value (if this value is negative, it means current cash flow may be negative and this model WOULD NOT WORK, scroll down to check)")
|
321 |
current_price = gr.Text(label="Actual Stock Price")
|
322 |
margin_of_safety = gr.Text(label="Margin of Safety")
|
323 |
+
|
324 |
+
# Discount rate and long term growth rate can change intrinsic value significantly, so we show all of the estimates here
|
325 |
+
with gr.Row():
|
326 |
+
gr.HTML("<h2>Intrinsic Values with Different Discount Rates (in Rows) Long Term Growth Rates (in Columns)</h2>")
|
327 |
+
with gr.Row():
|
328 |
+
df_intrinsic_values = gr.DataFrame(label="Intrinsic Values with Different Discount Rates/Long Term Growth Rates")
|
329 |
+
|
330 |
+
|
331 |
# Show metrics obtained and estimated from FinViz website that were essential for calculations
|
332 |
with gr.Row():
|
333 |
gr.HTML("<h2>Metrics Obtained (and Estimated) from FinViz Website</h2>")
|
|
|
382 |
btn.click(fn=run_all_steps, inputs=[ticker],
|
383 |
outputs=[q_cash_flow_statement, final_cash_flow_statement, q_balance_statement, fig_cash_flow, \
|
384 |
EPS_growth_5Y, EPS_growth_6Y_to_10Y, long_term_growth_rate, beta, shares_outstanding, current_price, \
|
385 |
+
discount_rate, forecast_cash_flows_df, terminal_value, intrinsic_value, fig_cash_forecast, margin_of_safety, df_intrinsic_values])
|
386 |
|
387 |
ticker.submit(fn=run_all_steps, inputs=[ticker],
|
388 |
outputs=[q_cash_flow_statement, final_cash_flow_statement, q_balance_statement, fig_cash_flow, \
|
389 |
EPS_growth_5Y, EPS_growth_6Y_to_10Y, long_term_growth_rate, beta, shares_outstanding, current_price, \
|
390 |
+
discount_rate, forecast_cash_flows_df, terminal_value, intrinsic_value, fig_cash_forecast, margin_of_safety, df_intrinsic_values])
|
391 |
|
392 |
app.launch()
|