Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,11 @@ import pandas as pd
|
|
2 |
import numpy as np
|
3 |
import gradio as gr
|
4 |
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
# Simple DCF Calculator Setup
|
7 |
def discounted_cash_flow(fcf, growth_rate, discount_rate, terminal_growth_rate, forecast_years=5):
|
@@ -24,7 +29,25 @@ def discounted_cash_flow(fcf, growth_rate, discount_rate, terminal_growth_rate,
|
|
24 |
|
25 |
return fcf_forecast, present_values, terminal_value, terminal_value_pv, total_value
|
26 |
|
27 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
fcf_forecast, present_values, terminal_value, terminal_value_pv, total_intrinsic_value = discounted_cash_flow(
|
29 |
fcf, growth_rate, discount_rate, terminal_growth_rate, forecast_years
|
30 |
)
|
@@ -42,17 +65,13 @@ def dcf_interface(fcf, growth_rate, discount_rate, terminal_growth_rate, forecas
|
|
42 |
ax.set_ylabel('Free Cash Flow ($)')
|
43 |
ax.grid(True)
|
44 |
|
45 |
-
summary =
|
46 |
-
🏦 Total Intrinsic Value Estimate: ${total_intrinsic_value:,.2f}
|
47 |
-
Terminal Value (undiscounted): ${terminal_value:,.2f}
|
48 |
-
Present Value of Terminal Value: ${terminal_value_pv:,.2f}
|
49 |
-
"""
|
50 |
return df, fig, summary
|
51 |
|
52 |
iface = gr.Interface(
|
53 |
fn=dcf_interface,
|
54 |
inputs=[
|
55 |
-
gr.
|
56 |
gr.Number(label="Annual Growth Rate (e.g., 0.06 for 6%)"),
|
57 |
gr.Number(label="Discount Rate (e.g., 0.08 for 8%)"),
|
58 |
gr.Number(label="Terminal Growth Rate (e.g., 0.025 for 2.5%)"),
|
@@ -61,14 +80,14 @@ iface = gr.Interface(
|
|
61 |
outputs=[
|
62 |
gr.Dataframe(label="DCF Forecast Table"),
|
63 |
gr.Plot(label="Free Cash Flow Forecast Chart"),
|
64 |
-
gr.Textbox(label="Summary")
|
65 |
],
|
66 |
examples=[
|
67 |
-
[
|
68 |
],
|
69 |
-
title="DCF Valuation Calculator",
|
70 |
-
description="
|
71 |
)
|
72 |
|
73 |
if __name__ == "__main__":
|
74 |
-
iface.launch()
|
|
|
2 |
import numpy as np
|
3 |
import gradio as gr
|
4 |
import matplotlib.pyplot as plt
|
5 |
+
import yfinance as yf
|
6 |
+
from transformers import pipeline
|
7 |
+
|
8 |
+
# Initialize Summarizer
|
9 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
10 |
|
11 |
# Simple DCF Calculator Setup
|
12 |
def discounted_cash_flow(fcf, growth_rate, discount_rate, terminal_growth_rate, forecast_years=5):
|
|
|
29 |
|
30 |
return fcf_forecast, present_values, terminal_value, terminal_value_pv, total_value
|
31 |
|
32 |
+
def get_company_fcf(symbol):
|
33 |
+
ticker = yf.Ticker(symbol)
|
34 |
+
try:
|
35 |
+
cashflow = ticker.cashflow
|
36 |
+
fcf = cashflow.loc['Total Cash From Operating Activities'][0] - cashflow.loc['Capital Expenditures'][0]
|
37 |
+
return fcf
|
38 |
+
except Exception:
|
39 |
+
return None
|
40 |
+
|
41 |
+
def generate_summary(symbol, intrinsic_value):
|
42 |
+
text = f"Based on a DCF analysis, the intrinsic value of {symbol} is estimated to be ${intrinsic_value:,.2f}."
|
43 |
+
summary = summarizer(text, max_length=100, min_length=30, do_sample=False)[0]['summary_text']
|
44 |
+
return summary
|
45 |
+
|
46 |
+
def dcf_interface(symbol, growth_rate, discount_rate, terminal_growth_rate, forecast_years):
|
47 |
+
fcf = get_company_fcf(symbol)
|
48 |
+
if fcf is None:
|
49 |
+
return "Error fetching financial data. Please check the symbol or try another company.", None, None
|
50 |
+
|
51 |
fcf_forecast, present_values, terminal_value, terminal_value_pv, total_intrinsic_value = discounted_cash_flow(
|
52 |
fcf, growth_rate, discount_rate, terminal_growth_rate, forecast_years
|
53 |
)
|
|
|
65 |
ax.set_ylabel('Free Cash Flow ($)')
|
66 |
ax.grid(True)
|
67 |
|
68 |
+
summary = generate_summary(symbol, total_intrinsic_value)
|
|
|
|
|
|
|
|
|
69 |
return df, fig, summary
|
70 |
|
71 |
iface = gr.Interface(
|
72 |
fn=dcf_interface,
|
73 |
inputs=[
|
74 |
+
gr.Textbox(label="Stock Symbol (e.g., AAPL)"),
|
75 |
gr.Number(label="Annual Growth Rate (e.g., 0.06 for 6%)"),
|
76 |
gr.Number(label="Discount Rate (e.g., 0.08 for 8%)"),
|
77 |
gr.Number(label="Terminal Growth Rate (e.g., 0.025 for 2.5%)"),
|
|
|
80 |
outputs=[
|
81 |
gr.Dataframe(label="DCF Forecast Table"),
|
82 |
gr.Plot(label="Free Cash Flow Forecast Chart"),
|
83 |
+
gr.Textbox(label="AI Summary")
|
84 |
],
|
85 |
examples=[
|
86 |
+
["AAPL", 0.06, 0.08, 0.025, 5]
|
87 |
],
|
88 |
+
title="AI-Powered DCF Valuation Calculator",
|
89 |
+
description="Enter a stock symbol and your assumptions. The app pulls live data, runs a DCF, and generates a research summary."
|
90 |
)
|
91 |
|
92 |
if __name__ == "__main__":
|
93 |
+
iface.launch()
|