diff options
Diffstat (limited to 'backend')
| -rw-r--r-- | backend/app/schemas.py | 1 | ||||
| -rw-r--r-- | backend/app/services/data_service.py | 5 | ||||
| -rw-r--r-- | backend/tests/test_api.py | 30 |
3 files changed, 34 insertions, 2 deletions
diff --git a/backend/app/schemas.py b/backend/app/schemas.py index 2c64333..c84b4c6 100644 --- a/backend/app/schemas.py +++ b/backend/app/schemas.py @@ -143,6 +143,7 @@ class DcfResult(BaseModel): base_fcf: float | None = None wacc: float = 0.10 terminal_growth: float = 0.03 + projection_years: int = 5 class MultipleResult(BaseModel): diff --git a/backend/app/services/data_service.py b/backend/app/services/data_service.py index f913ec5..9662227 100644 --- a/backend/app/services/data_service.py +++ b/backend/app/services/data_service.py @@ -505,9 +505,9 @@ def get_valuation(symbol: str) -> dict: ) if not dcf_raw: - dcf_out: dict = {"available": False, "wacc": 0.10, "terminal_growth": 0.03} + dcf_out: dict = {"available": False, "wacc": 0.10, "terminal_growth": 0.03, "projection_years": 5} elif "error" in dcf_raw: - dcf_out = {"available": True, "error": dcf_raw["error"], "wacc": 0.10, "terminal_growth": 0.03} + dcf_out = {"available": True, "error": dcf_raw["error"], "wacc": 0.10, "terminal_growth": 0.03, "projection_years": 5} else: dcf_out = { "available": True, @@ -523,6 +523,7 @@ def get_valuation(symbol: str) -> dict: "base_fcf": dcf_raw.get("base_fcf"), "wacc": 0.10, "terminal_growth": 0.03, + "projection_years": 5, } common = dict( diff --git a/backend/tests/test_api.py b/backend/tests/test_api.py index 345c0a3..230182e 100644 --- a/backend/tests/test_api.py +++ b/backend/tests/test_api.py @@ -633,6 +633,36 @@ def test_valuation_schema_structure() -> None: assert resp.ev_revenue.available is False +def test_dcf_result_projection_years_default() -> None: + from app.schemas import DcfResult + dcf = DcfResult(available=False) + assert dcf.projection_years == 5 + + +def test_get_valuation_includes_projection_years(monkeypatch) -> None: + import pandas as pd + clear_service_caches() + monkeypatch.setattr( + data_service, "get_company_info", + lambda symbol: { + "currentPrice": 150.0, + "sharesOutstanding": 1_000_000_000.0, + "totalDebt": 0.0, + "totalCash": 0.0, + }, + ) + monkeypatch.setattr(data_service, "get_shares_outstanding", lambda symbol: 1_000_000_000.0) + cf = annual_frame({ + "Operating Cash Flow": [80.0, 90.0, 100.0, 110.0], + "Capital Expenditure": [-10.0, -10.0, -10.0, -10.0], + }) + monkeypatch.setattr(data_service, "get_cash_flow", lambda symbol, quarterly=False: cf if not quarterly else pd.DataFrame()) + monkeypatch.setattr(data_service, "get_income_statement", lambda symbol, quarterly=False: pd.DataFrame()) + monkeypatch.setattr(data_service, "get_balance_sheet", lambda symbol, quarterly=False: pd.DataFrame()) + result = data_service.get_valuation("AAPL") + assert result["dcf"]["projection_years"] == 5 + + def test_build_fcf_series_happy_path() -> None: cf = annual_frame({ "Operating Cash Flow": [100.0, 90.0, 80.0, 70.0], |
