Types and Enums
Declaring types used throughout the project.
- class openseries.owntypes.ValueType(*values)[source]
-
Enum types of OpenTimeSeries to identify the output.
- EWMA = 'EWMA'
- PRICE = 'Price(Close)'
- RTRN = 'Return(Total)'
- RELRTRN = 'Relative return'
- ROLLBETA = 'Beta'
- ROLLCORR = 'Rolling correlation'
- ROLLCVAR = 'Rolling CVaR'
- ROLLINFORATIO = 'Information Ratio'
- ROLLRTRN = 'Rolling returns'
- ROLLVAR = 'Rolling VaR'
- ROLLVOL = 'Rolling volatility'
Value Types
- class openseries.owntypes.ValueType(*values)[source]
-
Enum types of OpenTimeSeries to identify the output.
- EWMA = 'EWMA'
- PRICE = 'Price(Close)'
- RTRN = 'Return(Total)'
- RELRTRN = 'Relative return'
- ROLLBETA = 'Beta'
- ROLLCORR = 'Rolling correlation'
- ROLLCVAR = 'Rolling CVaR'
- ROLLINFORATIO = 'Information Ratio'
- ROLLRTRN = 'Rolling returns'
- ROLLVAR = 'Rolling VaR'
- ROLLVOL = 'Rolling volatility'
The ValueType enum identifies the type of values in a time series (prices, returns, etc.).
Type Aliases
- openseries.owntypes.SeriesOrFloat_co = +SeriesOrFloat_co
Type variable.
The preferred way to construct a type variable is via the dedicated syntax for generic functions, classes, and type aliases:
class Sequence[T]: # T is a TypeVar ...
This syntax can also be used to create bound and constrained type variables:
# S is a TypeVar bound to str class StrSequence[S: str]: ... # A is a TypeVar constrained to str or bytes class StrOrBytesSequence[A: (str, bytes)]: ...
Type variables can also have defaults:
- class IntDefault[T = int]:
…
However, if desired, reusable type variables can also be constructed manually, like so:
T = TypeVar('T') # Can be anything S = TypeVar('S', bound=str) # Can be any subtype of str A = TypeVar('A', str, bytes) # Must be exactly str or bytes D = TypeVar('D', default=int) # Defaults to int
Type variables exist primarily for the benefit of static type checkers. They serve as the parameters for generic types as well as for generic function and type alias definitions.
The variance of type variables is inferred by type checkers when they are created through the type parameter syntax and when
infer_variance=Trueis passed. Manually created type variables may be explicitly marked covariant or contravariant by passingcovariant=Trueorcontravariant=True. By default, manually created type variables are invariant. See PEP 484 and PEP 695 for more details.
- openseries.owntypes.CountryStringType
Runtime representation of an annotated type.
At its core ‘Annotated[t, dec1, dec2, …]’ is an alias for the type ‘t’ with extra annotations. The alias behaves like a normal typing alias. Instantiating is the same as instantiating the underlying type; binding it to types is also the same.
The metadata itself is stored in a ‘__metadata__’ attribute as a tuple.
alias of
Annotated[str,StringConstraints(strip_whitespace=True, to_upper=True, to_lower=None, strict=True, min_length=2, max_length=2, pattern=^[A-Z]{2}$)]
- openseries.owntypes.CountrySetType
Runtime representation of an annotated type.
At its core ‘Annotated[t, dec1, dec2, …]’ is an alias for the type ‘t’ with extra annotations. The alias behaves like a normal typing alias. Instantiating is the same as instantiating the underlying type; binding it to types is also the same.
The metadata itself is stored in a ‘__metadata__’ attribute as a tuple.
alias of
Annotated[set[Annotated[str,StringConstraints(strip_whitespace=True, to_upper=True, to_lower=None, strict=True, min_length=2, max_length=2, pattern=^[A-Z]{2}$)]],MinLen(min_length=1)]
- openseries.owntypes.CountriesType
alias of
Annotated[set[Annotated[str,StringConstraints(strip_whitespace=True, to_upper=True, to_lower=None, strict=True, min_length=2, max_length=2, pattern=^[A-Z]{2}$)]],MinLen(min_length=1)] |Annotated[str,StringConstraints(strip_whitespace=True, to_upper=True, to_lower=None, strict=True, min_length=2, max_length=2, pattern=^[A-Z]{2}$)]
- openseries.owntypes.CurrencyStringType
Runtime representation of an annotated type.
At its core ‘Annotated[t, dec1, dec2, …]’ is an alias for the type ‘t’ with extra annotations. The alias behaves like a normal typing alias. Instantiating is the same as instantiating the underlying type; binding it to types is also the same.
The metadata itself is stored in a ‘__metadata__’ attribute as a tuple.
alias of
Annotated[str,StringConstraints(strip_whitespace=True, to_upper=True, to_lower=None, strict=True, min_length=3, max_length=3, pattern=^[A-Z]{3}$)]
- openseries.owntypes.DateStringType
Runtime representation of an annotated type.
At its core ‘Annotated[t, dec1, dec2, …]’ is an alias for the type ‘t’ with extra annotations. The alias behaves like a normal typing alias. Instantiating is the same as instantiating the underlying type; binding it to types is also the same.
The metadata itself is stored in a ‘__metadata__’ attribute as a tuple.
alias of
Annotated[str,StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=True, min_length=10, max_length=10, pattern=^d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]d|3[01])$)]
- openseries.owntypes.DateListType
Runtime representation of an annotated type.
At its core ‘Annotated[t, dec1, dec2, …]’ is an alias for the type ‘t’ with extra annotations. The alias behaves like a normal typing alias. Instantiating is the same as instantiating the underlying type; binding it to types is also the same.
The metadata itself is stored in a ‘__metadata__’ attribute as a tuple.
alias of
Annotated[list[Annotated[str,StringConstraints(strip_whitespace=True, to_upper=None, to_lower=None, strict=True, min_length=10, max_length=10, pattern=^d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]d|3[01])$)]],MinLen(min_length=1)]
- openseries.owntypes.ValueListType
Runtime representation of an annotated type.
At its core ‘Annotated[t, dec1, dec2, …]’ is an alias for the type ‘t’ with extra annotations. The alias behaves like a normal typing alias. Instantiating is the same as instantiating the underlying type; binding it to types is also the same.
The metadata itself is stored in a ‘__metadata__’ attribute as a tuple.
- openseries.owntypes.DaysInYearType
Runtime representation of an annotated type.
At its core ‘Annotated[t, dec1, dec2, …]’ is an alias for the type ‘t’ with extra annotations. The alias behaves like a normal typing alias. Instantiating is the same as instantiating the underlying type; binding it to types is also the same.
The metadata itself is stored in a ‘__metadata__’ attribute as a tuple.
alias of
Annotated[int, FieldInfo(annotation=NoneType, required=True, metadata=[Strict(strict=True), Ge(ge=1), Le(le=366)])]
- openseries.owntypes.DateType = str | datetime.date | datetime.datetime | numpy.datetime64 | pandas._libs.tslibs.timestamps.Timestamp
Represent a PEP 604 union type
E.g. for int | str
Literal Types
- openseries.owntypes.LiteralJsonOutput
alias of
Literal[‘values’, ‘tsdf’]
- openseries.owntypes.LiteralTrunc
alias of
Literal[‘before’, ‘after’, ‘both’]
- openseries.owntypes.LiteralLinePlotMode
alias of
Literal[‘lines’, ‘markers’, ‘lines+markers’, ‘lines+text’, ‘markers+text’, ‘lines+markers+text’] |None
- openseries.owntypes.LiteralHowMerge
alias of
Literal[‘outer’, ‘inner’]
- openseries.owntypes.LiteralQuantileInterp
alias of
Literal[‘linear’, ‘lower’, ‘higher’, ‘midpoint’, ‘nearest’]
- openseries.owntypes.LiteralBizDayFreq
alias of
Literal[‘B’, ‘BME’, ‘BQE’, ‘BYE’]
- openseries.owntypes.LiteralPandasReindexMethod
alias of
Literal[‘pad’, ‘ffill’, ‘backfill’, ‘bfill’, ‘nearest’] |None
- openseries.owntypes.LiteralNanMethod
alias of
Literal[‘fill’, ‘drop’]
- openseries.owntypes.LiteralCaptureRatio
alias of
Literal[‘up’, ‘down’, ‘both’]
- openseries.owntypes.LiteralBarPlotMode
alias of
Literal[‘stack’, ‘group’, ‘overlay’, ‘relative’]
- openseries.owntypes.LiteralPlotlyOutput
alias of
Literal[‘file’, ‘div’]
- openseries.owntypes.LiteralPlotlyJSlib
alias of
Literal[True, False, ‘cdn’]
- openseries.owntypes.LiteralPlotlyHistogramPlotType
alias of
Literal[‘bars’, ‘lines’]
- openseries.owntypes.LiteralPlotlyHistogramBarMode
alias of
Literal[‘stack’, ‘group’, ‘overlay’, ‘relative’]
- openseries.owntypes.LiteralPlotlyHistogramCurveType
alias of
Literal[‘normal’, ‘kde’]
- openseries.owntypes.LiteralPlotlyHistogramHistNorm
alias of
Literal[‘percent’, ‘probability’, ‘density’, ‘probability density’]
- openseries.owntypes.LiteralPortfolioWeightings
alias of
Literal[‘eq_weights’, ‘inv_vol’, ‘max_div’, ‘min_vol_overweight’]
- openseries.owntypes.LiteralMinimizeMethods
alias of
Literal[‘SLSQP’, ‘Nelder-Mead’, ‘Powell’, ‘CG’, ‘BFGS’, ‘Newton-CG’, ‘L-BFGS-B’, ‘TNC’, ‘COBYLA’, ‘trust-constr’, ‘dogleg’, ‘trust-ncg’, ‘trust-exact’, ‘trust-krylov’]
- openseries.owntypes.LiteralSeriesProps
alias of
Literal[‘value_ret’, ‘geo_ret’, ‘arithmetic_ret’, ‘vol’, ‘downside_deviation’, ‘ret_vol_ratio’, ‘sortino_ratio’, ‘kappa3_ratio’, ‘z_score’, ‘skew’, ‘kurtosis’, ‘positive_share’, ‘var_down’, ‘cvar_down’, ‘vol_from_var’, ‘worst’, ‘worst_month’, ‘max_drawdown_cal_year’, ‘max_drawdown’, ‘max_drawdown_date’, ‘first_idx’, ‘last_idx’, ‘length’, ‘span_of_days’, ‘yearfrac’, ‘periods_in_a_year’]
- openseries.owntypes.LiteralFrameProps
alias of
Literal[‘value_ret’, ‘geo_ret’, ‘arithmetic_ret’, ‘vol’, ‘downside_deviation’, ‘ret_vol_ratio’, ‘sortino_ratio’, ‘kappa3_ratio’, ‘z_score’, ‘skew’, ‘kurtosis’, ‘positive_share’, ‘var_down’, ‘cvar_down’, ‘vol_from_var’, ‘worst’, ‘worst_month’, ‘max_drawdown’, ‘max_drawdown_date’, ‘max_drawdown_cal_year’, ‘first_indices’, ‘last_indices’, ‘lengths_of_items’, ‘span_of_days_all’]
Validation Classes
- class openseries.owntypes.Countries(*, countryinput)[source]
Bases:
BaseModelDeclare Countries.
- Parameters:
countryinput (Annotated[set[Annotated[str, StringConstraints(strip_whitespace=True, to_upper=True, to_lower=None, strict=True, min_length=2, max_length=2, pattern=^[A-Z]{2}$)]], MinLen(min_length=1)] | Annotated[str, StringConstraints(strip_whitespace=True, to_upper=True, to_lower=None, strict=True, min_length=2, max_length=2, pattern=^[A-Z]{2}$)])
- countryinput: CountriesType
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class openseries.owntypes.Currency(*, ccy)[source]
Bases:
BaseModelDeclare Currency.
- Parameters:
ccy (Annotated[str, StringConstraints(strip_whitespace=True, to_upper=True, to_lower=None, strict=True, min_length=3, max_length=3, pattern=^[A-Z]{3}$)])
- ccy: CurrencyStringType
- model_config = {}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class openseries.owntypes.PropertiesList(iterable=(), /)[source]
-
Base class for allowed property arguments definition.
- allowed_strings: ClassVar[set[str]] = {'arithmetic_ret', 'cvar_down', 'downside_deviation', 'geo_ret', 'kappa3_ratio', 'kurtosis', 'max_drawdown', 'max_drawdown_cal_year', 'max_drawdown_date', 'omega_ratio', 'positive_share', 'ret_vol_ratio', 'skew', 'sortino_ratio', 'value_ret', 'var_down', 'vol', 'vol_from_var', 'worst', 'worst_month', 'z_score'}
- class openseries.owntypes.OpenTimeSeriesPropertiesList(*args)[source]
Bases:
PropertiesListAllowed property arguments for the OpenTimeSeries class.
- Parameters:
args (LiteralSeriesProps)
- allowed_strings: ClassVar[set[str]] = {'arithmetic_ret', 'cvar_down', 'downside_deviation', 'first_idx', 'geo_ret', 'kappa3_ratio', 'kurtosis', 'last_idx', 'length', 'max_drawdown', 'max_drawdown_cal_year', 'max_drawdown_date', 'omega_ratio', 'periods_in_a_year', 'positive_share', 'ret_vol_ratio', 'skew', 'sortino_ratio', 'span_of_days', 'value_ret', 'var_down', 'vol', 'vol_from_var', 'worst', 'worst_month', 'yearfrac', 'z_score'}
- __init__(*args)[source]
Property arguments for the OpenTimeSeries class.
- Parameters:
self (Self)
args (Literal['value_ret', 'geo_ret', 'arithmetic_ret', 'vol', 'downside_deviation', 'ret_vol_ratio', 'sortino_ratio', 'kappa3_ratio', 'z_score', 'skew', 'kurtosis', 'positive_share', 'var_down', 'cvar_down', 'vol_from_var', 'worst', 'worst_month', 'max_drawdown_cal_year', 'max_drawdown', 'max_drawdown_date', 'first_idx', 'last_idx', 'length', 'span_of_days', 'yearfrac', 'periods_in_a_year'])
- Return type:
None
- class openseries.owntypes.OpenFramePropertiesList(*args)[source]
Bases:
PropertiesListAllowed property arguments for the OpenFrame class.
- Parameters:
args (LiteralFrameProps)
- allowed_strings: ClassVar[set[str]] = {'arithmetic_ret', 'cvar_down', 'downside_deviation', 'first_indices', 'geo_ret', 'kappa3_ratio', 'kurtosis', 'last_indices', 'lengths_of_items', 'max_drawdown', 'max_drawdown_cal_year', 'max_drawdown_date', 'omega_ratio', 'positive_share', 'ret_vol_ratio', 'skew', 'sortino_ratio', 'span_of_days_all', 'value_ret', 'var_down', 'vol', 'vol_from_var', 'worst', 'worst_month', 'z_score'}
- __init__(*args)[source]
Property arguments for the OpenFrame class.
- Parameters:
self (Self)
args (Literal['value_ret', 'geo_ret', 'arithmetic_ret', 'vol', 'downside_deviation', 'ret_vol_ratio', 'sortino_ratio', 'kappa3_ratio', 'z_score', 'skew', 'kurtosis', 'positive_share', 'var_down', 'cvar_down', 'vol_from_var', 'worst', 'worst_month', 'max_drawdown', 'max_drawdown_date', 'max_drawdown_cal_year', 'first_indices', 'last_indices', 'lengths_of_items', 'span_of_days_all'])
- Return type:
None
Custom Exceptions
- exception openseries.owntypes.MixedValuetypesError[source]
Bases:
ExceptionRaised when provided timeseries valuetypes are not the same.
- exception openseries.owntypes.AtLeastOneFrameError[source]
Bases:
ExceptionRaised when none of the possible frame inputs is provided.
- exception openseries.owntypes.DateAlignmentError[source]
Bases:
ExceptionRaised when date input is not aligned with existing range.
- exception openseries.owntypes.NumberOfItemsAndLabelsNotSameError[source]
Bases:
ExceptionRaised when number of labels is not matching the number of timeseries.
- exception openseries.owntypes.InitialValueZeroError[source]
Bases:
ExceptionRaised when a calculation cannot be performed due to initial value(s) zero.
- exception openseries.owntypes.CountriesNotStringNorListStrError[source]
Bases:
ExceptionRaised when countries argument is not provided in correct format.
- exception openseries.owntypes.MarketsNotStringNorListStrError[source]
Bases:
ExceptionRaised when markets argument is not provided in correct format.
- exception openseries.owntypes.TradingDaysNotAboveZeroError[source]
Bases:
ExceptionRaised when trading days argument is not above zero.
- exception openseries.owntypes.BothStartAndEndError[source]
Bases:
ExceptionRaised when both start and end dates are provided.
- exception openseries.owntypes.NoWeightsError[source]
Bases:
ExceptionRaised when no weights are provided to function where necessary.
- exception openseries.owntypes.LabelsNotUniqueError[source]
Bases:
ExceptionRaised when provided label names are not unique.
- exception openseries.owntypes.RatioInputError[source]
Bases:
ExceptionRaised when ratio keyword not provided correctly.
- exception openseries.owntypes.MergingResultedInEmptyError[source]
Bases:
ExceptionRaised when a merge resulted in an empty DataFrame.
- exception openseries.owntypes.IncorrectArgumentComboError[source]
Bases:
ExceptionRaised when correct combination of arguments is not provided.