Error types
Many of the types defined in PortfolioOptimisers.jl make use of extensive data validation to ensure values meet various criteria. This simplifies the implementation of methods, and improves performance and by delegating as many checks as possible to variable instantiation. In cases where validation cannot be performed at variable instantiation, they are performed as soon as possible within functions.
PortfolioOptimisers.jl aims to catch potential data validation issues as soon as possible and in an informative manner, in order to do so it makes use of a few custom error types.
PortfolioOptimisers.IsNothingError — Type
struct IsNothingError{__T_msg} <: PortfolioOptimisersErrorException type thrown when an argument or value is unexpectedly nothing.
Fields
msg: Error message describing the condition that triggered the exception.
Constructors
IsNothingError(msg) -> IsNothingErrorArguments correspond to the fields above.
Examples
julia> throw(IsNothingError("Input data must not be nothing"))ERROR: IsNothingError: Input data must not be nothingStacktrace: [1] top-level scope @ none:1Related
PortfolioOptimisers.IsEmptyError — Type
struct IsEmptyError{__T_msg} <: PortfolioOptimisersErrorException type thrown when an argument or value is unexpectedly empty.
Fields
msg: Error message describing the condition that triggered the exception.
Constructors
IsEmptyError(msg) -> IsEmptyErrorArguments correspond to the fields above.
Examples
julia> throw(IsEmptyError("Input array must not be empty"))ERROR: IsEmptyError: Input array must not be emptyStacktrace: [1] top-level scope @ none:1Related
PortfolioOptimisers.IsNonFiniteError — Type
struct IsNonFiniteError{__T_msg} <: PortfolioOptimisersErrorException type thrown when an argument or value is unexpectedly non-finite (e.g., contains NaN or Inf).
Fields
msg: Error message describing the condition that triggered the exception.
Constructors
IsNonFiniteError(msg) -> IsNonFiniteErrorArguments correspond to the fields above.
Examples
julia> throw(IsNonFiniteError("Input array contains non-finite values"))ERROR: IsNonFiniteError: Input array contains non-finite valuesStacktrace: [1] top-level scope @ none:1Related
PortfolioOptimisers.PropertyPathError — Type
struct PropertyPathError{__T_msg} <: PortfolioOptimisersErrorException type thrown when a @forward_properties nested path cannot be descended because an intermediate node is nothing.
Fields
msg: Error message describing the condition that triggered the exception.
Constructors
PropertyPathError(msg) -> PropertyPathErrorArguments correspond to the fields above.
Examples
julia> throw(PropertyPathError("cannot descend path `sol.w` on `JuMPOptimisationResult`: intermediate `sol` is `nothing`"))ERROR: PropertyPathError: cannot descend path `sol.w` on `JuMPOptimisationResult`: intermediate `sol` is `nothing`Stacktrace: [1] top-level scope @ none:1Related
PortfolioOptimisers.ConflictingArgumentError — Type
struct ConflictingArgumentError{__T_msg} <: PortfolioOptimisersErrorException type thrown when an argument or value is mutually exclusive with another and both were supplied — a "must-be-absent" constraint was violated (e.g. an argument that must be nothing because a conflicting one is set).
Fields
msg: Error message describing the condition that triggered the exception.
Constructors
ConflictingArgumentError(msg) -> ConflictingArgumentErrorArguments correspond to the fields above.
Examples
julia> throw(ConflictingArgumentError("sbgt must be nothing when bgt is a BudgetCostEstimator"))ERROR: ConflictingArgumentError: sbgt must be nothing when bgt is a BudgetCostEstimatorStacktrace: [1] top-level scope @ none:1Related
PortfolioOptimisers.ObservationWeightsError — Type
struct ObservationWeightsError{__T_msg} <: PortfolioOptimisersErrorException type thrown when a DynamicAbstractWeights cannot resolve observation weights for the data it was handed, because no get_observation_weights method is implemented for that input's shape.
get_observation_weights returns nothing to mean no weights were requested, never weights were unavailable. Every isnothing branch downstream reads it the first way and computes an unweighted result, so a DynamicAbstractWeights that resolved to nothing would silently produce a numerically plausible but unweighted answer with no diagnostic. It raises instead.
Fields
msg: Error message describing the condition that triggered the exception.
Constructors
ObservationWeightsError(msg) -> ObservationWeightsErrorArguments correspond to the fields above.
Examples
julia> throw(ObservationWeightsError("MyWeights has no `get_observation_weights` method for a 2-dimensional input of size (3, 10)"))ERROR: ObservationWeightsError: MyWeights has no `get_observation_weights` method for a 2-dimensional input of size (3, 10)Stacktrace: [1] top-level scope @ none:1Related
PortfolioOptimisers.NonPositiveWealthError — Type
struct NonPositiveWealthError{__T_msg} <: PortfolioOptimisersErrorException type thrown when a drifted portfolio's wealth reaches zero or turns negative over the observations it is scored on.
A drifted series divides by the wealth of the previous observation, so a wealth of zero or below is outside the domain of the series rather than a large loss inside it. The check runs before any return is formed, so a ruined window gives no partial series. A negative wealth is finite, and every leg of the record flips its sign, so nothing downstream reads the failure from a NaN. That is why the drift raises rather than returning a value.
Fields
msg: Error message describing the condition that triggered the exception.
Constructors
NonPositiveWealthError(msg) -> NonPositiveWealthErrorArguments correspond to the fields above.
Examples
julia> throw(NonPositiveWealthError("the drifted wealth must satisfy `all(>(0), wealth)`, but the wealth is -0.3975 at row 2 of the window"))ERROR: NonPositiveWealthError: the drifted wealth must satisfy `all(>(0), wealth)`, but the wealth is -0.3975 at row 2 of the windowStacktrace: [1] top-level scope @ none:1Related
Base.showerror — Method
showerror(io::IO, err::PortfolioOptimisersError) -> Any
Print human-readable representation of PortfolioOptimisersError subtypes to io, stripping parametric type suffixes.
Algorithm
- Take
name, the string of the concrete type oferr. - Cut
nameat the first{or(, so a parametric subtype prints under its wrapper name alone. - Print
name, a colon, and themsgfield oferr.
Arguments
io: Stream the message is printed to.err: The error to render.
Returns
nothing.
Related