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.IsNothingErrorType
struct IsNothingError{__T_msg} <: PortfolioOptimisersError

Exception type thrown when an argument or value is unexpectedly nothing.

Fields

  • msg: Error message describing the condition that triggered the exception.

Constructors

IsNothingError(msg) -> IsNothingError

Arguments 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:1

Related

source
PortfolioOptimisers.IsEmptyErrorType
struct IsEmptyError{__T_msg} <: PortfolioOptimisersError

Exception type thrown when an argument or value is unexpectedly empty.

Fields

  • msg: Error message describing the condition that triggered the exception.

Constructors

IsEmptyError(msg) -> IsEmptyError

Arguments 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:1

Related

source
PortfolioOptimisers.IsNonFiniteErrorType
struct IsNonFiniteError{__T_msg} <: PortfolioOptimisersError

Exception 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) -> IsNonFiniteError

Arguments 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:1

Related

source
PortfolioOptimisers.PropertyPathErrorType
struct PropertyPathError{__T_msg} <: PortfolioOptimisersError

Exception 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) -> PropertyPathError

Arguments 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:1

Related

source
PortfolioOptimisers.ConflictingArgumentErrorType
struct ConflictingArgumentError{__T_msg} <: PortfolioOptimisersError

Exception 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) -> ConflictingArgumentError

Arguments 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:1

Related

source
PortfolioOptimisers.ObservationWeightsErrorType
struct ObservationWeightsError{__T_msg} <: PortfolioOptimisersError

Exception 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) -> ObservationWeightsError

Arguments 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:1

Related

source
PortfolioOptimisers.NonPositiveWealthErrorType
struct NonPositiveWealthError{__T_msg} <: PortfolioOptimisersError

Exception 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) -> NonPositiveWealthError

Arguments 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:1

Related

source
Base.showerrorMethod
showerror(io::IO, err::PortfolioOptimisersError) -> Any

Print human-readable representation of PortfolioOptimisersError subtypes to io, stripping parametric type suffixes.

Algorithm

  1. Take name, the string of the concrete type of err.
  2. Cut name at the first { or (, so a parametric subtype prints under its wrapper name alone.
  3. Print name, a colon, and the msg field of err.

Arguments

  • io: Stream the message is printed to.
  • err: The error to render.

Returns

  • nothing.

Related

source