src.main.data_models package

Submodules

src.main.data_models.stock_price_data module

class src.main.data_models.stock_price_data.ProviderEnum(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of data providers.

FMP: str = 'fmp'
INTRINIO: str = 'intrinio'
POLYGON: str = 'polygon'
TIINGO: str = 'tiingo'
YFINANCE: str = 'yfinance'
class src.main.data_models.stock_price_data.StockData(*, ticker: str, stock_price_data: list[StockPriceData])[source]

Bases: BaseModel

Pydantic model for representing stock data.

Notes

  1. Rationale

    This Pydantic model defines the structure for representing stock data, consisting of a stock ticker symbol and a list of associated stock price data.

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'stock_price_data': FieldInfo(annotation=list[StockPriceData], required=True), 'ticker': FieldInfo(annotation=str, required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

stock_price_data: list[StockPriceData]
ticker: str
class src.main.data_models.stock_price_data.StockPriceData(*, date: str, closing_price: float, returns: float | None, holding_period_yield: float | None, holding_period_return: float | None, portfolio_of_1000: float | None)[source]

Bases: BaseModel

Pydantic model for representing stock price data.

closing_price: float
convert()[source]

TODO:Convert the data types and formats as needed.

This method is responsible for converting the data types and formats of the StockPriceData object as needed. For example, it can be used to convert the date string to a datetime object.

date: str
holding_period_return: float | None
holding_period_yield: float | None
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_fields: ClassVar[dict[str, FieldInfo]] = {'closing_price': FieldInfo(annotation=float, required=True), 'date': FieldInfo(annotation=str, required=True), 'holding_period_return': FieldInfo(annotation=Union[float, NoneType], required=True), 'holding_period_yield': FieldInfo(annotation=Union[float, NoneType], required=True), 'portfolio_of_1000': FieldInfo(annotation=Union[float, NoneType], required=True), 'returns': FieldInfo(annotation=Union[float, NoneType], required=True)}

Metadata about the fields defined on the model, mapping of field names to [FieldInfo][pydantic.fields.FieldInfo].

This replaces Model.__fields__ from Pydantic V1.

portfolio_of_1000: float | None
returns: float | None
to_dict()[source]

Return a dictionary representation of the object.

validation()[source]

TODO: Validate the data types and formats.

Raises:

ValueError – If any validation fails.

src.main.data_models.stock_price_data.clean_stock_price(stock_price: DataFrame) DataFrame[source]

Clean the raw stock price data and enhance it with additional calculated metrics.

Parameters:

stock_price (pd.DataFrame) – The raw stock price data.

Returns:

The cleaned stock price data with additional calculated metrics.

Return type:

pd.DataFrame

Notes

  1. Rationale

    This function takes raw stock price data and performs data cleaning operations, including selecting relevant columns, calculating returns, and deriving additional metrics such as holding period yield, holding period return, and portfolio value based on a hypothetical initial investment of $1000.

src.main.data_models.stock_price_data.get_stock_data(symbol: str, provider: Literal[ProviderEnum.FMP, ProviderEnum.INTRINIO, ProviderEnum.POLYGON, ProviderEnum.TIINGO, ProviderEnum.YFINANCE], start_date: str, interval: str) StockData[source]

Retrieves and processes stock data for a given symbol, provider, start date, and interval.

Parameters:
  • symbol (str) – The stock ticker symbol.

  • provider (Literal[ProviderEnum.FMP, ProviderEnum.INTRINIO, ProviderEnum.POLYGON, ProviderEnum.TIINGO,) –

  • ProviderEnum.YFINANCE] – The data provider.

  • start_date (str) – The start date for the data retrieval in ‘YYYY-MM-DD’ format.

  • interval (str) – The interval for the stock data (e.g., ‘1d’ = One day, ‘1W’ = One week, ‘1M’ = One month).

Returns:

A Pydantic model instance containing the stock ticker symbol and a list of cleaned stock price data.

Return type:

StockData

Notes

  1. Implementation Details
    • Retrieves historical stock price data from the specified provider for given symbol, start date, and interval.

    • The raw stock price data is cleaned and additional metrics are calculated.

    • The cleaned data is structured into a StockData Pydantic model.

Module contents