feat: add fundamentals DB model and cached provider
This commit is contained in:
parent
6c909d12c3
commit
0530f496ca
5 changed files with 217 additions and 0 deletions
|
|
@ -30,6 +30,8 @@ from shared.models import (
|
|||
MarketData,
|
||||
PortfolioSnapshot,
|
||||
StrategyMetric,
|
||||
# Fundamentals
|
||||
Fundamentals,
|
||||
)
|
||||
from shared.db import create_db
|
||||
from shared.config import BaseConfig
|
||||
|
|
@ -284,6 +286,48 @@ class TestStrategyMetric:
|
|||
assert sm.sharpe_ratio == 1.8
|
||||
|
||||
|
||||
class TestFundamentals:
|
||||
def test_create_fundamentals(self) -> None:
|
||||
now = datetime.now(timezone.utc)
|
||||
f = Fundamentals(
|
||||
id=uuid.uuid4(),
|
||||
ticker="AAPL",
|
||||
eps_ttm=6.57,
|
||||
pe_ratio=28.3,
|
||||
peg_ratio=2.1,
|
||||
revenue_growth_yoy=0.08,
|
||||
profit_margin=0.26,
|
||||
debt_to_equity=1.87,
|
||||
market_cap=2_800_000_000_000.0,
|
||||
fetched_at=now,
|
||||
)
|
||||
assert f.ticker == "AAPL"
|
||||
assert f.eps_ttm == 6.57
|
||||
assert f.pe_ratio == 28.3
|
||||
assert f.peg_ratio == 2.1
|
||||
assert f.revenue_growth_yoy == 0.08
|
||||
assert f.profit_margin == 0.26
|
||||
assert f.debt_to_equity == 1.87
|
||||
assert f.market_cap == 2_800_000_000_000.0
|
||||
assert f.fetched_at == now
|
||||
|
||||
def test_create_with_optional_fields_none(self) -> None:
|
||||
now = datetime.now(timezone.utc)
|
||||
f = Fundamentals(
|
||||
id=uuid.uuid4(),
|
||||
ticker="XYZ",
|
||||
fetched_at=now,
|
||||
)
|
||||
assert f.ticker == "XYZ"
|
||||
assert f.eps_ttm is None
|
||||
assert f.pe_ratio is None
|
||||
assert f.peg_ratio is None
|
||||
assert f.revenue_growth_yoy is None
|
||||
assert f.profit_margin is None
|
||||
assert f.debt_to_equity is None
|
||||
assert f.market_cap is None
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Metadata / Base tests
|
||||
# ---------------------------------------------------------------------------
|
||||
|
|
@ -306,6 +350,7 @@ class TestMetadata:
|
|||
"market_data",
|
||||
"portfolio_snapshots",
|
||||
"strategy_metrics",
|
||||
"fundamentals",
|
||||
}
|
||||
assert expected.issubset(table_names)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue