Base
01_Base.jl implements the most basal symbols used in PortfolioOptimisers.jl.
Base abstract types
PortfolioOptimisers.jl is designed in a deliberately structured and hierarchical way. Enabling us to create self-contained, independent, composable processes. These abstract types form the basis of this hierarchy.
PortfolioOptimisers.AbstractEstimator Type
abstract type AbstractEstimator endAbstract supertype for all estimator types in PortfolioOptimisers.jl.
All custom estimators should subtype AbstractEstimator.
Estimators consume data to estimate parameters or models. Some estimators may utilise different algorithms. These can range from simple implementation details that don't change the result much but may have different numerical characteristics, to entirely different methodologies or algorithms yielding different results.
Related
sourcePortfolioOptimisers.AbstractAlgorithm Type
abstract type AbstractAlgorithm endAbstract supertype for all algorithm types in PortfolioOptimisers.jl.
All algorithms should subtype AbstractAlgorithm.
Algorithms are often used by estimators to perform specific tasks. These can be in the form of simple implementation details to entirely different procedures for estimating a quantity.
Related
sourcePortfolioOptimisers.AbstractResult Type
abstract type AbstractResult endAbstract supertype for all result types in PortfolioOptimisers.jl.
All result objects should subtype AbstractResult.
Result types encapsulate the outcomes of estimators. This makes dispatch and usage more straightforward, especially when the results encapsulate a wide range of information.
Related
sourcePretty printing
PortfolioOptimisers.jl's types tend to contain quite a lot of information, these functions enable pretty printing so they are easier to interpret.
PortfolioOptimisers.@define_pretty_show Macro
@define_pretty_show(T)Macro to define a custom pretty-printing Base.show method for types in PortfolioOptimisers.jl.
This macro generates a show method that displays the type name and all fields in a readable, aligned format. For fields that are themselves custom types or collections, the macro recursively applies pretty-printing for nested structures. Handles compact and multiline IO contexts gracefully.
Arguments
T: The type for which to define the pretty-printing method.
Returns
- Defines a
Base.show(io::IO, obj::T)method for the given type.
Details
Prints the type name and all fields with aligned labels.
Recursively pretty-prints nested custom types and collections.
Handles compact and multiline IO contexts.
Displays matrix/vector fields with their size and type.
Skips fields that are not present or are
nothing.
Related
sourcePortfolioOptimisers.has_pretty_show_method Function
has_pretty_show_method(::Any)Default method indicating whether a type has a custom pretty-printing show method.
Overloading this method to return true indicates that type already has a custom pretty-printing method.
Arguments
::Any: Any type.
Returns
flag::Bool:falseby default, indicating no custom pretty-printing method.
Related
sourceError 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.PortfolioOptimisersError Type
abstract type PortfolioOptimisersError <: Exception endAbstract supertype for all custom exception types in PortfolioOptimisers.jl.
All error types specific to PortfolioOptimisers.jl should be subtypes of PortfolioOptimisersError.
Related
sourcePortfolioOptimisers.IsNothingError Type
struct IsNothingError{T1} <: PortfolioOptimisersError
msg::T1
endException type thrown when an argument or value is unexpectedly nothing.
Fields
msg: Error message describing the condition that triggered the exception.
Constructors
IsNothingError(msg)Arguments correspond to the fields above.
Examples
julia> throw(IsNothingError("Input data must not be nothing"))
ERROR: IsNothingError: Input data must not be nothing
Stacktrace:
[1] top-level scope
@ none:1Related
sourcePortfolioOptimisers.IsEmptyError Type
struct IsEmptyError{T1} <: PortfolioOptimisersError
msg::T1
endException type thrown when an argument or value is unexpectedly empty.
Fields
msg: Error message describing the condition that triggered the exception.
Constructors
IsEmptyError(msg)Arguments correspond to the fields above.
Examples
julia> throw(IsEmptyError("Input array must not be empty"))
ERROR: IsEmptyError: Input array must not be empty
Stacktrace:
[1] top-level scope
@ none:1Related
sourcePortfolioOptimisers.IsNonFiniteError Type
struct IsNonFiniteError{T1} <: PortfolioOptimisersError
msg::T1
endException 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)Arguments correspond to the fields above.
Examples
julia> throw(IsNonFiniteError("Input array contains non-finite values"))
ERROR: IsNonFiniteError: Input array contains non-finite values
Stacktrace:
[1] top-level scope
@ none:1Related
sourceUtility types
Custom types are the bread and butter of PorfolioOptimisers.jl, the following types non-specific and used throughout the library.
PortfolioOptimisers.VecScalar Type
struct VecScalar{T1, T2} <: AbstractResult
v::T1
s::T2
endRepresents a composite result containing a vector and a scalar in PortfolioOptimisers.jl.
Encapsulates a vector and a scalar value, commonly used for storing results that combine both types of data (e.g., weighted statistics, risk measures).
Fields
v: Vector value.s: Scalar value.
Constructors
VecScalar(; v::VecNum, s::Number)Keyword arguments correspond to the fields above.
Validation
v:!isempty(v)andall(isfinite, v).s:isfinite(s).
Examples
julia> VecScalar([1.0, 2.0, 3.0], 4.2)
VecScalar
v ┼ Vector{Float64}: [1.0, 2.0, 3.0]
s ┴ Float64: 4.2Related
sourcePortfolioOptimisers.AbstractEstimatorValueAlgorithm Type
abstract type AbstractEstimatorValueAlgorithm <: AbstractAlgorithm endAbstract supertype for all estimator value algorithm types in PortfolioOptimisers.jl.
Subtypes of AbstractEstimatorValueAlgorithm implement algorithms for computing constraint result values. These are used to extend or modify the behavior of estimators in a composable and modular fashion.
Related
sourceBase type aliases
PortfolioOptimisers.jl heavily relies on Julia's dispatch and type system to ensure data validity. Many custom types and functions/methods can accept different data types. These can be represented as type unions, many of which are used throughout the library. The following type aliases centralise these union definitions, as well as improving correctness and maintainability.
PortfolioOptimisers.Option Type
const Option{T} = Union{Nothing, T}Alias for an optional value of type T, which may be nothing.
Related
sourcePortfolioOptimisers.VecNum Type
const VecNum = Union{<:AbstractVector{<:Union{<:Number, <:JuMP.AbstractJuMPScalar}}}Alias for an abstract vector of numeric types or JuMP scalar types.
Related
sourcePortfolioOptimisers.VecInt Type
const VecInt = AbstractVector{<:Integer}Alias for an abstract vector of integer types.
Related
sourcePortfolioOptimisers.MatNum Type
const MatNum = Union{<:AbstractMatrix{<:Union{<:Number, <:JuMP.AbstractJuMPScalar}}}Alias for an abstract matrix of numeric types or JuMP scalar types.
Related
sourcePortfolioOptimisers.ArrNum Type
const ArrNum = Union{<:AbstractArray{<:Union{<:Number, <:JuMP.AbstractJuMPScalar}}}Alias for an abstract array of numeric types or JuMP scalar types.
Related
sourcePortfolioOptimisers.Num_VecNum Type
const Num_VecNum = Union{<:Number, <:VecNum}Alias for a union of a numeric type or an abstract vector of numeric types.
Related
sourcePortfolioOptimisers.Num_ArrNum Type
const Num_ArrNum = Union{<:Number, <:ArrNum}Alias for a union of a numeric type or an abstract array of numeric types.
Related
sourcePortfolioOptimisers.PairStrNum Type
const PairStrNum = Pair{<:AbstractString, <:Number}Alias for a pair consisting of an abstract string and a numeric type.
Related
sourcePortfolioOptimisers.DictStrNum Type
const DictStrNum = AbstractDict{<:AbstractString, <:Number}Alias for an abstract dictionary with string keys and numeric values.
Related
sourcePortfolioOptimisers.MultiEstValType Type
const MultiEstValType = Union{<:DictStrNum, <:AbstractVector{<:PairStrNum}}Alias for a union of a dictionary with string keys and numeric values, or a vector of string-number pairs.
Related
sourcePortfolioOptimisers.EstValType Type
const EstValType = Union{<:Num_VecNum, <:PairStrNum, <:MultiEstValType, <:AbstractEstimatorValueAlgorithm}Alias for a union of numeric, vector of numeric, string-number pair, or multi-estimator value types.
Related
sourcePortfolioOptimisers.PairGSCV Type
const PairGSCV = Pair{<:AbstractString, <:AbstractVector}Alias for a pair consisting of an abstract string and an abstract vector.
Related
sourcePortfolioOptimisers.DictGSCV Type
const DictGSCV = AbstractDict{<:AbstractString, <:AbstractVector}Alias for an abstract dictionary with string keys and abstract vector values.
Related
sourcePortfolioOptimisers.MultiGSCVValType Type
const MultiGSCVValType = Union{<:DictGSCV, <:AbstractVector{<:PairGSCV}}Alias for a union of an abstract dictionary with string keys and abstract vector values, or a vector of string-vector pairs.
Related
sourcePortfolioOptimisers.VecMultiGSCVValType Type
const VecMultiGSCVValType = AbstractVector{<:MultiGSCVValType}Alias for an abstract vector of MultiGSCVValType elements.
Related
sourcePortfolioOptimisers.MultiGSCVValType_VecMultiGSCVValType Type
const MultiGSCVValType_VecMultiGSCVValType = Union{<:MultiGSCVValType,
<:VecMultiGSCVValType}Alias for a union of MultiGSCVValType and VecMultiGSCVValType elements.
Related
sourcePortfolioOptimisers.Str_Expr Type
const Str_Expr = Union{<:AbstractString, Expr}Alias for a union of abstract string or Julia expression.
Related
sourcePortfolioOptimisers.VecStr_Expr Type
const VecStr_Expr = AbstractVector{<:Str_Expr}Alias for an abstract vector of strings or Julia expressions.
Related
sourcePortfolioOptimisers.EqnType Type
const EqnType = Union{<:AbstractString, Expr, <:VecStr_Expr}Alias for a union of string, Julia expression, or vector of strings/expressions.
Related
sourcePortfolioOptimisers.VecVecNum Type
const VecVecNum = AbstractVector{<:VecNum}Alias for an abstract vector of numeric vectors.
Related
sourcePortfolioOptimisers.VecVecInt Type
const VecVecInt = AbstractVector{<:VecInt}Alias for an abstract vector of integer vectors.
Related
sourcePortfolioOptimisers.VecMatNum Type
const VecMatNum = AbstractVector{<:MatNum}Alias for an abstract vector of numeric matrices.
Related
sourcePortfolioOptimisers.VecStr Type
const VecStr = Union{<:AbstractVector{<:AbstractString}}Alias for an abstract vector of strings.
Related
sourcePortfolioOptimisers.VecPair Type
const VecPair = AbstractVector{<:Pair}Alias for an abstract vector of pairs.
Related
sourcePortfolioOptimisers.VecJuMPScalar Type
const VecJuMPScalar = Union{<:AbstractVector{<:JuMP.AbstractJuMPScalar}}Alias for an abstract vector of JuMP scalar types.
Related
sourcePortfolioOptimisers.MatNum_VecMatNum Type
const MatNum_VecMatNum = Union{<:MatNum, <:VecMatNum}Alias for a union of a numeric matrix or a vector of numeric matrices.
Related
sourcePortfolioOptimisers.Int_VecInt Type
const Int_VecInt = Union{<:Integer, <:VecInt}Alias for a union of an integer or a vector of integers.
Related
sourcePortfolioOptimisers.VecNum_VecVecNum Type
const VecNum_VecVecNum = Union{<:VecNum, <:VecVecNum}Alias for a union of a numeric vector or a vector of numeric vectors.
Related
sourcePortfolioOptimisers.VecDate Type
const VecDate = AbstractVector{<:Dates.AbstractTime}Alias for an abstract vector of date or time types.
Related
sourcePortfolioOptimisers.Dict_Vec Type
const Dict_Vec = Union{<:AbstractDict, <:AbstractVector}Alias for a union of an abstract dictionary or an abstract vector.
Related
sourcePortfolioOptimisers.Sym_Str Type
const Sym_Str = Union{Symbol, <:AbstractString}Alias for a union of a symbol or an abstract string.
Related
sourcePortfolioOptimisers.Str_Vec Type
const Str_Vec = Union{<:AbstractString, <:AbstractVector}Alias for a union of an abstract string or an abstract vector.
Related
sourcePortfolioOptimisers.Num_VecNum_VecScalar Type
const Num_VecNum_VecScalar = Union{<:Num_VecNum, <:VecScalar}Alias for a union of a numeric type, a vector of numeric types, or a VecScalar result.
Related
sourcePortfolioOptimisers.Num_ArrNum_VecScalar Type
const Num_ArrNum_VecScalar = Union{<:Num_ArrNum, <:VecScalar}Alias for a union of a numeric type, an array of numeric types, or a VecScalar result.
Related
sourceDocumentation arg_dict
In order to standardise the documentation we use a arg_dict of terms.
PortfolioOptimisers.arg_dict Constant
arg_dict = Dict(
# Weight vectors.
:pw => "`w`: Portfolio weights vector.",
:ow => "`w`: Observation weights vector.",
:oow => "`w`: Optional observation weights vector.",
# Matrix processing.
:pdm => "`pdm`: Positive definite matrix estimator.",
:dn => "`dn`: Matrix denoising estimator.",
:dt => "`dt`: Matrix detoning estimator.",
:mp => "`mp`: Matrix processing estimator.",
# Moments.
:me => "`me`: Expected returns estimator.",
:ce => "`ce`: Covariance estimator.",
:ve => "`ve`: Variance estimator.",
:ske => "`ske`: Coskewness estimator.",
:kte => "`kte`: Cokurtosis estimator.",
:de => "`de`: Distance matrix estimator.",
# Priors.
:pe => "`pe`: Prior estimator.",
:pr => "`pr`: Prior result.",
:per => "`pe`: Prior estimator or result.",
# Phylogeny.
:cle => "`cle`: Clusters estimator.",
:clr => "`clr`: Clusters result.",
:cler => "`cle`: Clusters estimator or result.",
:ple => "`pl`: Phylogeny estimator.",
:plr => "`pl`: Phylogeny result.",
:pler => "`pl`: Phylogeny estimator or result.",
:nte => "`pl`: Network estimator.",
:ntr => "`pl`: Network result.",
:nter => "`pl`: Network estimator or result.",
:cte => "`cte`: Centrality estimator.",
:cta => "`ct`: Centrality algorithm.",
:ctr => "`ct`: Centrality result.",
:cter => "`ct`: Centrality estimator or result.",
# Turnover.
:tne => "`tn`: Turnover estimator.",
:tnr => "`tn`: Turnover result.",
:tner => "`tn`: Turnover estimator or result.",
:tnes => "`tn`: Turnover estimator(s).",
:tnrs => "`tn`: Turnover result(s).",
:tners => "`tn`: Turnover estimator(s) or result(s).",
# Tracking.
:tre => "`tr`: Tracking error estimator.",
:trr => "`tr`: Tracking error result.",
:trer => "`tr`: Tracking error estimator or result.",
:tres => "`tr`: Tracking error estimator(s).",
:trrs => "`tr`: Tracking error result(s).",
:trers => "`tr`: Tracking error estimator(s) or result(s).",
# Weight bounds.
:wbe => "`wb`: Weight bounds estimator.",
:wbr => "`wb`: Weight bounds result.",
:wber => "`wb`: Weight bounds estimator or result.",
# Fees.
:feese => "`fees`: Fees estimator.",
:feesr => "`fees`: Fees result.",
:feeser => "`fees`: Fees estimator or result.")This dictionary contains the arg_dict terms and their corresponding descriptions used in the documentation of PortfolioOptimisers.jl.
PortfolioOptimisers.val_dict Constant
val_dict = Dict(:oow => "If `w` is not `nothing`, `!isempty(w)`.")Validation rules for certain arg_dict terms used in the documentation of PortfolioOptimisers.jl.
PortfolioOptimisers.ret_dict Constant
Dictionary containing return value descriptions for common parameters used in PortfolioOptimisers.jl.