File size: 2,748 Bytes
78f6302
 
 
6656d33
78f6302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90b4c40
78f6302
 
 
6656d33
 
 
 
 
78f6302
90b4c40
6656d33
 
 
 
 
 
78f6302
90b4c40
 
 
 
 
6656d33
78f6302
 
 
 
90b4c40
78f6302
 
 
 
 
6656d33
 
 
90b4c40
6656d33
 
90b4c40
6656d33
90b4c40
 
78f6302
 
 
27fa885
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import pandas as pd
import numpy as np
import gradio as gr
import matplotlib.pyplot as plt

# Simple DCF Calculator Setup
def discounted_cash_flow(fcf, growth_rate, discount_rate, terminal_growth_rate, forecast_years=5):
    fcf_forecast = []
    present_values = []

    for year in range(1, forecast_years + 1):
        fcf_year = fcf * ((1 + growth_rate) ** year)
        discount_factor = (1 + discount_rate) ** year
        present_value = fcf_year / discount_factor

        fcf_forecast.append(fcf_year)
        present_values.append(present_value)

    # Terminal Value Calculation (after final year)
    terminal_value = (fcf_forecast[-1] * (1 + terminal_growth_rate)) / (discount_rate - terminal_growth_rate)
    terminal_value_pv = terminal_value / ((1 + discount_rate) ** forecast_years)

    total_value = sum(present_values) + terminal_value_pv

    return fcf_forecast, present_values, terminal_value, terminal_value_pv, total_value

def dcf_interface(fcf, growth_rate, discount_rate, terminal_growth_rate, forecast_years):
    fcf_forecast, present_values, terminal_value, terminal_value_pv, total_intrinsic_value = discounted_cash_flow(
        fcf, growth_rate, discount_rate, terminal_growth_rate, forecast_years
    )
    df = pd.DataFrame({
        'Year': list(range(1, forecast_years + 1)),
        'Forecasted FCF ($)': fcf_forecast,
        'Present Value of FCF ($)': present_values
    })

    # Plot FCF
    fig, ax = plt.subplots()
    ax.plot(df['Year'], df['Forecasted FCF ($)'], marker='o')
    ax.set_title('Forecasted Free Cash Flow Over Time')
    ax.set_xlabel('Year')
    ax.set_ylabel('Free Cash Flow ($)')
    ax.grid(True)

    summary = f"""
🏦 Total Intrinsic Value Estimate: ${total_intrinsic_value:,.2f}
Terminal Value (undiscounted): ${terminal_value:,.2f}
Present Value of Terminal Value: ${terminal_value_pv:,.2f}
"""
    return df, fig, summary

iface = gr.Interface(
    fn=dcf_interface,
    inputs=[
        gr.Number(label="Initial Free Cash Flow ($)"),
        gr.Number(label="Annual Growth Rate (e.g., 0.06 for 6%)"),
        gr.Number(label="Discount Rate (e.g., 0.08 for 8%)"),
        gr.Number(label="Terminal Growth Rate (e.g., 0.025 for 2.5%)"),
        gr.Number(label="Forecast Years (e.g., 5 or 10)")
    ],
    outputs=[
        gr.Dataframe(label="DCF Forecast Table"),
        gr.Plot(label="Free Cash Flow Forecast Chart"),
        gr.Textbox(label="Summary")
    ],
    examples=[
        [100_560_000_000, 0.06, 0.08, 0.025, 5]  # Example: Apple
    ],
    title="DCF Valuation Calculator",
    description="Estimate a company's intrinsic value using Discounted Cash Flow (DCF) analysis. Adjust inputs or run a preset example."
)

if __name__ == "__main__":
    iface.launch()