summaryrefslogtreecommitdiff
path: root/backend/tests/test_dcf_advanced.py
blob: 20f6921e559db5427cb3a028b727382744ecc823 (plain)
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import pytest

from app.services.data_service import _run_dcf_explicit_build


_APPROX = pytest.approx


def test_run_dcf_explicit_build_two_year_reference_scenario() -> None:
    # Given
    base_revenue = 1_000.0

    # When
    result = _run_dcf_explicit_build(
        base_revenue=base_revenue,
        revenue_growth=[0.10, 0.05],
        ebitda_margin=[0.30, 0.32],
        dna_pct_revenue=[0.05, 0.05],
        capex_pct_revenue=[0.07, 0.07],
        nwc_chg_pct_delta_rev=[0.02, 0.02],
        tax_rate=[0.25, 0.25],
        wacc=0.10,
        terminal_growth=0.03,
        shares_outstanding=100.0,
        total_debt=50.0,
        cash=10.0,
        preferred_equity=5.0,
        minority_interest=3.0,
        projection_years=2,
    )

    # Then
    assert result["available"] is True
    assert result["base_fcf"] == _APPROX(184.25)
    assert result["fcf_pv_sum"] == _APPROX(357.42928814344134)
    assert result["terminal_value_pv"] == _APPROX(2_674.37743224556)
    assert result["enterprise_value"] == _APPROX(3_031.8067203890014)
    assert result["net_debt"] == 40.0
    assert result["equity_value"] == _APPROX(2_983.8067203890014)
    assert result["intrinsic_value_per_share"] == _APPROX(29.838067203890013)
    assert result["wacc"] == 0.10
    assert result["terminal_growth"] == 0.03
    assert result["projection_years"] == 2


def test_run_dcf_explicit_build_terminal_growth_at_wacc_returns_error() -> None:
    # Given / When
    result = _run_dcf_explicit_build(
        base_revenue=1_000.0,
        revenue_growth=[0.05],
        ebitda_margin=[0.30],
        dna_pct_revenue=[0.05],
        capex_pct_revenue=[0.07],
        nwc_chg_pct_delta_rev=[0.02],
        tax_rate=[0.25],
        wacc=0.10,
        terminal_growth=0.10,
        shares_outstanding=100.0,
        total_debt=0.0,
        cash=0.0,
        preferred_equity=0.0,
        minority_interest=0.0,
        projection_years=1,
    )

    # Then
    assert result["available"] is True
    assert "Terminal growth" in result["error"]
    assert "intrinsic_value_per_share" not in result


def test_run_dcf_explicit_build_zero_wacc_returns_error() -> None:
    # Given / When
    result = _run_dcf_explicit_build(
        base_revenue=1_000.0,
        revenue_growth=[0.05],
        ebitda_margin=[0.30],
        dna_pct_revenue=[0.05],
        capex_pct_revenue=[0.07],
        nwc_chg_pct_delta_rev=[0.02],
        tax_rate=[0.25],
        wacc=0.0,
        terminal_growth=0.03,
        shares_outstanding=100.0,
        total_debt=0.0,
        cash=0.0,
        preferred_equity=0.0,
        minority_interest=0.0,
        projection_years=1,
    )

    # Then
    assert result["available"] is True
    assert "WACC" in result["error"]
    assert "intrinsic_value_per_share" not in result


@pytest.mark.parametrize("shares_outstanding", [0.0, -1.0])
def test_run_dcf_explicit_build_nonpositive_shares_return_error(shares_outstanding: float) -> None:
    # Given / When
    result = _run_dcf_explicit_build(
        base_revenue=1_000.0,
        revenue_growth=[0.05],
        ebitda_margin=[0.30],
        dna_pct_revenue=[0.05],
        capex_pct_revenue=[0.07],
        nwc_chg_pct_delta_rev=[0.02],
        tax_rate=[0.25],
        wacc=0.10,
        terminal_growth=0.03,
        shares_outstanding=shares_outstanding,
        total_debt=0.0,
        cash=0.0,
        preferred_equity=0.0,
        minority_interest=0.0,
        projection_years=1,
    )

    # Then
    assert result["available"] is True
    assert "Shares outstanding" in result["error"]
    assert "intrinsic_value_per_share" not in result


def test_run_dcf_explicit_build_zero_base_revenue_returns_error() -> None:
    # Given / When
    result = _run_dcf_explicit_build(
        base_revenue=0.0,
        revenue_growth=[0.05],
        ebitda_margin=[0.30],
        dna_pct_revenue=[0.05],
        capex_pct_revenue=[0.07],
        nwc_chg_pct_delta_rev=[0.02],
        tax_rate=[0.25],
        wacc=0.10,
        terminal_growth=0.03,
        shares_outstanding=100.0,
        total_debt=0.0,
        cash=0.0,
        preferred_equity=0.0,
        minority_interest=0.0,
        projection_years=1,
    )

    # Then
    assert result["available"] is True
    assert "Base revenue" in result["error"]
    assert "intrinsic_value_per_share" not in result