summaryrefslogtreecommitdiff
path: root/backend/app/schemas.py
blob: 351de0638a057d0aecbf7aff6ee2ee2c9638d153 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
"""Pydantic response schemas for the Prism v2 Overview API."""
from typing import Literal

from pydantic import BaseModel, Field


class SearchResult(BaseModel):
    symbol: str
    name: str
    exchange: str | None = None


class MarketIndex(BaseModel):
    name: str
    price: float | None = None
    change_pct: float | None = None


class Quote(BaseModel):
    price: float | None = None
    prev_close: float | None = None
    change: float | None = None
    change_pct: float | None = None


class Signal(BaseModel):
    key: str
    state: Literal["pos", "warn", "neg", "neu"]
    value: str
    description: str


class OverviewStats(BaseModel):
    market_cap: float | None = None
    trailing_pe: float | None = None
    trailing_eps: float | None = None
    volume: float | None = None
    average_volume: float | None = None
    beta: float | None = None


class OverviewRatios(BaseModel):
    price_to_book: float | None = None
    price_to_sales: float | None = None
    ev_to_sales: float | None = None
    ev_to_ebitda: float | None = None
    gross_margin_ttm: float | None = None
    operating_margin_ttm: float | None = None
    net_margin_ttm: float | None = None
    roe_ttm: float | None = None
    roa_ttm: float | None = None
    roic_ttm: float | None = None
    debt_to_equity: float | None = None
    current_ratio: float | None = None
    dividend_yield_ttm: float | None = None
    dividend_payout_ratio_ttm: float | None = None


class Range52Week(BaseModel):
    low: float | None = None
    high: float | None = None
    price: float | None = None


class ShortInterest(BaseModel):
    short_percent_of_float: float | None = None
    short_ratio: float | None = None
    shares_short: int | None = None
    shares_short_prior_month: int | None = None
    shares_short_delta_pct: float | None = None


class CompanyProfile(BaseModel):
    symbol: str
    name: str
    sector: str | None = None
    industry: str | None = None
    exchange: str | None = None
    website: str | None = None
    summary: str | None = None


class OverviewMeta(BaseModel):
    status: Literal["complete", "partial"]
    is_partial: bool = False
    field_availability: dict[str, bool] = Field(default_factory=dict)
    sources: dict[str, str] = Field(default_factory=dict)


class TickerOverview(BaseModel):
    profile: CompanyProfile
    quote: Quote
    signals: list[Signal] = Field(default_factory=list)
    stats: OverviewStats
    ratios: OverviewRatios
    range_52w: Range52Week
    short_interest: ShortInterest
    meta: OverviewMeta


class HistoryPoint(BaseModel):
    date: str
    open: float | None = None
    high: float | None = None
    low: float | None = None
    close: float | None = None
    volume: float | None = None


class FinancialRow(BaseModel):
    label: str
    indent: int = 0
    is_total: bool = False
    is_section: bool = False
    is_margin: bool = False
    values: list[float | None] = Field(default_factory=list)


class FinancialStatement(BaseModel):
    columns: list[str] = Field(default_factory=list)
    rows: list[FinancialRow] = Field(default_factory=list)


class FinancialsResponse(BaseModel):
    period: Literal["annual", "quarterly"]
    income: FinancialStatement
    balance: FinancialStatement
    cash_flow: FinancialStatement


class DcfResult(BaseModel):
    available: bool = True
    error: str | None = None
    intrinsic_value_per_share: float | None = None
    enterprise_value: float | None = None
    equity_value: float | None = None
    net_debt: float | None = None
    cash_and_equivalents: float | None = None
    total_debt: float | None = None
    terminal_value_pv: float | None = None
    fcf_pv_sum: float | None = None
    growth_rate_used: float | None = None
    base_fcf: float | None = None
    wacc: float = 0.10
    terminal_growth: float = 0.03
    projection_years: int = 5


class MultipleResult(BaseModel):
    available: bool = True
    implied_price_per_share: float | None = None
    implied_ev: float | None = None
    equity_value: float | None = None
    net_debt: float | None = None
    multiple_used: float | None = None


class ValuationResponse(BaseModel):
    symbol: str
    current_price: float | None = None
    shares_outstanding: float | None = None
    dcf: DcfResult
    ev_ebitda: MultipleResult
    ev_revenue: MultipleResult
    price_to_book: MultipleResult


class WatchlistItem(BaseModel):
    symbol: str
    created_at: str
    quote: Quote | None = None


class WatchlistResponse(BaseModel):
    items: list[WatchlistItem]
    limit: int = 10


class RatioPoint(BaseModel):
    value: float | None = None
    spark: list[float | None] = Field(default_factory=list)
    vs_sector: float | None = None


class RatiosResponse(BaseModel):
    pe_ttm: RatioPoint
    ev_ebitda: RatioPoint
    gross_margin: RatioPoint
    net_margin: RatioPoint
    price_to_book: RatioPoint
    price_to_sales: RatioPoint
    ev_to_sales: RatioPoint
    p_fcf: RatioPoint
    forward_pe: RatioPoint
    operating_margin: RatioPoint
    ebitda_margin: RatioPoint
    fcf_margin: RatioPoint
    roe: RatioPoint
    roa: RatioPoint
    roic: RatioPoint
    debt_to_equity: RatioPoint
    current_ratio: RatioPoint
    quick_ratio: RatioPoint
    interest_coverage: RatioPoint
    dividend_yield: RatioPoint
    dividend_payout: RatioPoint


class InsiderTransaction(BaseModel):
    date: str | None = None
    insider: str
    position: str
    direction: Literal["buy", "sell", "other"]
    shares: int | None = None
    value: float | None = None


class InsiderMonthPoint(BaseModel):
    month: str
    buy: float
    sell: float


class InsiderSummary(BaseModel):
    buy_count: int
    sell_count: int
    buy_value: float
    sell_value: float


class InsidersResponse(BaseModel):
    summary: InsiderSummary
    monthly_chart: list[InsiderMonthPoint] = Field(default_factory=list)
    transactions: list[InsiderTransaction] = Field(default_factory=list)


class FilingItem(BaseModel):
    date: str
    form: str
    title: str
    url: str | None = None


class FilingKpis(BaseModel):
    total: int = 0
    count_10k: int = 0
    count_10q: int = 0
    count_8k: int = 0
    distinct_forms: int = 0


class FormMixRow(BaseModel):
    form: str
    count: int
    pct: float | None = None


class CadencePoint(BaseModel):
    month: str
    count_10k: int = 0
    count_10q: int = 0
    count_8k: int = 0
    count_other: int = 0


class FilingsResponse(BaseModel):
    kpis: FilingKpis
    cadence: list[CadencePoint] = Field(default_factory=list)
    form_mix: list[FormMixRow] = Field(default_factory=list)
    readout: str
    filings: list[FilingItem] = Field(default_factory=list)


class ErrorResponse(BaseModel):
    detail: str


class NewsItem(BaseModel):
    id: str
    title: str
    summary: str
    source: str
    url: str
    sentiment: Literal["bullish", "neutral", "bearish"]
    published_at: str


class NewsAggregate(BaseModel):
    buzz_articles_last_week: int
    bullish_pct: float
    neutral_pct: float
    bearish_pct: float


class NewsResponse(BaseModel):
    items: list[NewsItem] = Field(default_factory=list)
    aggregate: NewsAggregate | None = None
    provider: Literal["finnhub", "fmp"] | None = None
    fetched_at: str