summaryrefslogtreecommitdiffstats
path: root/openbb_platform/core/openbb_core/provider/standard_models/sales_estimates.py
blob: 3216421d3064f7c236f09ab1b98eaaf1c023e273 (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
"""Sales Estimates Standard Model."""

from datetime import date as dateType
from typing import List, Literal, Set, Union, Optional

from pydantic import Field, field_validator

from openbb_core.provider.abstract.data import Data
from openbb_core.provider.abstract.query_params import QueryParams
from openbb_core.provider.utils.descriptions import (
    QUERY_DESCRIPTIONS,
)

#from openbb_intrinio.utils.references import IntrinioCompany

# doing this to avoid recursion lol
class IntrinioCompany(Data):
    """Intrinio Company Data."""

    id: str = Field(description="The Intrinio ID of the Company.")
    ticker: Optional[str] = Field(
        description="The stock market ticker symbol associated with the company's common stock securities",
        default=None,
    )
    name: Optional[str] = Field(description="The company's common name.", default=None)
    lei: Optional[str] = Field(
        description="The Legal Entity Identifier (LEI) of the company.", default=None
    )
    cik: Optional[str] = Field(
        description="The Central Index Key (CIK) of the company.",
    )


class SalesEstimatesQueryParams(QueryParams):
    """Sales Estimates Query."""

    symbol: str = Field(description=QUERY_DESCRIPTIONS.get("symbol", ""))
    start_date: Optional[dateType] = Field(
        default=None,
        description=QUERY_DESCRIPTIONS.get("start_date", ""),
    )
    end_date: Optional[dateType] = Field(
        default=None,
        description=QUERY_DESCRIPTIONS.get("end_date", ""),
    )
    fiscal_year: Optional[int] = Field(
        default=None,
        description="Only for the given fiscal year."
    )
    fiscal_period: Optional[Literal["Q1TTM", "Q2TTM", "Q3TTM", "FY", "Q1", "Q2", "Q3", "Q4", "Q2YTD", "Q3YTD"]] = Field(
        default=None,
        description="The fiscal period"
    )
    calendar_year: Optional[int] = Field(
        default=None,
        description="Only for the given calendar year."
    )
    calendar_period: Optional[Literal["Q1TTM", "Q2TTM", "Q3TTM", "FY", "Q1", "Q2", "Q3", "Q4", "Q2YTD", "Q3YTD"]] = Field(
        default=None,
        description="The calendar period"
    )
    next_page: Optional[int] = Field(
        default=None,
        description="Gets the next page of data from a previous API call."
    )
    page_size: Optional[int] = Field(
        default=None,
        description="The number of results to return."
    )

    @field_validator("symbol", mode="before", check_fields=False)
    @classmethod
    def upper_symbol(cls, v: str) -> str:
        """Convert symbol to uppercase."""
        return v.upper()


class SalesEstimatesData(Data):
    """Sales Estimates data."""
    estimates: List[float] = Field(description="Zacks Sales estimate data for a given date range.")
    company: Optional[IntrinioCompany] = Field(
        description="The company to get sales estimates data from.", default=None
    )
    date: Union[date, str] = Field(description="The period end date.")
    fiscal_year: Optional[int] = Field(
        default=None,
        description="The company's fiscal year for the reported period."
    )
    fiscal_period: Optional[str] = Field(
        default=None,
        description="The company's fiscal quarter for the reported period."
    )
    calendar_year: Optional[int] = Field(
        default=None,
        description="The closest calendar year for the company's fiscal year."
    )
    calendar_period: Optional[str] = Field(
        default=None,
        description="The closest calendar quarter for the company's fiscal year."
    )
    count: Optional[int] = Field(
        default=None,
        description="The number of estimates for the period."
    )
    mean: Optional[float] = Field(
        default=None,
        description="The sales estimate mean estimate for the period."
    )
    median: Optional[float] = Field(
        default=None,
        description="The sales estimate median estimate for the period."
    )
    high: Optional[float] = Field(
        default=None,
        description="The sales estimate high estimate for the period."
    )
    low: Optional[float] = Field(
        default=None,
        description="The sales estimate low estimate for the period."
    )
    standard_deviation: Optional[float] = Field(
        default=None,
        description="The sales estimate standard deviation estimate for the period."
    )
    analyst_revisions_percent_change_1w: Optional[float] = Field(
        default=None,
        description="The analyst revisions percent change in estimate for the period of 1 week."
    )
    analyst_revisions_up_1w: Optional[float] = Field(
        default=None,
        description="The analyst revisions going up for the period of 1 week."
    )
    analyst_revisions_down_1w: Optional[float] = Field(
        default=None,
        description="The analyst revisions going down for the period of 1 week."
    )
    analyst_revisions_percent_change_1m: Optional[float] = Field(
        default=None,
        description="The analyst revisions percent change in estimate for the period of 1 month."
    )
    analyst_revisions_up_1m: Optional[float] = Field(
        default=None,
        description="The analyst revisions going up for the period of 1 month."
    )
    analyst_revisions_down_1m: Optional[float] = Field(
        default=None,
        description="The analyst revisions going down for the period of 1 month."
    )
    analyst_revisions_percent_change_3m: Optional[float] = Field(
        default=None,
        description="The analyst revisions percent change in estimate for the period of 3 months."
    )
    analyst_revisions_up_3m: Optional[float] = Field(
        default=None,
        description="The analyst revisions going up for the period of 3 months."
    )
    analyst_revisions_down_3m: Optional[float] = Field(
        default=None,
        description="The analyst revisions going down for the period of 3 months."
    )
    next_page: Optional[str] = Field(
        default=None,
        description="The token required to request the next page of the data. If null, no further results are available."
    )

    @field_validator("symbol", mode="before", check_fields=False)
    @classmethod
    def upper_symbol(cls, v: Union[str, List[str], Set[str]]):
        """Convert symbol to uppercase."""
        if isinstance(v, str):
            return v.upper()
        return ",".join([symbol.upper() for symbol in list(v)]) if v else None