Asset turnover
The turnover is used to measure the absolute weight change between the current weights and benchmark weights. They can be used to compute fees, or as a constraint. It can also be used as a risk measure, but we will detail that use in Risk Measures
PortfolioOptimisers.TurnoverEstimator Type
struct TurnoverEstimator{T1, T2, T3} <: AbstractEstimator
w::T1
val::T2
dval::T3
endEstimator for turnover portfolio constraints.
TurnoverEstimator specifies turnover constraints for each asset in a portfolio, based on current portfolio weights w, asset-specific turnover values val, and a default value for assets not explicitly specified. Supports asset-specific turnover via dictionaries, pairs, or vectors of pairs.
This estimator can be converted into a concrete Turnover constraint using the turnover_constraints function, which maps the estimator's specifications to the assets in a given AssetSets object.
Fields
w: Vector of current portfolio weights.val: Asset-specific turnover values, as a dictionary, pair, or vector of pairs.dval: Default turnover value for assets not specified inval.
Constructor
TurnoverEstimator(; w::VecNum, val::EstValType, dval::Option{<:Number} = nothing)Validation
wis validated withassert_nonempty_finite_val.valis validated withassert_nonempty_nonneg_finite_val.dval, if notnothing,dval >= 0.
Examples
julia> TurnoverEstimator(; w = [0.2, 0.3, 0.5], val = Dict("A" => 0.1, "B" => 0.2), dval = 0.0)
TurnoverEstimator
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Dict{String, Float64}: Dict("B" => 0.2, "A" => 0.1)
dval ┴ Float64: 0.0Related
sourcePortfolioOptimisers.Turnover Type
struct Turnover{T1, T2} <: AbstractResult
w::T1
val::T2
endContainer for turnover portfolio constraints.
Turnover stores the portfolio weights and turnover constraint values for each asset. The turnover constraint can be specified as a scalar (applied to all assets) or as a vector of per-asset values.
Where:
: N × 1turnover vector.: N × 1vector of current portfolio weights.: N × 1vector of benchmark portfolio weights.: Element-wise absolute value.
Fields
w: Vector of benchmark portfolio weights.val: Scalar or vector of turnover constraint values. Scalar values are broadcast to all assets.When used as a constraint, this value is used to constrain the maximum allowed turnover per asset.
When used in
Fees, this value represents the turnover fee per asset.
Constructor
Turnover(; w::VecNum, val::Num_VecNum = 0.0)Keyword arguments correspond to the fields above.
Validation
!isempty(w).val:AbstractVector:!isempty(val),length(w) == length(val),any(isfinite, val),all(x -> x >= 0, val).Number:isfinite(val)andval >= 0.
Examples
julia> Turnover(; w = [0.2, 0.3, 0.5], val = [0.1, 0.2, 0.0])
Turnover
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┴ Vector{Float64}: [0.1, 0.2, 0.0]
julia> Turnover(; w = [0.2, 0.3, 0.5], val = 0.02)
Turnover
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┴ Float64: 0.02Related
PortfolioOptimisers.factory Method
factory(tn::Turnover, w::VecNum)Create a new Turnover constraint with updated portfolio weights.
factory constructs a new Turnover object using the provided portfolio weights w and the turnover values from an existing Turnover constraint tn. This enables composable updating of weights while preserving turnover constraint values.
Arguments
tn: ExistingTurnoverconstraint object.w: New portfolio weights vector.
Returns
tn::Turnover: New constraint object with updated weights and original turnover values.
Details
Copies turnover values from
tn.Updates only the weights field.
Examples
julia> tn = Turnover(; w = [0.2, 0.3, 0.5], val = [0.1, 0.2, 0.0])
Turnover
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┴ Vector{Float64}: [0.1, 0.2, 0.0]
julia> factory(tn, [0.0, 0.2, 0.8])
Turnover
w ┼ Vector{Float64}: [0.0, 0.2, 0.8]
val ┴ Vector{Float64}: [0.1, 0.2, 0.0]Related
sourcePortfolioOptimisers.factory Method
factory(tn::TurnoverEstimator, w::VecNum)Create a new TurnoverEstimator with updated portfolio weights.
Constructs a new TurnoverEstimator object using the provided portfolio weights w and the turnover values and default value from an existing TurnoverEstimator tn. This enables composable updating of weights while preserving turnover constraint values.
Arguments
tn: ExistingTurnoverEstimatorobject. Supplies turnover values and default value.w: New portfolio weights vector.
Returns
tn::TurnoverEstimator: New estimator object with updated weights and original turnover values and default.
Validation
wis validated to be non-empty, finite, and numeric.
Details
Copies turnover values and default value from
tn.Updates only the weights field.
Examples
julia> tn = TurnoverEstimator(; w = [0.2, 0.3, 0.5], val = Dict("A" => 0.1, "B" => 0.2),
dval = 0.0)
TurnoverEstimator
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┼ Dict{String, Float64}: Dict("B" => 0.2, "A" => 0.1)
dval ┴ Float64: 0.0
julia> factory(tn, [0.1, 0.4, 0.5])
TurnoverEstimator
w ┼ Vector{Float64}: [0.1, 0.4, 0.5]
val ┼ Dict{String, Float64}: Dict("B" => 0.2, "A" => 0.1)
dval ┴ Float64: 0.0Related
sourcePortfolioOptimisers.turnover_constraints Function
turnover_constraints(tn::TurnoverEstimator, sets::AssetSets; datatype::DataType = Float64,
strict::Bool = false)Generate turnover portfolio constraints from a TurnoverEstimator and asset set.
turnover_constraints constructs a Turnover object representing turnover constraints for the assets in sets, using the specifications in tn. Supports scalar, vector, dictionary, pair, or custom turnover types for flexible assignment and validation.
Arguments
tn:TurnoverEstimatorspecifying current weights, asset-specific turnover values, and default value.sets:AssetSetscontaining asset names or indices.datatype: Data type for default turnover values whendvalisnothing.strict: Iftrue, enforces strict matching between assets and turnover values (throws error on mismatch); iffalse, issues a warning.
Returns
tn::Turnover: Object containing portfolio weights and turnover values aligned withsets.
Details
- Turnover values are extracted and mapped to assets using
estimator_to_val.
Examples
julia> sets = AssetSets(; dict = Dict("nx" => ["A", "B", "C"]));
julia> tn = TurnoverEstimator([0.2, 0.3, 0.5], Dict("A" => 0.1, "B" => 0.2));
julia> turnover_constraints(tn, sets)
Turnover
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┴ Vector{Float64}: [0.1, 0.2, 0.0]Related
sourceturnover_constraints(tn::Option{<:Turnover}, args...; kwargs...)Propagate or pass through turnover portfolio constraints.
turnover_constraints returns the input Turnover object unchanged or nothing. This method is used to propagate already constructed turnover constraints, enabling composability and uniform interface handling in constraint generation workflows.
Arguments
tn: An existingTurnoverobject.args...: Additional positional arguments (ignored).kwargs...: Additional keyword arguments (ignored).
Returns
tn::Option{<:Turnover}: The input constraint object, unchanged.
Examples
julia> tn = Turnover(; w = [0.2, 0.3, 0.5], val = [0.1, 0.2, 0.0]);
julia> turnover_constraints(tn)
Turnover
w ┼ Vector{Float64}: [0.2, 0.3, 0.5]
val ┴ Vector{Float64}: [0.1, 0.2, 0.0]Related
sourceturnover_constraints(tn::VecTnE_Tn, sets::AssetSets; datatype::DataType = Float64,
strict::Bool = false)Broadcasts threshold_constraints over the vector.
Provides a uniform interface for processing multiple constraint estimators simultaneously.
Arguments
tn: Vector of turnover constraints or estimators.sets:AssetSetscontaining asset names or indices.datatype: Data type for default turnover values whendvalisnothing.strict: Iftrue, enforces strict matching between assets and turnover values (throws error on mismatch); iffalse, issues a warning.
Returns
res::VecTn: Vector of constructed turnover constraints.
Related
sourcePortfolioOptimisers.turnover_view Function
turnover_view(::Nothing, ::Any)Returns nothing when the turnover constraint or estimator is not provided.
Used as a fallback method for missing turnover constraints or estimators, ensuring composability and uniform interface handling in constraint processing workflows.
Arguments
::Nothing: Indicates absence of a turnover constraint or estimator.::Any: Index or argument (ignored).
Returns
nothing.
Related
sourceturnover_view(tn::TurnoverEstimator, i)Create a view of a TurnoverEstimator for a subset of assets.
turnover_view returns a new TurnoverEstimator with portfolio weights and turnover values restricted to the indices or assets specified by i. The default turnover value is propagated unchanged.
Arguments
tn: An instance ofTurnoverEstimator.i: Index or indices specifying the subset of assets.
Returns
tn::TurnoverEstimator: A new estimator with fields restricted to the specified subset.
Details
Uses
viewto create a subset of the weights.Uses
nothing_scalar_array_viewto subset turnover values.Propagates the default turnover value.
Examples
julia> tn = TurnoverEstimator(; w = [0.2, 0.3, 0.5], val = Dict("A" => 0.1, "B" => 0.2),
dval = 0.0);
julia> PortfolioOptimisers.turnover_view(tn, 1:2)
TurnoverEstimator
w ┼ SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}: [0.2, 0.3]
val ┼ Dict{String, Float64}: Dict("B" => 0.2, "A" => 0.1)
dval ┴ Float64: 0.0Related
sourceturnover_view(tn::Turnover, i)Create a view of a Turnover for a subset of assets.
Returns a new Turnover object with portfolio weights and turnover values restricted to the indices or assets specified by i.
Arguments
tn: ATurnoverobject containing portfolio weights and turnover values.i: Index or indices specifying the subset of assets.
Returns
tn::Turnover: A new turnover constraint object with fields restricted to the specified subset.
Details
Uses
viewto create a subset of the weights.Uses
nothing_scalar_array_viewto subset turnover values.
Examples
julia> tn = Turnover(; w = [0.2, 0.3, 0.5], val = [0.1, 0.2, 0.0]);
julia> PortfolioOptimisers.turnover_view(tn, 1:2)
Turnover
w ┼ SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}: [0.2, 0.3]
val ┴ SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}: [0.1, 0.2]Related
sourceturnover_view(tn::VecTnE_Tn, i)Create views of multiple turnover constraints or estimators for a subset of assets.
turnover_view returns a vector of turnover constraint or estimator objects, each restricted to the indices or assets specified by i. This enables batch processing and composable handling of asset subsets across multiple turnover specifications.
Arguments
tn: Vector of turnover constraints or estimators.i: Index or indices specifying the subset of assets.
Returns
res::VecTnE_Tn: Vector of turnover constraint or estimator objects, each restricted to the specified subset.
Details
Applies
turnover_viewto each element intn.Supports both
TurnoverandTurnoverEstimatortypes.Enables composable and uniform processing of asset subsets for batch turnover constraints.
Examples
julia> tn1 = Turnover(; w = [0.2, 0.3, 0.5], val = [0.1, 0.2, 0.0]);
julia> tn2 = TurnoverEstimator(; w = [0.2, 0.3, 0.5], val = Dict("A" => 0.1, "B" => 0.2),
dval = 0.0);
julia> PortfolioOptimisers.turnover_view(concrete_typed_array([tn1, tn2]), 1:2)
2-element Vector{Any}:
Turnover
w ┼ SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}: [0.2, 0.3]
val ┴ SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}: [0.1, 0.2]
TurnoverEstimator
w ┼ SubArray{Float64, 1, Vector{Float64}, Tuple{UnitRange{Int64}}, true}: [0.2, 0.3]
val ┼ Dict{String, Float64}: Dict("B" => 0.2, "A" => 0.1)
dval ┴ Float64: 0.0Related
sourcePortfolioOptimisers.TnE_Tn Type
const TnE_Tn = Union{<:Turnover, <:TurnoverEstimator}Alias for a turnover constraint or estimator.
Represents either a constructed turnover constraint or a turnover constraint estimator. Used for flexible dispatch in turnover constraint generation and processing.
Related Types
sourcePortfolioOptimisers.VecTnE_Tn Type
const VecTnE_Tn = AbstractVector{<:TnE_Tn}Alias for a vector of turnover constraints or estimators.
Represents a collection of turnover constraints or estimators, enabling batch processing and broadcasting of turnover constraint generation.
Related Types
sourcePortfolioOptimisers.VecTn Type
const VecTn = AbstractVector{<:Turnover}Alias for a vector of turnover constraints.
Represents a collection of constructed turnover constraints for multiple portfolios or assets.
Related Types
sourcePortfolioOptimisers.Tn_VecTn Type
const Tn_VecTn = Union{<:Turnover, <:VecTn}Alias for a single turnover constraint or a vector of turnover constraints.
Enables flexible dispatch for functions that accept either a single turnover constraint or multiple constraints.
Related Types
sourcePortfolioOptimisers.TnE_Tn_VecTnE_Tn Type
const TnE_Tn_VecTnE_Tn = Union{<:TnE_Tn, <:VecTnE_Tn}Alias for a single turnover constraint/estimator or a vector of them.
Supports flexible dispatch for turnover constraint generation and processing, accepting either a single constraint/estimator or a collection.
Related Types
source