🕸️ Core¤
The core
module to contain logic & functions used in controllers.
This module is intended to contain sub-modules and functions that are not directly utilized from the package, but rather used in building the package itself. This means that the core module should not contain any code that is specific to the package's use case, but rather should be generic and reusable in other contexts.
humbldata.core.standard_models
¤
Models to represent core data structures of the Standardization Framework.
humbldata.core.standard_models.abstract
¤
Abstract core DATA MODELS to be inherited by other models.
humbldata.core.standard_models.abstract.data
¤
A wrapper around OpenBB Data Standardized Model to use with humbldata.
humbldata.core.standard_models.abstract.data.Data
¤
Bases: Data
An abstract standard_model to represent a base Data Model.
The Data Model should be used to define the data that is being
collected and analyzed in a context.category.command
call.
This Data model is meant to be inherited and built upon by other standard_models for a specific context.
Example
total_time = f"{end_time - start_time:.3f}"
class EquityHistoricalData(Data):
date: Union[dateType, datetime] = Field(
description=DATA_DESCRIPTIONS.get("date", "")
)
open: float = Field(description=DATA_DESCRIPTIONS.get("open", ""))
high: float = Field(description=DATA_DESCRIPTIONS.get("high", ""))
low: float = Field(description=DATA_DESCRIPTIONS.get("low", ""))
close: float = Field(description=DATA_DESCRIPTIONS.get("close", ""))
volume: Optional[Union[float, int]] = Field(
default=None, description=DATA_DESCRIPTIONS.get("volume", "")
)
@field_validator("date", mode="before", check_fields=False)
def date_validate(cls, v): # pylint: disable=E0213
v = parser.isoparse(str(v))
if v.hour == 0 and v.minute == 0:
return v.date()
return v
Source code in src\humbldata\core\standard_models\abstract\data.py
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 |
|
humbldata.core.standard_models.abstract.errors
¤
An ABSTRACT DATA MODEL to be inherited by custom errors.
humbldata.core.standard_models.abstract.errors.HumblDataError
¤
Bases: BaseException
Base Error for HumblData logic.
Source code in src\humbldata\core\standard_models\abstract\errors.py
4 5 6 7 8 9 |
|
humbldata.core.standard_models.abstract.query_params
¤
A wrapper around OpenBB QueryParams Standardized Model to use with humbldata.
humbldata.core.standard_models.abstract.query_params.QueryParams
¤
Bases: QueryParams
An abstract standard_model to represent a base QueryParams Data.
QueryParams model should be used to define the query parameters for a
context.category.command
call.
This QueryParams model is meant to be inherited and built upon by other standard_models for a specific context.
Examples:
class EquityHistoricalQueryParams(QueryParams):
symbol: str = Field(description=QUERY_DESCRIPTIONS.get("symbol", ""))
interval: Optional[str] = Field(
default="1d",
description=QUERY_DESCRIPTIONS.get("interval", ""),
)
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", ""),
)
@field_validator("symbol", mode="before", check_fields=False)
@classmethod
def upper_symbol(cls, v: Union[str, List[str], Set[str]]):
if isinstance(v, str):
return v.upper()
return ",".join([symbol.upper() for symbol in list(v)])
This would create a class that would be used to query historical price data for equities from any given command.
This could then be used to create a
MandelbrotChannelEquityHistoricalQueryParams
that would define what query
parameters are needed for the Mandelbrot Channel command.
Source code in src\humbldata\core\standard_models\abstract\query_params.py
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 |
|
humbldata.core.standard_models.abstract.singleton
¤
An ABSTRACT DATA MODEL, Singleton, to represent a class that should only have one instance.
humbldata.core.standard_models.abstract.singleton.SingletonMeta
¤
Bases: type
, Generic[T]
SingletonMeta is a metaclass that creates a Singleton instance of a class.
Singleton design pattern restricts the instantiation of a class to a single instance. This is useful when exactly one object is needed to coordinate actions across the system.
Source code in src\humbldata\core\standard_models\abstract\singleton.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
humbldata.core.standard_models.abstract.singleton.SingletonMeta.__call__
¤
__call__(*args, **kwargs) -> T
Override the call method.
If the class exists, otherwise creates a new instance and stores it in the _instances dictionary.
Source code in src\humbldata\core\standard_models\abstract\singleton.py
21 22 23 24 25 26 27 28 29 30 31 32 |
|
humbldata.core.standard_models.abstract.tagged
¤
An ABSTRACT DATA MODEL, Tagged, to be inherited by other models as identifier.
humbldata.core.standard_models.abstract.tagged.Tagged
¤
Bases: BaseModel
A class to represent an object tagged with a uuid7.
Source code in src\humbldata\core\standard_models\abstract\tagged.py
7 8 9 10 |
|
humbldata.core.standard_models.toolbox
¤
Context: Toolbox || Category: Standardized Framework Model.
This module defines the QueryParams and Data classes for the Toolbox context. THis is where all of the context(s) of your project go. The STANDARD MODELS for categories and subsequent commands are nested here.
Classes:
Name | Description |
---|---|
ToolboxQueryParams |
Query parameters for the ToolboxController. |
ToolboxData |
A Pydantic model that defines the data returned by the ToolboxController. |
Attributes:
Name | Type | Description |
---|---|---|
symbol |
str
|
The symbol/ticker of the stock. |
interval |
Optional[str]
|
The interval of the data. Defaults to '1d'. |
start_date |
str
|
The start date of the data. |
end_date |
str
|
The end date of the data. |
humbldata.core.standard_models.toolbox.technical
¤
Context: Toolbox || Category: Technical.
humbldata.core.standard_models.toolbox.technical.mandelbrotchannel
¤
Mandelbrot Channel Standard Model.
Context: Toolbox || Category: Technical || Command: Mandelbrot Channel.
This module is used to define the QueryParams and Data model for the Mandelbrot Channel command.
humbldata.core.standard_models.toolbox.technical.mandelbrotchannel.MandelbrotChannelQueryParams
¤
Bases: QueryParams
QueryParams for the Mandelbrot Channel command.
Source code in src\humbldata\core\standard_models\toolbox\technical\mandelbrotchannel.py
21 22 23 24 25 26 |
|
humbldata.core.standard_models.toolbox.technical.mandelbrotchannel.MandelbrotChannelData
¤
Bases: Data
Data model for the Mandelbrot Channel command.
Source code in src\humbldata\core\standard_models\toolbox\technical\mandelbrotchannel.py
29 30 31 32 |
|
humbldata.core.standard_models.toolbox.technical.mandelbrotchannel.MandelbrotChannelFetcher
¤
Bases: MandelbrotChannelQueryParams
, MandelbrotChannelData
Fetcher for the Mandelbrot Channel command.
Source code in src\humbldata\core\standard_models\toolbox\technical\mandelbrotchannel.py
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 |
|
humbldata.core.standard_models.toolbox.technical.mandelbrotchannel.MandelbrotChannelFetcher.transform_query
¤transform_query()
Transform the params to the command-specific query.
Source code in src\humbldata\core\standard_models\toolbox\technical\mandelbrotchannel.py
50 51 |
|
humbldata.core.standard_models.toolbox.technical.mandelbrotchannel.MandelbrotChannelFetcher.extract_data
¤extract_data()
Extract the data from the provider.
Source code in src\humbldata\core\standard_models\toolbox\technical\mandelbrotchannel.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
humbldata.core.standard_models.toolbox.technical.mandelbrotchannel.MandelbrotChannelFetcher.transform_data
¤transform_data()
Transform the command-specific data.
Source code in src\humbldata\core\standard_models\toolbox\technical\mandelbrotchannel.py
68 69 |
|
humbldata.core.standard_models.toolbox.technical.realized_volatility
¤
Volatility Standard Model.
Context: Toolbox || Category: Technical || Command: Volatility.
This module is used to define the QueryParams and Data model for the Volatility command.
humbldata.core.standard_models.toolbox.technical.realized_volatility.RealizedVolatilityQueryParams
¤
Bases: QueryParams
QueryParams for the Realized Volatility command.
Source code in src\humbldata\core\standard_models\toolbox\technical\realized_volatility.py
21 22 23 24 |
|
humbldata.core.standard_models.toolbox.technical.realized_volatility.RealizedVolatilityData
¤
Bases: Data
Data model for the Realized Volatility command.
Source code in src\humbldata\core\standard_models\toolbox\technical\realized_volatility.py
27 28 29 30 |
|
humbldata.core.standard_models.toolbox.technical.realized_volatility.RealizedVolatilityFetcher
¤
Bases: RealizedVolatilityQueryParams
Fetcher for the Realized Volatility command.
Source code in src\humbldata\core\standard_models\toolbox\technical\realized_volatility.py
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 |
|
humbldata.core.standard_models.toolbox.technical.realized_volatility.RealizedVolatilityFetcher.transform_query
¤transform_query()
Transform the params to the command-specific query.
Source code in src\humbldata\core\standard_models\toolbox\technical\realized_volatility.py
48 49 |
|
humbldata.core.standard_models.toolbox.technical.realized_volatility.RealizedVolatilityFetcher.extract_data
¤extract_data()
Extract the data from the provider.
Source code in src\humbldata\core\standard_models\toolbox\technical\realized_volatility.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
|
humbldata.core.standard_models.toolbox.technical.realized_volatility.RealizedVolatilityFetcher.transform_data
¤transform_data()
Transform the command-specific data.
Source code in src\humbldata\core\standard_models\toolbox\technical\realized_volatility.py
68 69 |
|
humbldata.core.standard_models.toolbox.technical.realized_volatility.RealizedVolatilityFetcher.fetch_data
¤fetch_data()
Execute the TET pattern.
Source code in src\humbldata\core\standard_models\toolbox\technical\realized_volatility.py
72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
humbldata.core.standard_models.toolbox.ToolboxQueryParams
¤
Bases: QueryParams
Query parameters for the ToolboxController.
This class defines the query parameters used by the ToolboxController, including the stock symbol, data interval, start date, and end date. It also includes a method to ensure the stock symbol is in uppercase.
Attributes:
Name | Type | Description |
---|---|---|
symbol |
str
|
The symbol or ticker of the stock. |
interval |
Optional[str]
|
The interval of the data. Defaults to '1d'. Can be None. |
start_date |
str
|
The start date for the data query. |
end_date |
str
|
The end date for the data query. |
Methods:
Name | Description |
---|---|
upper_symbol |
A Pydantic |
Source code in src\humbldata\core\standard_models\toolbox\__init__.py
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 |
|
humbldata.core.standard_models.toolbox.ToolboxQueryParams.upper_symbol
classmethod
¤
upper_symbol(v: str | list[str] | set[str]) -> str | list[str]
Convert the stock symbol to uppercase.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
v |
Union[str, List[str], Set[str]]
|
The stock symbol or collection of symbols to be converted. |
required |
Returns:
Type | Description |
---|---|
Union[str, List[str]]
|
The uppercase stock symbol or a comma-separated string of uppercase symbols. |
Source code in src\humbldata\core\standard_models\toolbox\__init__.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
|
humbldata.core.standard_models.toolbox.ToolboxData
¤
Bases: Data
The Data for the ToolboxController.
WIP: I'm thinking that this is the final layer around which the HumblDataObject will be returned to the user, with all necessary information about the query, command, data and charts that they should want. This HumblDataObject will return values in json/dict format, with methods to allow transformation into polars_df, pandas_df, a list, a dict...
Source code in src\humbldata\core\standard_models\toolbox\__init__.py
106 107 108 109 110 111 112 113 114 115 |
|
humbldata.core.utils
¤
humbldata core utils.
Utils is used to keep; helpers, descriptions, constants, and other useful tools.
humbldata.core.utils.constants
¤
A module to contain all project-wide constants.
humbldata.core.utils.core_helpers
¤
A module to contain core helper functions for the program.
humbldata.core.utils.core_helpers.is_debug_mode
¤
is_debug_mode() -> bool
Check if the current system is in debug mode.
Returns:
Type | Description |
---|---|
bool
|
True if the system is in debug mode, False otherwise. |
Source code in src\humbldata\core\utils\core_helpers.py
12 13 14 15 16 17 18 19 20 21 |
|
humbldata.core.utils.core_helpers.log_start_end
¤
log_start_end(func: Callable | None = None, *, log: Logger | None = None) -> Callable
Add logging at the start and end of any function it decorates, including time tracking.
Handles exceptions by logging them and modifies behavior based on the system's debug mode. Logs the total time taken by the function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
Optional[Callable]
|
The function to decorate. |
None
|
log |
Optional[Logger]
|
The logger to use for logging. |
None
|
Returns:
Type | Description |
---|---|
Callable
|
The decorated function. |
Source code in src\humbldata\core\utils\core_helpers.py
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 |
|
humbldata.core.utils.descriptions
¤
Common descriptions for model fields.
humbldata.core.utils.env
¤
The Env Module, to control a single instance of environment variables.
humbldata.core.utils.env.Env
¤
A singleton environment to hold all Environment variables.
Source code in src\humbldata\core\utils\env.py
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 |
|
humbldata.core.utils.env.Env.str2bool
staticmethod
¤
str2bool(value: str | bool) -> bool
Match a value to its boolean correspondent.
Args: value (str): The string value to be converted to a boolean.
Returns:
Type | Description |
---|---|
bool: The boolean value corresponding to the input string.
|
|
Raises:
Type | Description |
---|---|
ValueError: If the input string does not correspond to a boolean
|
value. |
Source code in src\humbldata\core\utils\env.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
humbldata.core.utils.openbb_helpers
¤
Core Module - OpenBB Helpers.
This module contains functions used to interact with OpenBB, or wrap commands to have specific data outputs.
humbldata.core.utils.openbb_helpers.obb_login
¤
obb_login(pat: str | None = None) -> bool
Log into the OpenBB Hub using a Personal Access Token (PAT).
This function wraps the obb.account.login
method to provide a simplified
interface for logging into OpenBB Hub. It optionally accepts a PAT. If no PAT
is provided, it attempts to use the PAT stored in the environment variable
OBB_PAT
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
pat |
str | None
|
The personal access token for authentication. If None, the token is
retrieved from the environment variable |
None
|
Returns:
Type | Description |
---|---|
bool
|
True if login is successful, False otherwise. |
Raises:
Type | Description |
---|---|
HumblDataError
|
If an error occurs during the login process. |
Examples:
>>> # obb_login("your_personal_access_token_here")
True
>>> # obb_login() # Assumes `OBB_PAT` is set in the environment
True
Source code in src\humbldata\core\utils\openbb_helpers.py
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 |
|
humbldata.core.utils.openbb_helpers.get_latest_price
¤
get_latest_price(symbol: str | list[str] | Series, provider: Literal['fmp', 'intrinio'] | None = None) -> LazyFrame
Context: Core || Category: Utils || Subcategory: OpenBB Helpers || Command: get_latest_price.
This function queries the latest stock price data using the specified
provider. If no provider is specified, it defaults to using
FinancialModelingPrep (fmp
). The function returns a LazyFrame containing
the stock symbols and their corresponding latest prices.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
symbol |
str | list[str] | Series
|
The stock symbol(s) for which to fetch the latest price. Can be a single symbol, a list of symbols, or a Polars Series of symbols. |
required |
provider |
Literal['fmp', 'intrinio'] | None
|
The data provider to use for fetching the stock prices. If not specified, a default provider is used. |
None
|
Returns:
Type | Description |
---|---|
LazyFrame
|
A Polars LazyFrame containing columns for the stock symbols ('symbol') and their most recent prices ('last_price'). |
Source code in src\humbldata\core\utils\openbb_helpers.py
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 |
|