bohmian commited on
Commit
bda9bfa
·
1 Parent(s): c942045

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -26
app.py CHANGED
@@ -234,6 +234,39 @@ def calculate_intrinsic_value(latest_year, cash_flow, total_debt, cash_and_ST_in
234
  margin_of_safety = (1-current_price/intrinsic_value)*100
235
 
236
  return forecast_cash_flows_df, terminal_value, intrinsic_value, margin_of_safety
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
 
238
 
239
  # Plot forecasted cash flows from years 1 to 10, as well as the discounted cash flows
@@ -270,37 +303,15 @@ def run_all_steps(ticker):
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) + '%', \
302
  beta, shares_outstanding, current_price, \
303
- str(discount_rate) + '%', forecast_cash_flows_df.reset_index(), terminal_value, intrinsic_value, fig_cash_forecast, str(margin_of_safety) + '%'
304
 
305
 
306
  # Gradio App and UI
 
234
  margin_of_safety = (1-current_price/intrinsic_value)*100
235
 
236
  return forecast_cash_flows_df, terminal_value, intrinsic_value, margin_of_safety
237
+
238
+
239
+ # Discount rate and long term growth rate can change intrinsic value significantly
240
+ # So we estimate the intrinsic values for the different discount rates and long term growth rates below and store them in a DataFrame
241
+ def calculate_multiple_intrinsic_values(latest_year, cash_flow, total_debt, cash_and_ST_investments,
242
+ EPS_growth_5Y, EPS_growth_6Y_to_10Y, long_term_growth_rate,
243
+ shares_outstanding, discount_rate, current_price):
244
+
245
+ discount_rates = [discount_rate-2, discount_rate-1.5,
246
+ discount_rate-1, discount_rate-0.5,
247
+ discount_rate,
248
+ discount_rate+0.5, discount_rate+1,
249
+ discount_rate+1.5, discount_rate+2]
250
+
251
+ long_term_growth_rates = [long_term_growth_rate-1, long_term_growth_rate-0.5,
252
+ long_term_growth_rate,
253
+ long_term_growth_rate+0.5, long_term_growth_rate+1]
254
+
255
+
256
+ intrinsic_values = {}
257
+ for dr in discount_rates:
258
+ intrinsic_values[dr] = {}
259
+ for lr in long_term_growth_rates:
260
+ _, _, intrinsic_value, _ = calculate_intrinsic_value(latest_year, cash_flow, total_debt, cash_and_ST_investments,
261
+ EPS_growth_5Y, EPS_growth_6Y_to_10Y, lr,
262
+ shares_outstanding, dr, current_price)
263
+ intrinsic_values[dr][lr] = intrinsic_value
264
+
265
+ df_intrinsic_values = pd.DataFrame(intrinsic_values).T
266
+ df_intrinsic_values.index.name = 'Discount Rates'
267
+ df_intrinsic_values = df_intrinsic_values.reset_index()
268
+
269
+ return df_intrinsic_values
270
 
271
 
272
  # Plot forecasted cash flows from years 1 to 10, as well as the discounted cash flows
 
303
 
304
  fig_cash_forecast = plot_forecasted_cash_flows(ticker, forecast_cash_flows_df)
305
 
306
+ df_intrinsic_values = calculate_multiple_intrinsic_values(latest_year, cash_flow, total_debt, cash_and_ST_investments,
307
+ EPS_growth_5Y, EPS_growth_6Y_to_10Y, long_term_growth_rate,
308
+ shares_outstanding, discount_rate, current_price)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
309
 
310
 
311
  return q_cash_flow_statement.reset_index(), final_cash_flow_statement.reset_index(), q_balance_statement.reset_index(), fig_cash_flow, \
312
  str(EPS_growth_5Y) + '%', str(EPS_growth_6Y_to_10Y) + '%', str(long_term_growth_rate) + '%', \
313
  beta, shares_outstanding, current_price, \
314
+ str(discount_rate) + '%', forecast_cash_flows_df.reset_index(), terminal_value, intrinsic_value, fig_cash_forecast, str(margin_of_safety) + '%', df_intrinsic_values
315
 
316
 
317
  # Gradio App and UI